/************************************************************************************ * getHdrInfo: * * DESCRIPTION: * Function to store httpHdrBuffer (pointed by hdrBuf) information into pHdrInfo * * RETURN: * void ************************************************************************************/ static void getHdrInfo(HdrInfo_T * pHdrInfo, INKMBuffer hdrBuf, INKMLoc hdrLoc) { LOG_SET_FUNCTION_NAME("getHdrInfo"); INKMLoc urlLoc = NULL; const char *sHostName = NULL, *sHttpMethod = NULL, *sHttpHdrReason = NULL; int iHttpHdrReasonLength, iHttpMethodLength, iHostLength; if ((pHdrInfo->httpType = INKHttpHdrTypeGet(hdrBuf, hdrLoc)) == INK_ERROR) { LOG_API_ERROR("INKHttpHdrTypeGet"); } if ((pHdrInfo->hdrLength = INKHttpHdrLengthGet(hdrBuf, hdrLoc)) == INK_ERROR) { LOG_API_ERROR("INKHttpHdrLengthGet"); } if ((pHdrInfo->httpVersion = INKHttpHdrVersionGet(hdrBuf, hdrLoc)) == INK_ERROR) { LOG_API_ERROR("INKHttpHdrVersionGet"); } if (pHdrInfo->httpType == INK_HTTP_TYPE_REQUEST) { if ((sHttpMethod = INKHttpHdrMethodGet(hdrBuf, hdrLoc, &iHttpMethodLength)) == INK_ERROR_PTR) { LOG_API_ERROR("INKHttpHdrMethodGet"); } else { pHdrInfo->httpMethod = INKstrndup(sHttpMethod, iHttpMethodLength); } if ((urlLoc = INKHttpHdrUrlGet(hdrBuf, hdrLoc)) == INK_ERROR_PTR) { LOG_API_ERROR("INKHttpHdrUrlGet"); } else if ((sHostName = INKUrlHostGet(hdrBuf, urlLoc, &iHostLength)) == INK_ERROR_PTR) { LOG_API_ERROR("INKUrlHostGet"); } else { pHdrInfo->hostName = INKstrndup(sHostName, iHostLength); } /* Clean-up */ STR_RELEASE(hdrBuf, urlLoc, sHostName); STR_RELEASE(hdrBuf, urlLoc, sHttpMethod); HANDLE_RELEASE(hdrBuf, hdrLoc, urlLoc); } else if (pHdrInfo->httpType == INK_HTTP_TYPE_RESPONSE) { if ((pHdrInfo->httpStatus = INKHttpHdrStatusGet(hdrBuf, hdrLoc)) == INK_ERROR) { LOG_API_ERROR("INKHttpHdrStatusGet"); } if ((sHttpHdrReason = INKHttpHdrReasonGet(hdrBuf, hdrLoc, &iHttpHdrReasonLength)) == INK_ERROR_PTR) { LOG_API_ERROR("INKHttpHdrReasonGet"); } else if (sHttpHdrReason) { pHdrInfo->hdrReason = INKstrndup(sHttpHdrReason, iHttpHdrReasonLength); } /* clean-up */ STR_RELEASE(hdrBuf, hdrLoc, sHttpHdrReason); } else { LOG_AUTO_ERROR("getHdrInfo", "httpType unknown"); } }
/*********************************************************************** * Get the server ip and request method in the client request. Get the * next hop ip from the server response. * Create a new http header field MY_HDR in the server response and * insert server ip, request method and next hop ip into the field as * field values. ***********************************************************************/ static int handle_response_hdr(INKCont contp, INKHttpTxn txnp) { LOG_SET_FUNCTION_NAME("handle_response_hdr"); INKMBuffer resp_bufp; INKMLoc resp_loc = NULL; INKMLoc field_loc = NULL; unsigned int next_hop_ip = 0; unsigned int server_ip = 0; const char *request_method = NULL; char *r_method = NULL; int length; INKMBuffer req_bufp; INKMLoc req_loc = NULL; int incoming_port = 0, port = 0; char *hostname = NULL; int ret_value = -1; /* negative test */ #ifdef DEBUG if (INKHttpTxnServerIPGet(NULL) != 0) LOG_ERROR_NEG("INKHttpTxnServerIPGet"); if (INKHttpTxnNextHopIPGet(NULL) != 0) LOG_ERROR_NEG("INKHttpTxnNextHopIPGet"); if (INKHttpTxnParentProxyGet(NULL, &hostname, &port) != INK_ERROR) LOG_ERROR_NEG("INKHttpTxnParentProxyGet"); #endif /* get the server ip */ if ((server_ip = INKHttpTxnServerIPGet(txnp)) == 0) LOG_ERROR_AND_RETURN("INKHttpTxnServerIPGet"); /* get the request method */ if (!INKHttpTxnServerReqGet(txnp, &req_bufp, &req_loc)) LOG_ERROR_AND_RETURN("INKHttpTxnServerReqGet"); if ((request_method = INKHttpHdrMethodGet(req_bufp, req_loc, &length)) == INK_ERROR_PTR || request_method == NULL) LOG_ERROR_AND_CLEANUP("INKHttpHdrMethodGet"); r_method = INKstrndup(request_method, length); /* get the next hop ip */ if ((next_hop_ip = INKHttpTxnNextHopIPGet(txnp)) == INK_ERROR) LOG_ERROR_AND_CLEANUP("INKHttpTxnNextHopIPGet"); /* get the client incoming port */ if ((incoming_port = INKHttpTxnClientIncomingPortGet(txnp)) == INK_ERROR) LOG_ERROR_AND_CLEANUP("INKHttpTxnClientIncomingPortGet"); /* get the parent proxy */ if (INKHttpTxnParentProxyGet(txnp, &hostname, &port) == INK_ERROR) LOG_ERROR_AND_CLEANUP("INKHttpTxnParentProxyGet"); /* If no parent defined in records.config, set hostname to NULL and port to -1 */ if (hostname == NULL) { hostname = "NULL"; port = -1; } /* retrieve the server response header */ if (!INKHttpTxnServerRespGet(txnp, &resp_bufp, &resp_loc)) LOG_ERROR_AND_CLEANUP("INKHttpTxnServerRespGet"); /* create and insert into hdr a new mime header field */ if ((field_loc = INKMimeHdrFieldCreate(resp_bufp, resp_loc)) == INK_ERROR_PTR || field_loc == NULL) LOG_ERROR_AND_CLEANUP("INKMimeHdrFieldCreate"); if (INKMimeHdrFieldAppend(resp_bufp, resp_loc, field_loc) == INK_ERROR) LOG_ERROR_AND_CLEANUP("INKMimeHdrFieldAppend"); if (INKMimeHdrFieldNameSet(resp_bufp, resp_loc, field_loc, MY_HDR, strlen(MY_HDR)) == INK_ERROR) LOG_ERROR_AND_CLEANUP("INKMimeHdrFieldNameSet"); /* Add value to the new mime header field */ if (INKMimeHdrFieldValueStringInsert(resp_bufp, resp_loc, field_loc, -1, r_method, strlen(r_method)) == INK_ERROR) LOG_ERROR_AND_CLEANUP("INKMimeHdrFieldValueStringInsert"); if (INKMimeHdrFieldValueUintInsert(resp_bufp, resp_loc, field_loc, -1, server_ip) == INK_ERROR) LOG_ERROR_AND_CLEANUP("INKMimeHdrFieldValueUintInsert"); if (INKMimeHdrFieldValueUintInsert(resp_bufp, resp_loc, field_loc, -1, next_hop_ip) == INK_ERROR) LOG_ERROR_AND_CLEANUP("INKMimeHdrFieldValueUintInsert"); if (INKMimeHdrFieldValueIntInsert(resp_bufp, resp_loc, field_loc, -1, incoming_port) == INK_ERROR) LOG_ERROR_AND_CLEANUP("INKMimeHdrFieldValueIntInsert"); if (INKMimeHdrFieldValueIntInsert(resp_bufp, resp_loc, field_loc, -1, port) == INK_ERROR) LOG_ERROR_AND_CLEANUP("INKMimeHdrFieldValueIntInsert"); /* success */ ret_value = 0; Lcleanup: if (VALID_POINTER(r_method)) INKfree(r_method); /* negative test for INKHandleStringRelease */ #ifdef DEBUG if (INKHandleStringRelease(NULL, req_loc, request_method) != INK_ERROR) { LOG_ERROR_NEG("INKHandleStringRelease"); } #endif /* release the buffer handles */ if (VALID_POINTER(request_method)) INKHandleStringRelease(req_bufp, req_loc, request_method); if (VALID_POINTER(req_loc)) INKHandleMLocRelease(req_bufp, INK_NULL_MLOC, req_loc); /* free the handles and continuation data */ if (VALID_POINTER(field_loc)) INKHandleMLocRelease(resp_bufp, resp_loc, field_loc); if (VALID_POINTER(resp_loc)) INKHandleMLocRelease(resp_bufp, INK_NULL_MLOC, resp_loc); return ret_value; }
static void handleReadRequest(INKCont pCont, INKHttpTxn pTxn) { LOG_SET_FUNCTION_NAME("handleReadRequest"); INKMBuffer reqHdrBuf = NULL, newHttpHdrBuf = NULL; INKMLoc reqHdrLoc = NULL, newHttpHdrLoc = NULL; INKHttpType httpType; int iOldHttpVersion, iHttpMethodLength, iHttpVersion; const char *sHttpMethod = NULL; char *outputString = NULL, *sOldHttpMethod = NULL; HdrInfo_T *pReqHdrInfo = NULL, *pNewReqHdrInfo = NULL; #if 0 const char *constant_request_header_str = "GET http://www.joes-hardware.com/ HTTP/1.0\r\nDate: Wed, 05 Jul 2000 22:12:26 GMT\r\nConnection: Keep-Alive\r\nUser-Agent: Mozilla/4.51 [en] (X11; U; IRIX 6.2 IP22)\r\nHost: www.joes-hardware.com\r\nCache-Control: no-cache\r\nAccept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, image/png, */*\r\nAccept-Charset: iso-8859-1,*,utf-8\r\nAccept-Encoding: gzip\r\nAccept-Language: en\r\nX-Number-Header: 12345\r\nX-Silly-Header: frobnichek grobbledegook\r\nAccept-Charset: windows-1250, koi8-r\r\nX-Silly-Header: wawaaa\r\n\r\n"; #endif pReqHdrInfo = initHdr(); pNewReqHdrInfo = initHdr(); INKDebug(REQ, "\n>>>>>> handleReadRequest <<<<<<<\n"); /* Get Request Marshall Buffer */ if (!INKHttpTxnClientReqGet(pTxn, &reqHdrBuf, &reqHdrLoc)) { LOG_API_ERROR_COMMENT("INKHttpTxnClientReqGet", "ERROR: Can't retrieve client req hdr"); goto done; } /******* (1): Get every specifics from the HTTP header *********/ INKDebug(REQ, "--------------------------------"); getHdrInfo(pReqHdrInfo, reqHdrBuf, reqHdrLoc); printHttpHeader(reqHdrBuf, reqHdrLoc, REQ, 1); #ifdef DEBUG negTesting(reqHdrBuf, reqHdrLoc); #endif /*********** (2): Create/Copy/Destroy **********/ /* For every request, create, copy and destroy a new HTTP header and * print the details */ INKDebug(REQ, "--------------------------------"); if ((newHttpHdrBuf = INKMBufferCreate()) == INK_ERROR_PTR) { LOG_API_ERROR_COMMENT("INKMBufferCreate", "skipping to section 3"); goto section_3; /* Skip to section (3) down the line directly; I hate GOTOs */ } /*** INKHttpHdrCreate ***/ if ((newHttpHdrLoc = INKHttpHdrCreate(newHttpHdrBuf)) == INK_ERROR_PTR) { LOG_API_ERROR_COMMENT("INKHttpHdrCreate", "skipping to section 3"); goto section_3; /* Skip to section (3) down the line directly; I hate GOTOs */ } /* Make sure the newly created HTTP header has INKHttpType value of INK_HTTP_TYPE_UNKNOWN */ if ((httpType = INKHttpHdrTypeGet(newHttpHdrBuf, newHttpHdrLoc)) == INK_ERROR) { LOG_API_ERROR_COMMENT("INKHttpHdrTypeGet", "but still continuing..."); } else if (httpType != INK_HTTP_TYPE_UNKNOWN) { LOG_AUTO_ERROR("INKHttpHdrCreate", "Newly created hdr not of type INK_HTTP_TYPE_UNKNOWN"); } /* set the HTTP header type: a new buffer has a type INK_HTTP_TYPE_UNKNOWN by default */ if (INKHttpHdrTypeSet(newHttpHdrBuf, newHttpHdrLoc, INK_HTTP_TYPE_REQUEST) == INK_ERROR) { LOG_API_ERROR_COMMENT("INKHttpHdrTypeSet", "unable to set it to INK_HTTP_TYPE_REQUEST"); } else if ((httpType = INKHttpHdrTypeGet(newHttpHdrBuf, newHttpHdrLoc)) == INK_ERROR) { LOG_API_ERROR_COMMENT("INKHttpHdrTypeGet", "still continuing"); } else if (httpType != INK_HTTP_TYPE_REQUEST) { LOG_AUTO_ERROR("INKHttpHdrTypeSet", "Type not set to INK_HTTP_TYPE_REQUEST"); } /*** INKHttpHdrCopy ***/ if (INKHttpHdrCopy(newHttpHdrBuf, newHttpHdrLoc, reqHdrBuf, reqHdrLoc) == INK_ERROR) { LOG_API_ERROR("INKHttpHdrCopy"); } getHdrInfo(pNewReqHdrInfo, newHttpHdrBuf, newHttpHdrLoc); if (!identical_hdr(pNewReqHdrInfo, pReqHdrInfo)) { LOG_AUTO_ERROR("INKHttpHdrCopy", "New req buffer not identical to the original"); } printHttpHeader(newHttpHdrBuf, newHttpHdrLoc, REQ, 2); FREE(pNewReqHdrInfo->httpMethod); FREE(pNewReqHdrInfo->hostName); section_3: /********* (3): Excercise all the INK__Set on ReqBuf *********/ INKDebug(REQ, "--------------------------------"); /*** INKHttpHdrMethodSet ***/ /* save the original method */ if ((sHttpMethod = INKHttpHdrMethodGet(reqHdrBuf, reqHdrLoc, &iHttpMethodLength)) == INK_ERROR_PTR) { LOG_API_ERROR("INKHttpHdrMethodGet"); } else { sOldHttpMethod = INKstrndup(sHttpMethod, iHttpMethodLength); } /* change it to some unknown method */ if (INKHttpHdrMethodSet(reqHdrBuf, reqHdrLoc, "FOOBAR", strlen("FOOBAR")) == INK_ERROR) { LOG_API_ERROR("INKHttpHdrMethodSet"); } else { if ((sHttpMethod = INKHttpHdrMethodGet(reqHdrBuf, reqHdrLoc, &iHttpMethodLength)) == INK_ERROR_PTR) { LOG_API_ERROR("INKHttpHdrMethodGet"); } else if (strncmp(sHttpMethod, "FOOBAR", iHttpMethodLength)) { LOG_AUTO_ERROR("INKHttpHdrMethodSet/Get", "GET method different from SET method"); } } outputString = INKstrndup(sHttpMethod, iHttpMethodLength); INKDebug(REQ, "(3): new HTTP Header Method = %s", outputString); FREE(outputString); STR_RELEASE(reqHdrBuf, reqHdrLoc, sHttpMethod); printHttpHeader(reqHdrBuf, reqHdrLoc, REQ, 3); /* set it back to the original method */ /*INKHttpHdrMethodSet (reqHdrBuf, reqHdrLoc, sOldHttpMethod, iHttpMethodLength); */ if (INKHttpHdrMethodSet(reqHdrBuf, reqHdrLoc, sOldHttpMethod, strlen(sOldHttpMethod)) == INK_ERROR) { LOG_API_ERROR("INKHttpHdrMethodSet"); } else if ((sHttpMethod = INKHttpHdrMethodGet(reqHdrBuf, reqHdrLoc, &iHttpMethodLength)) == INK_ERROR_PTR) { LOG_API_ERROR("INKHttpHdrMethodGet"); } else if (strncmp(sHttpMethod, sOldHttpMethod, iHttpMethodLength)) { LOG_AUTO_ERROR("INKHttpHdrMethodSet/Get", "GET method different from SET method"); } outputString = INKstrndup(sHttpMethod, iHttpMethodLength); INKDebug(REQ, "(3): original HTTP Header Method = %s", outputString); FREE(outputString); STR_RELEASE(reqHdrBuf, reqHdrLoc, sHttpMethod); /*** INKHttpHdrVersionSet ***/ /* get the original version */ if ((iOldHttpVersion = INKHttpHdrVersionGet(reqHdrBuf, reqHdrLoc)) == INK_ERROR) { LOG_API_ERROR("INKHttpHdrVersionGet"); } /* change it to some unknown version */ if (INKHttpHdrVersionSet(reqHdrBuf, reqHdrLoc, INK_HTTP_VERSION(10, 10)) == INK_ERROR) { LOG_API_ERROR("INKHttpHdrVersionSet"); } else if ((iHttpVersion = INKHttpHdrVersionGet(reqHdrBuf, reqHdrLoc)) == INK_ERROR) { LOG_API_ERROR("INKHttpHdrVersionGet"); } else if ((INK_HTTP_MAJOR(iHttpVersion) != 10) || (INK_HTTP_MINOR(iHttpVersion) != 10)) { LOG_AUTO_ERROR("INKHttpHdrVersionSet/Get", "SET HTTP version different from GET version"); } INKDebug(REQ, "(3): new HTTP version; Major = %d Minor = %d", INK_HTTP_MAJOR(iHttpVersion), INK_HTTP_MINOR(iHttpVersion)); /* change it back to the original version */ if (INKHttpHdrVersionSet(reqHdrBuf, reqHdrLoc, iOldHttpVersion) == INK_ERROR) { LOG_API_ERROR("INKHttpHdrVersionSet"); } else if ((iHttpVersion = INKHttpHdrVersionGet(reqHdrBuf, reqHdrLoc)) == INK_ERROR) { LOG_API_ERROR("INKHttpHdrVersionGet"); } else if (iHttpVersion != iOldHttpVersion) { LOG_AUTO_ERROR("INKHttpHdrVersionSet/Get", "SET HTTP version different from GET version"); } getHdrInfo(pNewReqHdrInfo, reqHdrBuf, reqHdrLoc); if (!identical_hdr(pNewReqHdrInfo, pReqHdrInfo)) { LOG_AUTO_ERROR("INK..Set", "ReqBuf: Values not restored properly"); } /* (3): clean-up */ FREE(sOldHttpMethod); done: /*************** Clean-up ***********************/ /* FREE(pReqHdrInfo->httpMethod); FREE(pReqHdrInfo->hostName); FREE(pNewReqHdrInfo->httpMethod); FREE(pNewReqHdrInfo->hostName); FREE(pReqHdrInfo); FREE(pNewReqHdrInfo); */ freeHdr(pReqHdrInfo); freeHdr(pNewReqHdrInfo); /* release hdrLoc */ HANDLE_RELEASE(reqHdrBuf, INK_NULL_MLOC, reqHdrLoc); HANDLE_RELEASE(newHttpHdrBuf, INK_NULL_MLOC, newHttpHdrLoc); /* destroy hdr */ HDR_DESTROY(newHttpHdrBuf, newHttpHdrLoc); /* destroy mbuffer */ BUFFER_DESTROY(newHttpHdrBuf); if (INKHttpTxnReenable(pTxn, INK_EVENT_HTTP_CONTINUE) == INK_ERROR) { LOG_API_ERROR("INKHttpTxnReenable"); } INKDebug(REQ, "..... exiting handleReadRequest ......\n"); } /* handleReadReadRequest */
static void printHttpHeader(INKMBuffer hdrBuf, INKMLoc hdrLoc, char *debugTag, float section) { LOG_SET_FUNCTION_NAME("printHttpHeader"); INKMLoc urlLoc = NULL; INKHttpStatus httpStatus; INKHttpType httpType; int iHostLength, iHttpHdrLength, iHttpMethodLength, iHttpHdrReasonLength, iHttpVersion; const char *sHostName = NULL, *sHttpMethod = NULL, *sHttpHdrReason = NULL; char *outputString = NULL; /*** INKHttpHdrTypeGet ***/ if ((httpType = INKHttpHdrTypeGet(hdrBuf, hdrLoc)) == INK_ERROR) { LOG_API_ERROR("INKHttpHdrTypeGet"); } INKDebug(debugTag, "(%g) HTTP Header Type = %d", section, httpType); /*** INKHttpHdrLengthGet ***/ if ((iHttpHdrLength = INKHttpHdrLengthGet(hdrBuf, hdrLoc)) == INK_ERROR) { LOG_API_ERROR("INKHttpHdrLengthGet"); } INKDebug(debugTag, "(%g) HTTP Header Length = %d", section, iHttpHdrLength); /*** INKHttpVersionGet ***/ if ((iHttpVersion = INKHttpHdrVersionGet(hdrBuf, hdrLoc)) == INK_ERROR) { LOG_API_ERROR("INKHttpHdrVersionGet"); } INKDebug(debugTag, "(%g) HTTP Header Version = %d", section, iHttpVersion); INKDebug(debugTag, "(%g) Major Version = %d, Minor Version = %d", section, INK_HTTP_MAJOR(iHttpVersion), INK_HTTP_MINOR(iHttpVersion)); if (httpType == INK_HTTP_TYPE_REQUEST) { /*** INKHttpHdrMethodGet ***/ if ((sHttpMethod = INKHttpHdrMethodGet(hdrBuf, hdrLoc, &iHttpMethodLength)) == INK_ERROR_PTR) { LOG_API_ERROR("INKHttpHdrMethodGet"); } else { outputString = INKstrndup(sHttpMethod, iHttpMethodLength); INKDebug(debugTag, "(%g) HTTP Header Method = %s", section, outputString); FREE(outputString); STR_RELEASE(hdrBuf, urlLoc, sHttpMethod); } /*** INKHttpHdrUrlGet ***/ if ((urlLoc = INKHttpHdrUrlGet(hdrBuf, hdrLoc)) == INK_ERROR_PTR) { LOG_API_ERROR("INKHttpHdrUrlGet"); } else if ((sHostName = INKUrlHostGet(hdrBuf, urlLoc, &iHostLength)) == INK_ERROR_PTR) { LOG_API_ERROR("INKUrlHostGet"); } else if (sHostName) { outputString = INKstrndup(sHostName, iHostLength); INKDebug(debugTag, "(%g) HTTP Host = %s", section, outputString); FREE(outputString); STR_RELEASE(hdrBuf, urlLoc, sHostName); } /* Clean-up */ HANDLE_RELEASE(hdrBuf, hdrLoc, urlLoc); } else if (httpType == INK_HTTP_TYPE_RESPONSE) { /*** INKHttpHdrReasonGet ***/ /* Try getting reason phrase from the request header - this is an error */ if ((sHttpHdrReason = INKHttpHdrReasonGet(hdrBuf, hdrLoc, &iHttpHdrReasonLength)) == INK_ERROR_PTR) { LOG_API_ERROR("INKHttpHdrReasonGet"); } else { outputString = INKstrndup(sHttpHdrReason, iHttpHdrReasonLength); INKDebug(debugTag, "(%g) HTTP Header Reason = %s", section, outputString); FREE(outputString); STR_RELEASE(hdrBuf, hdrLoc, sHttpHdrReason); } /*** INKHttpHdrStatusGet ***/ /* Try getting status phrase from the request header - this is an error */ if ((httpStatus = INKHttpHdrStatusGet(hdrBuf, hdrLoc)) == INK_ERROR) { LOG_API_ERROR("INKHttpHdrStatusGet"); } else { INKDebug(debugTag, "(%g) HTTP Header Status = %d", section, httpStatus); } } }
void negTesting(INKMBuffer hdrBuf, INKMLoc httpHdrLoc) { LOG_SET_FUNCTION_NAME("negTesting"); INKMBuffer negHdrBuf = NULL; INKMLoc negHttpHdrLoc = NULL; INKHttpType negType, hdrHttpType; INKHttpStatus httpStatus; const char *sHttpReason = NULL; int iHttpMethodLength, iHttpHdrReasonLength; /* INKMBufferCreate: Nothing to neg test */ /* INKMBufferDestroy */ if (INKMBufferDestroy(NULL) != INK_ERROR) { LOG_NEG_ERROR("INKMBufferDestroy"); } /* INKHttpHdrCreate */ if (INKHttpHdrCreate(NULL) != INK_ERROR_PTR) { LOG_NEG_ERROR("INKHttpHdrCreate"); } /* INKHttpHdrCopy */ /* Copy w/o creating the hdrBuf and httpHdrLoc */ if (INKHttpHdrCopy(negHdrBuf, negHttpHdrLoc, hdrBuf, httpHdrLoc) != INK_ERROR) { LOG_NEG_ERROR("INKHttpHdrCopy"); } /* valid create */ if ((negHdrBuf = INKMBufferCreate()) == INK_ERROR_PTR) { LOG_API_ERROR("INKHttpHdrCreate"); } if ((negHttpHdrLoc = INKHttpHdrCreate(negHdrBuf)) == INK_ERROR_PTR) { LOG_API_ERROR("INKMHttpHdrCreate"); } if (INKHttpHdrCopy(NULL, negHttpHdrLoc, hdrBuf, httpHdrLoc) != INK_ERROR) { LOG_NEG_ERROR("INKHttpHdrCopy"); } if (INKHttpHdrCopy(negHdrBuf, NULL, hdrBuf, httpHdrLoc) != INK_ERROR) { LOG_NEG_ERROR("INKHttpHdrCopy"); } if (INKHttpHdrCopy(negHdrBuf, negHttpHdrLoc, NULL, httpHdrLoc) != INK_ERROR) { LOG_NEG_ERROR("INKHttpHdrCopy"); } if (INKHttpHdrCopy(negHdrBuf, negHttpHdrLoc, hdrBuf, NULL) != INK_ERROR) { LOG_NEG_ERROR("INKHttpHdrCopy"); } /* INKHttpHdrTypeSet */ /* Docs - INKHttpHdrTypeSet should NOT be called after INKHttpHdrCopy */ /* Try some incorrect (but valid int type) arguments */ if (INKHttpHdrTypeSet(negHdrBuf, negHttpHdrLoc, 10) != INK_ERROR) { LOG_NEG_ERROR("INKHttpHdrTypeSet"); } if (INKHttpHdrTypeSet(negHdrBuf, negHttpHdrLoc, -1) != INK_ERROR) { LOG_NEG_ERROR("INKHttpHdrTypeSet"); } if (INKHttpHdrTypeSet(NULL, negHttpHdrLoc, INK_HTTP_TYPE_RESPONSE) != INK_ERROR) { LOG_NEG_ERROR("INKHttpHdrTypeSet"); } if (INKHttpHdrTypeSet(negHdrBuf, NULL, INK_HTTP_TYPE_RESPONSE) != INK_ERROR) { LOG_NEG_ERROR("INKHttpHdrTypeSet"); } /* INKqa12708 */ if (INKHttpHdrTypeSet(negHdrBuf, negHttpHdrLoc, 100) != INK_ERROR) { LOG_NEG_ERROR("INKHttpHdrTypeSet"); } /* INKHtttpHdrTypeGet */ if ((negType = INKHttpHdrTypeGet(NULL, negHttpHdrLoc)) != INK_ERROR) { LOG_NEG_ERROR("INKHttpHdrTypeGet"); } if ((negType = INKHttpHdrTypeGet(negHdrBuf, NULL)) != INK_ERROR) { LOG_NEG_ERROR("INKHttpHdrTypeGet"); } /* INKHttpHdrVersionGet */ if (INKHttpHdrVersionGet(NULL, negHttpHdrLoc) != INK_ERROR) { LOG_NEG_ERROR("INKHttpHdrVersionGet"); } if (INKHttpHdrVersionGet(negHdrBuf, NULL) != INK_ERROR) { LOG_NEG_ERROR("INKHttpHdrVersionGet"); } /* INKHttpHdrVersionSet */ if (INKHttpHdrVersionSet(NULL, negHttpHdrLoc, INK_HTTP_VERSION(1, 1)) != INK_ERROR) { LOG_NEG_ERROR("INKHttpHdrVersionSet"); } if (INKHttpHdrVersionSet(negHdrBuf, NULL, INK_HTTP_VERSION(1, 1)) != INK_ERROR) { LOG_NEG_ERROR("INKHttpHdrVersionSet"); } /* Try some incorrect (but valid int type) arguments */ if (INKHttpHdrVersionSet(negHdrBuf, negHttpHdrLoc, 0) == INK_ERROR) { LOG_NEG_ERROR("INKHttpHdrVersionSet"); } if (INKHttpHdrVersionSet(negHdrBuf, negHttpHdrLoc, -1) == INK_ERROR) { LOG_NEG_ERROR("INKHttpHdrVersionSet"); } /* INKHttpHdrLengthGet */ if (INKHttpHdrLengthGet(NULL, negHttpHdrLoc) != INK_ERROR) { LOG_NEG_ERROR("INKHttpHdrLengthGet"); } if (INKHttpHdrLengthGet(negHdrBuf, NULL) != INK_ERROR) { LOG_NEG_ERROR("INKHttpHdrLengthGet"); } /* valid copy */ if (INKHttpHdrCopy(negHdrBuf, negHttpHdrLoc, hdrBuf, httpHdrLoc) == INK_ERROR) { LOG_API_ERROR("INKHttpHdrCopy"); } if ((hdrHttpType = INKHttpHdrTypeGet(negHdrBuf, negHttpHdrLoc)) == INK_ERROR) { LOG_API_ERROR("INKHttpHdrTypeGet"); } if (hdrHttpType == INK_HTTP_TYPE_REQUEST) { /* INKHttpHdrUrlGet */ if (INKHttpHdrUrlGet(NULL, negHttpHdrLoc) != INK_ERROR_PTR) { LOG_NEG_ERROR("INKHttpHdrUrlGet"); } if (INKHttpHdrUrlGet(negHdrBuf, NULL) != INK_ERROR_PTR) { LOG_NEG_ERROR("INKHttpHdrUrlGet"); } /* INKHttpHdrMethodGet */ if (INKHttpHdrMethodGet(NULL, negHttpHdrLoc, &iHttpMethodLength) != INK_ERROR_PTR) { LOG_NEG_ERROR("INKHttpHdrMethodGet"); } if (INKHttpHdrMethodGet(negHdrBuf, NULL, &iHttpMethodLength) != INK_ERROR_PTR) { LOG_NEG_ERROR("INKHttpHdrMethodGet"); } if (INKHttpHdrMethodGet(negHdrBuf, negHttpHdrLoc, NULL) == INK_ERROR_PTR) { LOG_NEG_ERROR("INKHttpHdrMethodGet"); } /* INKHttpHdrMethodSet */ if (INKHttpHdrMethodSet(NULL, negHttpHdrLoc, "FOOBAR", strlen("FOOBAR")) != INK_ERROR) { LOG_NEG_ERROR("INKHttpHdrMethodSet"); } if (INKHttpHdrMethodSet(negHdrBuf, NULL, "FOOBAR", strlen("FOOBAR")) != INK_ERROR) { LOG_NEG_ERROR("INKHttpHdrMethodSet"); } /* INKqa12722 */ if (INKHttpHdrMethodSet(negHdrBuf, negHttpHdrLoc, NULL, -1) != INK_ERROR) { LOG_NEG_ERROR("INKHttpHdrMethodSet"); } /* FIXME: This neg test would crash TS */ /* NOTE: This is a valid (corner) test case */ if (INKHttpHdrMethodSet(negHdrBuf, negHttpHdrLoc, "", -1) == INK_ERROR) { LOG_NEG_ERROR("INKHttpHdrMethodSet"); } } else if (hdrHttpType == INK_HTTP_TYPE_RESPONSE) { /* INKHttpHdrStatusGet */ if (INKHttpHdrStatusGet(NULL, negHttpHdrLoc) != INK_ERROR) { LOG_NEG_ERROR("INKHttpHdrStatusGet"); } if (INKHttpHdrStatusGet(negHdrBuf, NULL) != INK_ERROR) { LOG_NEG_ERROR("INKHttpHdrStatusGet"); } /* INKHttpHdrStatusSet */ /* valid status get */ if ((httpStatus = INKHttpHdrStatusGet(negHdrBuf, negHttpHdrLoc)) == INK_ERROR) { LOG_API_ERROR("INKHttpHdrStatusGet"); } if (INKHttpHdrStatusSet(NULL, negHttpHdrLoc, httpStatus) != INK_ERROR) { LOG_NEG_ERROR("INKHttpHdrStatusSet"); } if (INKHttpHdrStatusSet(negHdrBuf, NULL, httpStatus) != INK_ERROR) { LOG_NEG_ERROR("INKHttpHdrStatusSet"); } /* setting status = NULL is NOT an error */ if (INKHttpHdrStatusSet(negHdrBuf, negHttpHdrLoc, -1) == INK_ERROR) { LOG_NEG_ERROR("INKHttpHdrStatusSet"); } /* INKHttpHdrReasonGet */ /* valid reason get */ if ((sHttpReason = INKHttpHdrReasonGet(negHdrBuf, negHttpHdrLoc, &iHttpHdrReasonLength)) == INK_ERROR_PTR) { LOG_API_ERROR("INKHttpHdrReasonGet"); } if (INKHttpHdrReasonGet(NULL, negHttpHdrLoc, &iHttpHdrReasonLength) != INK_ERROR_PTR) { LOG_NEG_ERROR("INKHttpHdrReasonGet"); } if (INKHttpHdrReasonGet(negHdrBuf, NULL, &iHttpHdrReasonLength) != INK_ERROR_PTR) { LOG_NEG_ERROR("INKHttpHdrReasonGet"); } /* NULL is a valid length arg */ if (INKHttpHdrReasonGet(negHdrBuf, negHttpHdrLoc, NULL) == INK_ERROR_PTR) { LOG_NEG_ERROR("INKHttpHdrReasonGet"); } /* INKHttpHdrReasonSet */ if (INKHttpHdrReasonSet(NULL, negHttpHdrLoc, sHttpReason, iHttpHdrReasonLength) != INK_ERROR) { LOG_NEG_ERROR("INKHttpHdrReasonSet"); } if (INKHttpHdrReasonSet(negHdrBuf, NULL, sHttpReason, iHttpHdrReasonLength) != INK_ERROR) { LOG_NEG_ERROR("INKHttpHdrReasonSet"); } /* NOTE: INKqa12722: NULL reason arg fixed now */ if (INKHttpHdrReasonSet(negHdrBuf, negHttpHdrLoc, NULL, iHttpHdrReasonLength) != INK_ERROR) { LOG_NEG_ERROR("INKHttpHdrReasonSet"); } /* FIXME: INKqa12722 - This neg test would crash TS */ if (INKHttpHdrReasonSet(negHdrBuf, negHttpHdrLoc, NULL, -1) != INK_ERROR) { LOG_NEG_ERROR("INKHttpHdrReasonSet"); } STR_RELEASE(negHdrBuf, negHttpHdrLoc, sHttpReason); } /* Clean-up */ HANDLE_RELEASE(negHdrBuf, INK_NULL_MLOC, negHttpHdrLoc); BUFFER_DESTROY(negHdrBuf); }