implement some TODOs, add malloc checks and logging
r1984 | dcl | 2007-05-25 16:12:10 +1000 (Fri, 25 May 2007) | 2 lines
This commit is contained in:
@@ -48,7 +48,7 @@ int defaultHandleInput(pAsyncProtocol p, pAsyncTxn txn, int ch) {
|
||||
}
|
||||
|
||||
int defaultHandleEvent(pAsyncProtocol p, pAsyncTxn txn, int event) {
|
||||
/* TODO: handle the event */
|
||||
/* TODO: what could or should we do to handle the event */
|
||||
return AQU_POP_CMD;
|
||||
}
|
||||
|
||||
@@ -73,12 +73,20 @@ int defaultPrepareTxn(pAsyncProtocol p, pAsyncTxn txn, const char* cmd, int cmd_
|
||||
if (term[state] == 0) {
|
||||
/* outgoing command is correctly terminated */
|
||||
txn->out_buf = malloc(cmd_len + 1);
|
||||
if (txn->out_buf == NULL) {
|
||||
SICSLogWrite("Out of memory in AsyncProtocol::defaultPrepareTxn", eError);
|
||||
return 0;
|
||||
}
|
||||
memcpy(txn->out_buf, cmd, cmd_len + 1);
|
||||
}
|
||||
else {
|
||||
/* outgoing command is NOT correctly terminated */
|
||||
int tlen = strlen(term);
|
||||
txn->out_buf = malloc(cmd_len + tlen + 1);
|
||||
if (txn->out_buf == NULL) {
|
||||
SICSLogWrite("Out of memory in AsyncProtocol::defaultPrepareTxn", eError);
|
||||
return 0;
|
||||
}
|
||||
memcpy(txn->out_buf, cmd, cmd_len);
|
||||
memcpy(txn->out_buf + cmd_len, term, tlen + 1);
|
||||
cmd_len += tlen;
|
||||
@@ -86,6 +94,12 @@ int defaultPrepareTxn(pAsyncProtocol p, pAsyncTxn txn, const char* cmd, int cmd_
|
||||
txn->out_len = cmd_len;
|
||||
txn->out_idx = 0;
|
||||
txn->inp_buf = malloc(rsp_len);
|
||||
if (txn->inp_buf == NULL) {
|
||||
SICSLogWrite("Out of memory in AsyncProtocol::defaultPrepareTxn", eError);
|
||||
free(txn->out_buf);
|
||||
txn->out_buf = NULL;
|
||||
return 0;
|
||||
}
|
||||
txn->inp_len = rsp_len;
|
||||
txn->inp_idx = 0;
|
||||
txn->txn_state = 0;
|
||||
@@ -149,8 +163,10 @@ static char *decodeTerminator(char *code)
|
||||
return NULL;
|
||||
count = strlen(code);
|
||||
pResult = (char *) malloc(count + 1);
|
||||
if (!pResult)
|
||||
if (!pResult) {
|
||||
SICSLogWrite("Out of memory in AsyncProtocol::decodeTerminator", eError);
|
||||
return NULL;
|
||||
}
|
||||
memset(pResult, 0, count + 1);
|
||||
|
||||
pCh = pResult;
|
||||
@@ -217,7 +233,7 @@ int AsyncProtocolAction(SConnection *pCon, SicsInterp *pSics,
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
if (strcasecmp(argv[1], "replyterminator") == 0) {
|
||||
else if (strcasecmp(argv[1], "replyterminator") == 0) {
|
||||
if (argc > 2) {
|
||||
char* pPtr = decodeTerminator(argv[2]);
|
||||
if (pPtr) {
|
||||
@@ -238,13 +254,23 @@ int AsyncProtocolAction(SConnection *pCon, SicsInterp *pSics,
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
/* TODO: other actions */
|
||||
else if (strcasecmp(argv[1], "list") == 0) {
|
||||
int ac = 2;
|
||||
char* av[3] = { argv[0], 0, 0 };
|
||||
av[1] = "sendterminator";
|
||||
AsyncProtocolAction(pCon, pSics, pData, ac, av);
|
||||
av[1] = "replyterminator";
|
||||
AsyncProtocolAction(pCon, pSics, pData, ac, av);
|
||||
return 1;
|
||||
}
|
||||
/* handle any other actions here */
|
||||
return AsyncProtocolNoAction(pCon, pSics, pData, argc,argv);
|
||||
}
|
||||
|
||||
void defaultKillPrivate(pAsyncProtocol p) {
|
||||
if (p->privateData) {
|
||||
/* TODO: anything? */
|
||||
/* TODO: should we do anything? */
|
||||
free(p->privateData);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -252,7 +278,6 @@ void AsyncProtocolKill(void *pData) {
|
||||
pAsyncProtocol self = (pAsyncProtocol) pData;
|
||||
if(self->pDes)
|
||||
DeleteDescriptor(self->pDes);
|
||||
/* TODO: more destruction maybe */
|
||||
if(self->sendTerminator != NULL)
|
||||
free(self->sendTerminator);
|
||||
if(self->replyTerminator != NULL)
|
||||
@@ -274,7 +299,7 @@ pAsyncProtocol AsyncProtocolCreate(SicsInterp *pSics, const char* protocolName,
|
||||
|
||||
self = (pAsyncProtocol) malloc(sizeof(AsyncProtocol));
|
||||
if (self == NULL) {
|
||||
/* TODO */
|
||||
SICSLogWrite("Out of memory in AsyncProtocolCreate", eError);
|
||||
return NULL;
|
||||
}
|
||||
memset(self, 0, sizeof(AsyncProtocol));
|
||||
@@ -285,7 +310,7 @@ pAsyncProtocol AsyncProtocolCreate(SicsInterp *pSics, const char* protocolName,
|
||||
pKFunc = AsyncProtocolKill;
|
||||
iRet = AddCommand(pSics, protocolName, pFunc, pKFunc, self);
|
||||
if (!iRet ) {
|
||||
/* TODO */
|
||||
SICSLogWrite("AddCommand failed in AsyncProtocolCreate", eError);
|
||||
AsyncProtocolKill(self);
|
||||
return NULL;
|
||||
}
|
||||
@@ -307,7 +332,7 @@ int AsyncProtocolFactory(SConnection *pCon, SicsInterp *pSics,
|
||||
}
|
||||
pAsyncProtocol pNew = AsyncProtocolCreate(pSics, argv[1],
|
||||
AsyncProtocolAction, AsyncProtocolKill);
|
||||
/* TODO: handle arguments */
|
||||
/* handle any extra arguments here */
|
||||
pNew->privateData = NULL;
|
||||
return 1;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user