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