aqhome: cleanup AQH_HttpService_ParsePostBody().
This commit is contained in:
@@ -25,7 +25,7 @@ GWEN_INHERIT(AQH_SERVICE, AQH_HTTP_SERVICE)
|
||||
|
||||
static void GWENHYWFAR_CB _freeData(void *bp, void *p);
|
||||
|
||||
static int _checkHeaderGetBodySize(const GWEN_MSG *msgReceived);
|
||||
static int _parsePostBody(const char *s, int contentLength, GWEN_DB_NODE *dbBody);
|
||||
|
||||
|
||||
|
||||
@@ -230,15 +230,47 @@ void AQH_HttpService_AddHeader(AQH_SERVICE *sv, GWEN_DB_NODE *dbHeader, GWEN_BUF
|
||||
|
||||
int AQH_HttpService_ParsePostBody(AQH_SERVICE *sv, const GWEN_MSG *msgReceived, GWEN_DB_NODE *dbBody)
|
||||
{
|
||||
GWEN_DB_NODE *dbParsedInfo;
|
||||
GWEN_DB_NODE *dbHeader;
|
||||
const char *contentType;
|
||||
int contentLength;
|
||||
const char *s;
|
||||
|
||||
contentLength=_checkHeaderGetBodySize(msgReceived);
|
||||
dbParsedInfo=GWEN_Msg_GetDbParsedInfo(msgReceived);
|
||||
if (dbParsedInfo==NULL) {
|
||||
DBG_ERROR(AQH_LOGDOMAIN, "No parsed info in received message");
|
||||
return GWEN_ERROR_BAD_DATA;
|
||||
}
|
||||
dbHeader=GWEN_DB_GetGroup(dbParsedInfo, GWEN_PATH_FLAGS_PATHMUSTEXIST, "header");
|
||||
if (dbHeader==NULL) {
|
||||
DBG_ERROR(AQH_LOGDOMAIN, "No http header group in received message");
|
||||
return GWEN_ERROR_BAD_DATA;
|
||||
}
|
||||
|
||||
contentType=GWEN_DB_GetCharValue(dbHeader, "content-type", 0, NULL);
|
||||
if (!(contentType && *contentType && strcasecmp(contentType, "application/x-www-form-urlencoded")==0)) {
|
||||
DBG_ERROR(NULL, "Invalid or missing content type [%s]", contentType?contentType:"<no type>");
|
||||
return GWEN_ERROR_BAD_DATA;
|
||||
}
|
||||
|
||||
contentLength=GWEN_Msg_GetParsedPayloadSize(msgReceived);
|
||||
if (contentLength<1) {
|
||||
DBG_ERROR(NULL, "Empty message body");
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (contentLength<1) {
|
||||
DBG_ERROR(NULL, "Empty message body");
|
||||
return 0;
|
||||
}
|
||||
s=(const char*)(GWEN_Msg_GetConstBuffer(msgReceived)+GWEN_Msg_GetParsedPayloadOffset(msgReceived));
|
||||
return _parsePostBody(s, contentLength, dbBody);
|
||||
}
|
||||
|
||||
|
||||
|
||||
int _parsePostBody(const char *s, int contentLength, GWEN_DB_NODE *dbBody)
|
||||
{
|
||||
while(contentLength>0) {
|
||||
const char *sNameStart;
|
||||
int nameLen;
|
||||
@@ -289,40 +321,3 @@ int AQH_HttpService_ParsePostBody(AQH_SERVICE *sv, const GWEN_MSG *msgReceived,
|
||||
|
||||
|
||||
|
||||
int _checkHeaderGetBodySize(const GWEN_MSG *msgReceived)
|
||||
{
|
||||
GWEN_DB_NODE *dbParsedInfo;
|
||||
GWEN_DB_NODE *dbHeader;
|
||||
const char *contentType;
|
||||
int contentLength;
|
||||
|
||||
dbParsedInfo=GWEN_Msg_GetDbParsedInfo(msgReceived);
|
||||
if (dbParsedInfo==NULL) {
|
||||
DBG_ERROR(AQH_LOGDOMAIN, "No parsed info in received message");
|
||||
return GWEN_ERROR_BAD_DATA;
|
||||
}
|
||||
dbHeader=GWEN_DB_GetGroup(dbParsedInfo, GWEN_PATH_FLAGS_PATHMUSTEXIST, "header");
|
||||
if (dbHeader==NULL) {
|
||||
DBG_ERROR(AQH_LOGDOMAIN, "No http header group in received message");
|
||||
return GWEN_ERROR_BAD_DATA;
|
||||
}
|
||||
|
||||
contentType=GWEN_DB_GetCharValue(dbHeader, "content-type", 0, NULL);
|
||||
if (!(contentType && *contentType && strcasecmp(contentType, "application/x-www-form-urlencoded")==0)) {
|
||||
DBG_ERROR(NULL, "Invalid or missing content type [%s]", contentType?contentType:"<no type>");
|
||||
return GWEN_ERROR_BAD_DATA;
|
||||
}
|
||||
|
||||
contentLength=GWEN_Msg_GetParsedPayloadSize(msgReceived);
|
||||
if (contentLength<1) {
|
||||
DBG_ERROR(NULL, "Empty message body");
|
||||
return 0;
|
||||
}
|
||||
|
||||
return contentLength;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user