fixed memory leaks, added cleanup code, added valgrind scripts to test binaries
This commit is contained in:
@@ -119,7 +119,7 @@ void _addSockets(GWEN_MSG_ENDPOINT *ep, GWEN_SOCKETSET *readSet, GWEN_SOCKETSET
|
||||
} /* if socket */
|
||||
}
|
||||
else if (xep->addSocketsFn) {
|
||||
DBG_INFO(AQH_LOGDOMAIN, "Endpoint %s: Not connected, calling base function", GWEN_MsgEndpoint_GetName(ep));
|
||||
DBG_DEBUG(AQH_LOGDOMAIN, "Endpoint %s: Not connected, calling base function", GWEN_MsgEndpoint_GetName(ep));
|
||||
xep->addSocketsFn(ep, readSet, writeSet, xSet);
|
||||
}
|
||||
} /* if (xep) */
|
||||
@@ -172,7 +172,7 @@ void _checkSockets(GWEN_MSG_ENDPOINT *ep, GWEN_SOCKETSET *readSet, GWEN_SOCKETSE
|
||||
}
|
||||
} /* if connected */
|
||||
else if (xep->checkSocketsFn) {
|
||||
DBG_INFO(AQH_LOGDOMAIN, "Endpoint %s: Not connected, calling base function", GWEN_MsgEndpoint_GetName(ep));
|
||||
DBG_DEBUG(AQH_LOGDOMAIN, "Endpoint %s: Not connected, calling base function", GWEN_MsgEndpoint_GetName(ep));
|
||||
xep->checkSocketsFn(ep, readSet, writeSet, xSet);
|
||||
}
|
||||
}
|
||||
@@ -208,7 +208,7 @@ int _writeCurrentMessage(GWEN_MSG_ENDPOINT *ep)
|
||||
}
|
||||
GWEN_Msg_IncCurrentPos(msg, rv);
|
||||
if (rv==remaining) {
|
||||
DBG_INFO(AQH_LOGDOMAIN, "Message completely sent");
|
||||
DBG_DEBUG(AQH_LOGDOMAIN, "Message completely sent");
|
||||
/* end current message */
|
||||
GWEN_Msg_List_Del(msg);
|
||||
GWEN_Msg_free(msg);
|
||||
@@ -216,7 +216,7 @@ int _writeCurrentMessage(GWEN_MSG_ENDPOINT *ep)
|
||||
}
|
||||
}
|
||||
else {
|
||||
DBG_INFO(AQH_LOGDOMAIN, "Nothing to send");
|
||||
DBG_DEBUG(AQH_LOGDOMAIN, "Nothing to send");
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@@ -309,7 +309,7 @@ int _distributeBufferInCommandMode(GWEN_MSG_ENDPOINT *ep, const uint8_t *bufferP
|
||||
const char *s;
|
||||
|
||||
/* line complete */
|
||||
DBG_INFO(AQH_LOGDOMAIN, "Command line complete");
|
||||
DBG_DEBUG(AQH_LOGDOMAIN, "Command line complete");
|
||||
rv=-rv;
|
||||
xep=GWEN_INHERIT_GETDATA(GWEN_MSG_ENDPOINT, AQH_ENDPOINT_HTTP, ep);
|
||||
|
||||
@@ -319,21 +319,21 @@ int _distributeBufferInCommandMode(GWEN_MSG_ENDPOINT *ep, const uint8_t *bufferP
|
||||
DBG_INFO(AQH_LOGDOMAIN, "Error parsing command line [%s]", GWEN_Buffer_GetStart(xep->currentReadBuffer));
|
||||
return GWEN_ERROR_BAD_DATA;
|
||||
}
|
||||
DBG_ERROR(AQH_LOGDOMAIN, "Command line received: %s", GWEN_Buffer_GetStart(xep->currentReadBuffer));
|
||||
DBG_DEBUG(AQH_LOGDOMAIN, "Command line received: %s", GWEN_Buffer_GetStart(xep->currentReadBuffer));
|
||||
s=GWEN_DB_GetCharValue(xep->dbCurrentReadCommand, "protocol", 0, "HTTP/0.9");
|
||||
if (s && *s && strcasecmp(s, "HTTP/0.9")==0) {
|
||||
DBG_INFO(AQH_LOGDOMAIN, "HTTP 0.9, no header, message finished");
|
||||
_finishMessageAndStartNext(ep);
|
||||
return rv;
|
||||
}
|
||||
DBG_INFO(AQH_LOGDOMAIN,
|
||||
DBG_DEBUG(AQH_LOGDOMAIN,
|
||||
"Command line complete, advancing to header read mode (start: %d)",
|
||||
GWEN_Buffer_GetPos(xep->currentReadBuffer));
|
||||
xep->readMode=AQH_EndpointHttpd_ReadMode_Headers;
|
||||
xep->currentHeaderPos=GWEN_Buffer_GetPos(xep->currentReadBuffer);
|
||||
}
|
||||
else {
|
||||
DBG_INFO(AQH_LOGDOMAIN, "Line not yet finished (%d)", rv);
|
||||
DBG_DEBUG(AQH_LOGDOMAIN, "Line not yet finished (%d)", rv);
|
||||
}
|
||||
|
||||
return rv;
|
||||
@@ -352,7 +352,7 @@ int _distributeBufferInStatusMode(GWEN_MSG_ENDPOINT *ep, const uint8_t *bufferPt
|
||||
/* line complete, TODO: parse status/command line */
|
||||
rv=-rv;
|
||||
xep=GWEN_INHERIT_GETDATA(GWEN_MSG_ENDPOINT, AQH_ENDPOINT_HTTP, ep);
|
||||
DBG_INFO(AQH_LOGDOMAIN, "Line complete, advancing to header read mode");
|
||||
DBG_DEBUG(AQH_LOGDOMAIN, "Line complete, advancing to header read mode");
|
||||
xep->readMode=AQH_EndpointHttpd_ReadMode_Headers;
|
||||
xep->currentBodyPos=GWEN_Buffer_GetPos(xep->currentReadBuffer);
|
||||
}
|
||||
@@ -382,7 +382,7 @@ int _distributeBufferInHeaderMode(GWEN_MSG_ENDPOINT *ep, const uint8_t *bufferPt
|
||||
int contentLength;
|
||||
|
||||
/* Empty line received, TODO: parse header */
|
||||
DBG_INFO(AQH_LOGDOMAIN, "Empty header line received, end of header reached (header pos: %d).", xep->currentHeaderPos);
|
||||
DBG_DEBUG(AQH_LOGDOMAIN, "Empty header line received, end of header reached (header pos: %d).", xep->currentHeaderPos);
|
||||
copyOfHeader=strdup(GWEN_Buffer_GetStart(xep->currentReadBuffer)+xep->currentHeaderPos);
|
||||
xep->dbCurrentReadHeader=GWEN_DB_Group_new("header");
|
||||
if (_parseHeader(copyOfHeader, xep->dbCurrentReadHeader)<0) {
|
||||
@@ -393,7 +393,7 @@ int _distributeBufferInHeaderMode(GWEN_MSG_ENDPOINT *ep, const uint8_t *bufferPt
|
||||
free(copyOfHeader);
|
||||
contentLength=GWEN_DB_GetIntValue(xep->dbCurrentReadHeader, "Content-Length", 0, -1);
|
||||
if (contentLength==0 || contentLength==-1) {
|
||||
DBG_INFO(AQH_LOGDOMAIN, "Message has no body, done");
|
||||
DBG_DEBUG(AQH_LOGDOMAIN, "Message has no body, done");
|
||||
_finishMessageAndStartNext(ep);
|
||||
}
|
||||
else {
|
||||
@@ -425,7 +425,7 @@ int _distributeBufferInBodyMode(GWEN_MSG_ENDPOINT *ep, const uint8_t *bufferPtr,
|
||||
GWEN_Buffer_AppendBytes(xep->currentReadBuffer, (const char*) bufferPtr, len);
|
||||
xep->remainingBodySize-=len;
|
||||
if (xep->remainingBodySize==0) {
|
||||
DBG_INFO(AQH_LOGDOMAIN, "Body completely received");
|
||||
DBG_DEBUG(AQH_LOGDOMAIN, "Body completely received");
|
||||
_finishMessageAndStartNext(ep);
|
||||
}
|
||||
return len;
|
||||
@@ -475,7 +475,7 @@ void _finishMessageAndStartNext(GWEN_MSG_ENDPOINT *ep)
|
||||
GWEN_MSG *msg;
|
||||
GWEN_DB_NODE *dbParsedData;
|
||||
|
||||
DBG_INFO(AQH_LOGDOMAIN, "Message completely received.");
|
||||
DBG_DEBUG(AQH_LOGDOMAIN, "Message completely received.");
|
||||
xep=GWEN_INHERIT_GETDATA(GWEN_MSG_ENDPOINT, AQH_ENDPOINT_HTTP, ep);
|
||||
|
||||
msg=GWEN_Msg_fromBytes((const uint8_t*)GWEN_Buffer_GetStart(xep->currentReadBuffer), GWEN_Buffer_GetUsedBytes(xep->currentReadBuffer));
|
||||
@@ -502,11 +502,11 @@ void _finishMessageAndStartNext(GWEN_MSG_ENDPOINT *ep)
|
||||
xep->dbCurrentReadHeader=NULL;
|
||||
|
||||
if (xep->flags & AQH_ENDPOINT_HTTP_FLAGS_PASSIVE) {
|
||||
DBG_INFO(AQH_LOGDOMAIN, "Passive connection");
|
||||
DBG_DEBUG(AQH_LOGDOMAIN, "Passive connection");
|
||||
xep->readMode=AQH_EndpointHttpd_ReadMode_Command;
|
||||
}
|
||||
else {
|
||||
DBG_INFO(AQH_LOGDOMAIN, "Active connection");
|
||||
DBG_DEBUG(AQH_LOGDOMAIN, "Active connection");
|
||||
xep->readMode=AQH_EndpointHttpd_ReadMode_Status;
|
||||
}
|
||||
}
|
||||
@@ -517,7 +517,7 @@ void _abortMessage(GWEN_MSG_ENDPOINT *ep)
|
||||
{
|
||||
AQH_ENDPOINT_HTTP *xep;
|
||||
|
||||
DBG_INFO(AQH_LOGDOMAIN, "Message completely received.");
|
||||
DBG_DEBUG(AQH_LOGDOMAIN, "Aborting message (if any).");
|
||||
xep=GWEN_INHERIT_GETDATA(GWEN_MSG_ENDPOINT, AQH_ENDPOINT_HTTP, ep);
|
||||
|
||||
GWEN_Buffer_Reset(xep->currentReadBuffer);
|
||||
@@ -587,7 +587,7 @@ int _parseHeader(char *bufferPtr, GWEN_DB_NODE *db)
|
||||
while (*p && (*p==32 || *p==9))
|
||||
p++;
|
||||
if (*p) {
|
||||
DBG_ERROR(AQH_LOGDOMAIN, "Setting header variable: [%s] = [%s]", pVarBegin, p);
|
||||
DBG_DEBUG(AQH_LOGDOMAIN, "Setting header variable: [%s] = [%s]", pVarBegin, p);
|
||||
GWEN_DB_SetCharValue(db, GWEN_PATH_FLAGS_CREATE_VAR, pVarBegin, p);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user