Rename protocol structs
This commit is contained in:
@@ -90,12 +90,12 @@ int main(int count, char *strings[])
|
||||
}
|
||||
|
||||
do {
|
||||
struct msg buf;
|
||||
memset(&buf, 0, sizeof(struct msg));
|
||||
bytes = SSL_read(ssl, &buf, sizeof(struct msg));
|
||||
struct msg_t buf;
|
||||
memset(&buf, 0, sizeof(struct msg_t));
|
||||
bytes = SSL_read(ssl, &buf, sizeof(struct msg_t));
|
||||
if (bytes > 0) {
|
||||
short index;
|
||||
if (bytes != sizeof(struct msg)) {
|
||||
if (bytes != sizeof(struct msg_t)) {
|
||||
fprintf( stderr,
|
||||
"Received non-standard data from server!\n" );
|
||||
continue;
|
||||
@@ -104,11 +104,11 @@ int main(int count, char *strings[])
|
||||
if ((index = get_job_slot()) == FAIL) {
|
||||
buf.chunk.id = -1; /* ID -1 means reject (full) */
|
||||
sprintf((char*)buf.chunk.data, "The agent's queue is full!");
|
||||
SSL_write(ssl, &buf, sizeof(struct msg));
|
||||
SSL_write(ssl, &buf, sizeof(struct msg_t));
|
||||
continue;
|
||||
}
|
||||
args[index].slot = FULL;
|
||||
memcpy(&args[index].buf, &buf, sizeof(struct msg));
|
||||
memcpy(&args[index].buf, &buf, sizeof(struct msg_t));
|
||||
switch (args[index].buf.meta.type) {
|
||||
case UNIX:
|
||||
pthread_create( &job_thread[index],
|
||||
@@ -181,7 +181,7 @@ int main(int count, char *strings[])
|
||||
sprintf( (char*)buf.chunk.data,
|
||||
"Unsupported job type with ID: %d",
|
||||
buf.meta.type );
|
||||
SSL_write(ssl, &buf, sizeof(struct msg));
|
||||
SSL_write(ssl, &buf, sizeof(struct msg_t));
|
||||
continue;
|
||||
}
|
||||
} else {
|
||||
@@ -189,9 +189,9 @@ int main(int count, char *strings[])
|
||||
if (index == FAIL) {
|
||||
sprintf( (char*)buf.chunk.data,
|
||||
"Data was sent for an invalid job ID" );
|
||||
SSL_write(ssl, &buf, sizeof(struct msg));
|
||||
SSL_write(ssl, &buf, sizeof(struct msg_t));
|
||||
} else
|
||||
memcpy(&args[index].buf, &buf, sizeof(struct msg));
|
||||
memcpy(&args[index].buf, &buf, sizeof(struct msg_t));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
14
agent/job.c
14
agent/job.c
@@ -83,14 +83,14 @@ void* get_os(void *args)
|
||||
if ((fd = open(dump_path, O_RDONLY)) == -1) {
|
||||
fprintf(stderr, "Cannot open file: %s\n", dump_path);
|
||||
job->buf.meta.len = sprintf((char*)job->buf.chunk.data, "Unknown");
|
||||
SSL_write(job->ssl, &job->buf, sizeof(struct msg));
|
||||
SSL_write(job->ssl, &job->buf, sizeof(struct msg_t));
|
||||
} else {
|
||||
job->buf.meta.len = read(fd, job->buf.chunk.data, sizeof(job->buf.chunk.data));
|
||||
if ((signed)job->buf.meta.len == -1) {
|
||||
perror("Failed to read from file: ");
|
||||
}
|
||||
close(fd);
|
||||
SSL_write(job->ssl, &job->buf, sizeof(struct msg));
|
||||
SSL_write(job->ssl, &job->buf, sizeof(struct msg_t));
|
||||
job->slot = FREE;
|
||||
}
|
||||
unlink(dump_path);
|
||||
@@ -103,7 +103,7 @@ void* get_kernel(void *args)
|
||||
struct job_args *job = args;
|
||||
if (uname(&name) == -1) {
|
||||
job->buf.meta.len = sprintf((char*)job->buf.chunk.data, "Unknown");
|
||||
SSL_write(job->ssl, &job->buf, sizeof(struct msg));
|
||||
SSL_write(job->ssl, &job->buf, sizeof(struct msg_t));
|
||||
} else {
|
||||
job->buf.meta.len = sprintf( (char*)job->buf.chunk.data,
|
||||
"%s %s %s %s %s",
|
||||
@@ -112,7 +112,7 @@ void* get_kernel(void *args)
|
||||
name.release,
|
||||
name.version,
|
||||
name.machine );
|
||||
SSL_write(job->ssl, &job->buf, sizeof(struct msg));
|
||||
SSL_write(job->ssl, &job->buf, sizeof(struct msg_t));
|
||||
}
|
||||
job->slot = FREE;
|
||||
return 0;
|
||||
@@ -125,11 +125,11 @@ void* get_uptime(void *args)
|
||||
|
||||
if (sysinfo(&sys) != 0) {
|
||||
job->buf.meta.len = sprintf((char*)job->buf.chunk.data, "Unknown");
|
||||
SSL_write(job->ssl, &job->buf, sizeof(struct msg));
|
||||
SSL_write(job->ssl, &job->buf, sizeof(struct msg_t));
|
||||
} else {
|
||||
memcpy(&job->buf.chunk.data, &sys.uptime, sizeof(long));
|
||||
//sprintf((char*)&job->buf.chunk.data, "%ld", sys.uptime);
|
||||
SSL_write(job->ssl, &job->buf, sizeof(struct msg));
|
||||
SSL_write(job->ssl, &job->buf, sizeof(struct msg_t));
|
||||
}
|
||||
job->slot = FREE;
|
||||
return 0;
|
||||
@@ -147,7 +147,7 @@ void* get_memory(void *args)
|
||||
"%ld / %ld (MB)",
|
||||
((pages - freepages) * pagesize) / 1048576 /* 1024*1024 */,
|
||||
(pages * pagesize) / 1048576 );
|
||||
SSL_write(job->ssl, &job->buf, sizeof(struct msg));
|
||||
SSL_write(job->ssl, &job->buf, sizeof(struct msg_t));
|
||||
job->slot = FREE;
|
||||
//return 0;
|
||||
pthread_detach(pthread_self());
|
||||
|
||||
@@ -8,7 +8,7 @@ enum pthread_state { WAIT, WORK };
|
||||
enum job_slot_state { FREE, FULL };
|
||||
|
||||
struct job_args {
|
||||
struct msg buf;
|
||||
struct msg_t buf;
|
||||
unsigned short slot;
|
||||
SSL *ssl;
|
||||
};
|
||||
|
||||
10
protocol.h
10
protocol.h
@@ -18,7 +18,7 @@ enum msg_types {
|
||||
GET_MEMORY
|
||||
};
|
||||
|
||||
struct msg_meta {
|
||||
struct msg_meta_t {
|
||||
unsigned short id; /* Agent job ID */
|
||||
unsigned short type; /* Data type */
|
||||
unsigned len; /* Data size to expect in buffer */
|
||||
@@ -27,14 +27,14 @@ struct msg_meta {
|
||||
short locking;
|
||||
};
|
||||
|
||||
struct msg_chunk {
|
||||
struct msg_chunk_t {
|
||||
int id;
|
||||
unsigned char data[CHUNKSIZE];
|
||||
};
|
||||
|
||||
struct msg {
|
||||
struct msg_meta meta;
|
||||
struct msg_chunk chunk;
|
||||
struct msg_t {
|
||||
struct msg_meta_t meta;
|
||||
struct msg_chunk_t chunk;
|
||||
};
|
||||
|
||||
#endif /* PROTOCOL_H */
|
||||
|
||||
@@ -40,7 +40,7 @@ static void show_certs(SSL *ssl)
|
||||
|
||||
static void* servlet(void *args) /* Serve the connection -- threadable */
|
||||
{
|
||||
struct msg buf;
|
||||
struct msg_t buf;
|
||||
int bytes, ret;
|
||||
//unsigned short job[MAXJOBS] = { 0 };
|
||||
struct agent_args *agent = (struct agent_args*)args;
|
||||
@@ -59,7 +59,7 @@ static void* servlet(void *args) /* Serve the connection -- threadable */
|
||||
SSL_write(agent->ssl, &buf, sizeof(buf));
|
||||
bytes = SSL_read(agent->ssl, &buf, sizeof(buf));
|
||||
if (bytes > 0) {
|
||||
if (bytes != sizeof(struct msg)) {
|
||||
if (bytes != sizeof(struct msg_t)) {
|
||||
log( WARNING,
|
||||
"Agent [%s] sent non-standard data!",
|
||||
agent->ip );
|
||||
@@ -77,7 +77,7 @@ static void* servlet(void *args) /* Serve the connection -- threadable */
|
||||
log(VERBOSE, "Client didn't send data! SSL error below:");
|
||||
//log_ssl(); /* We actually don't have anything to log from SSL */
|
||||
sprintf((char*)buf.chunk.data, "%s", "Where's the data, m8?");
|
||||
SSL_write(agent->ssl, &buf, sizeof(struct msg));
|
||||
SSL_write(agent->ssl, &buf, sizeof(struct msg_t));
|
||||
}
|
||||
log(INFO, "Agent [%s] disconnected.", agent->ip);
|
||||
} while (bytes);
|
||||
|
||||
Reference in New Issue
Block a user