diff options
Diffstat (limited to 'agni.c')
-rw-r--r-- | agni.c | 65 |
1 files changed, 42 insertions, 23 deletions
@@ -34,6 +34,8 @@ #include "arg.h" +#include "nbrpc.h" + /* no defence programming, no error checking, no argument checking just PoC nothing else @@ -125,8 +127,8 @@ tble_cmd_resp* cllbk_wrapper( void *(*call)(void *), tble_cmd_param *param) } //dangerouse place =P - free(data_out); - free(data); + FREE(data_out); + FREE(data); return resp; } @@ -398,8 +400,8 @@ int th_start_client(void *data) write(conn.conn_fd, cmd_buf, fret); } - free(dest_user); dest_user = NULL; - free(resp_user); resp_user = NULL; + FREE(dest_user); + FREE(resp_user); //remove command by id //for now just remove command without checkings its state @@ -444,7 +446,7 @@ int th_start_client(void *data) irc_line = irc_buf_line(ib); if (irc_line) { - printf("PARSE>>%s<<\n",irc_line); + //printf("PARSE>>%s<<\n",irc_line); if (memcmp(irc_line,"PING",4)==0) @@ -530,21 +532,21 @@ int th_start_client(void *data) tbl_qcmd_add_tok(qcmd, itok); //HOW? add commands that are in execution list, dont process all messages tbl_qcmd_add(qtbl, qcmd); - tbl_qcmd_print_tbl(qtbl,TBL_PF_QCMD_ID - |TBL_PF_QCMD_CID - |TBL_PF_QCMD_STATE - |TBL_PF_QCMD_CMD - |TBL_PF_QCMD_PARAM - |TBL_PF_QCMD_TID - |TBL_PF_QCMD_TIDX); + //tbl_qcmd_print_tbl(qtbl,TBL_PF_QCMD_ID + // |TBL_PF_QCMD_CID + // |TBL_PF_QCMD_STATE + // |TBL_PF_QCMD_CMD + // |TBL_PF_QCMD_PARAM + // |TBL_PF_QCMD_TID + // |TBL_PF_QCMD_TIDX); } //create command and send to mq - PRINT("MSG %s\n",msg); + //PRINT("MSG %s\n",msg); mq_cmd *privcmd = mq_cmd_create(qcmd->cid,"PRIVMSG",strlen("PRIVMSG"),msg,strlen(msg)); char *bufPtr; bufPtr = mq_cmd_buf(privcmd); - PRINT("%s\n",bufPtr); + //PRINT("%s\n",bufPtr); PRINT("write %d bytes\n",mq_ntf_write(mq, MQ_OUT, bufPtr, strlen(bufPtr))); mq_cmd_free(privcmd); @@ -552,8 +554,8 @@ int th_start_client(void *data) qcmd = NULL; } - free(msg); - free(uname); + FREE(msg); + FREE(uname); } token_destroy(itok); itok = NULL; @@ -561,8 +563,7 @@ int th_start_client(void *data) if (irc_line!=NULL) { memset(irc_line,0,strlen(irc_line)); - free(irc_line); - irc_line = NULL; + FREE(irc_line); } __irc_buf_drain_io(ib); } @@ -753,7 +754,7 @@ int th_event_manager(void *data) mq_cur = &mq[i_mq]; if (mq_event == 1) { - PRINT("MQ_EVENT OUT\n"); + //PRINT("MQ_EVENT OUT\n"); memset(out_buf, 0, out_attr.mq_msgsize); //will fail if some of queue have different buffer size param if (mq_ntf_read(&mq[i_mq], MQ_OUT, out_buf, out_attr.mq_msgsize) == -1) @@ -854,7 +855,7 @@ int th_event_manager(void *data) } - free(out_buf); + FREE(out_buf); PNL(); printf("End event thread\n"); @@ -926,9 +927,12 @@ int main(int argc, char **argv) ERROR("BLow"); } srvc->user = alloc_new_str(isrvc.user); + IF_NULL(srvc->user,{},{ERROR("Cant allocate srvc->user\n")}); //srvc->password = alloc_new_str(isrvc.password); srvc->server = alloc_new_str(isrvc.server); + IF_NULL(srvc->user,{},{ERROR("Cant allocate srvc->server\n")}); srvc->port = alloc_new_str(isrvc.port); + IF_NULL(srvc->user,{},{ERROR("Cant allocate srvc->port\n")}); srvc->ssl = isrvc.ssl; //srvc->channels = isrvc.channels; for (j=0;j<SERV_CHAN_MAX_NUM;j++) @@ -936,6 +940,7 @@ int main(int argc, char **argv) if (isrvc.channels[j]) { srvc->channels[j] = alloc_new_str(isrvc.channels[j]); + IF_NULL(srvc->channels[j],{},{ERROR("Cannt alloc srvc->channels[j]\n");}) } else { srvc->channels[j] = NULL; @@ -958,17 +963,31 @@ int main(int argc, char **argv) PRINT("SERVER:%s PORT:%s USER:%s\n", srvc->server, srvc->port, srvc->user); /* clone new proc */ - clone(th_start_client, srvc->stack+STACK_SIZE, CLONE_VM|CLONE_FILES, (void *)srvc); + if (-1 == clone(th_start_client, srvc->stack+STACK_SIZE, CLONE_VM|CLONE_FILES, (void *)srvc)) + { + ERROR("Cant allocate new server process\n"); + } } /* event handler thread */ evhnd_cfg = malloc(sizeof(event_handler_cfg)); + if (evhnd_cfg == NULL) + { + ERROR("cant allocate event handler\n"); + } memset(evhnd_cfg, 0, sizeof(event_handler_cfg)); evhnd_cfg->stack = malloc(EVENT_HND_STACK_SIZE); + if (evhnd_cfg->stack == NULL) + { + ERROR("Cant allocate event handler stack\n"); + } atomic_store(&evhnd_cfg->running, 0); evhnd_cfg->mq_num = cnt_servers; evhnd_cfg->mq_listen = mq_array; - clone(th_event_manager, evhnd_cfg->stack+EVENT_HND_STACK_SIZE, CLONE_VM|CLONE_FILES, (void *)evhnd_cfg); + if (-1 == clone(th_event_manager, evhnd_cfg->stack+EVENT_HND_STACK_SIZE, CLONE_VM|CLONE_FILES, (void *)evhnd_cfg)) + { + ERROR("Couldnt create process\n"); + } //PNL(); /* wait a sec while all threads will start running */ @@ -991,7 +1010,7 @@ int main(int argc, char **argv) sleep(1); } - free(cfg_list); + FREE(cfg_list); ERROR("Exit\n"); |