From 2442ceaee200c26307954aa4ca66fdfa73951faf Mon Sep 17 00:00:00 2001 From: Bogomil Vasilev Date: Sat, 17 Sep 2016 15:04:12 +0300 Subject: [PATCH] Oops.. --- job_queue.c | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++ job_queue.h | 12 ++++++++++++ sql.c | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++ sql.h | 7 +++++++ 4 files changed, 127 insertions(+) create mode 100644 job_queue.c create mode 100644 job_queue.h create mode 100644 sql.c create mode 100644 sql.h diff --git a/job_queue.c b/job_queue.c new file mode 100644 index 0000000..49d3037 --- /dev/null +++ b/job_queue.c @@ -0,0 +1,53 @@ +#include +#include +#include "sql.h" +#include "job_queue.h" + +struct msg_t **slot; +int total_queues = 0; + +int start_msg_queue(void) +{ + int i; + for (i = 0; i < total_queues; i++) { + if (slot[i] == NULL) { + slot[i] = (struct msg_t *)calloc(100, sizeof(struct msg_t)); + if (slot[i] == NULL) + return -1; + return i; + } + } + return -1; +} + +void free_queue(int id) +{ + free(slot[id]); +} + +int start_job_queue(int poolsize) +{ + slot = (struct msg_t **)calloc(poolsize, sizeof(struct msg_t *)); + if (slot == NULL) + return -1; + total_queues = poolsize; + return 0; +} + +int add_msg_to_queue(int id, struct msg_t buf) +{ + int i; + for (i = 0; i < 100; i++) { + if (slot[id][i].meta.is_recv) { + memcpy(&slot[id][i], &buf, sizeof(struct msg_t)); + return 0; + } + } + return -1; +} + +void create_job(struct msg_t buf) +{ +// add_job_in_db(); + +} diff --git a/job_queue.h b/job_queue.h new file mode 100644 index 0000000..387b2de --- /dev/null +++ b/job_queue.h @@ -0,0 +1,12 @@ +#ifndef JOB_QUEUE_H +#define JOB_QUEUE_H + +#include "protocol.h" + +//void* create_job(void *arg); +int start_msg_queue(void); +void free_queue(int id); +int start_job_queue(int poolsize); +int add_msg_to_queue(int id, struct msg_t buf); + +#endif /* JOB_QUEUE_H */ diff --git a/sql.c b/sql.c new file mode 100644 index 0000000..c7759e3 --- /dev/null +++ b/sql.c @@ -0,0 +1,55 @@ +#include +#include +#include +#include "log.h" +#include "sql.h" +#include "confparser.h" + +int add_user() +{ + MYSQL *con = mysql_init(NULL); + char sql[200]; + if (con == NULL) { + log(ERROR, "Failed to add user: %s", mysql_error(con)); + return -1; + } + if (mysql_real_connect(con, conf_db_hostname(), "rmps", conf_db_pass(), + NULL, 0, NULL, 0) == NULL) { + log(ERROR, "Failed to add user: %s", mysql_error(con)); + mysql_close(con); + return -1; + } + sprintf(sql, "call addUser(`%s`, `%s`, `%s`, `%s`, `%s`, `%s`)", + "user", "noob", "asd@asd.asd", "asdsadasdassda", "salt", "more"); + if (mysql_query(con, sql)) { + //fprintf(stderr, "%s\n", mysql_error(con)); + + mysql_close(con); + exit(1); + } + MYSQL_RES *result = mysql_store_result(con); + if (result == NULL) { + log(ERROR, "Failed to add user: %s", mysql_error(con)); + return -1; + } + + int num_fields = mysql_num_fields(result); + MYSQL_ROW row; + MYSQL_FIELD *field; + + while ((row = mysql_fetch_row(result))) { + int i; + for (i = 0; i < num_fields; i++) { + if (i == 0) { + while(field = mysql_fetch_field(result)) { + printf("| %s ", field->name); + } + printf("\n"); + } + printf("| %s ", row[i] ? row[i] : "NULL"); + } + } + mysql_free_result(result); + mysql_close(con); + exit(0); +} diff --git a/sql.h b/sql.h new file mode 100644 index 0000000..4d892c0 --- /dev/null +++ b/sql.h @@ -0,0 +1,7 @@ +#ifndef SQL_H +#define SQL_H + +int add_user(); + +#endif /* SQL_H */ +