Rename protocol structs

This commit is contained in:
2016-08-12 12:18:10 +03:00
parent dcd7a46d0a
commit 3309026308
5 changed files with 25 additions and 25 deletions

View File

@@ -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));
}
}

View File

@@ -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());

View File

@@ -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;
};