void INKPluginInit(int argc, const char *argv[]) { INKCont pCont; LOG_SET_FUNCTION_NAME("INKPluginInit"); if ((pCont = INKContCreate(contHandler, NULL)) == INK_ERROR_PTR) { LOG_API_ERROR("INKContCreate") } else if (INKHttpHookAdd(INK_HTTP_TXN_START_HOOK, pCont) == INK_ERROR) { LOG_API_ERROR("INKHttpHookAdd"); } }
/************************************************************************************ * 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"); } }
static void handleTxnStart(INKCont pCont, INKHttpTxn pTxn) { LOG_SET_FUNCTION_NAME("handleTxnStart"); if (INKHttpTxnHookAdd(pTxn, INK_HTTP_READ_REQUEST_HDR_HOOK, pCont) == INK_ERROR) { LOG_API_ERROR("INKHttpHookAdd"); } if (INKHttpTxnHookAdd(pTxn, INK_HTTP_SEND_RESPONSE_HDR_HOOK, pCont) == INK_ERROR) { LOG_API_ERROR("INKHttpHookAdd"); } if (INKHttpTxnReenable(pTxn, INK_EVENT_HTTP_CONTINUE) == INK_ERROR) { LOG_API_ERROR("INKHttpTxnReenable"); } }
/* ** list_contract_type: ** Print product type info for the specified contract_type. ** If successful, return the number of items found; otherwise return -1. */ int list_contract_type(short contract_type) { struct fields { int type; char description_text[80 + 1]; }; int success; int ret; int no_items; int item_cnt; ABP_CONTRACT_TYPE keys = NULL, item = NULL, list = NULL; for (success = 0; !success; success = 1) { keys = new_abp_contract_type(); if (keys == NULL) { logprintf(LOG_ERR, "new_abp_contract_type() failed\n"); break; } unset_abp_contract_type(keys); set_abp_contract_type_type(keys, contract_type); ret = list_abp_contract_types(g_dbhandle, keys, &list); if (ret < 0) { LOG_API_ERROR(g_dbhandle, ret); break; } no_items = ret; printf("\n"); printf("Contract Type\n"); printf("-------------\n"); for (item = list, item_cnt = 0; item != NULL; item = next_abp_contract_type(item), item_cnt++) { struct fields f; char *label; label = "type:"; ret = get_abp_contract_type_type(item, &f.type); print_int(ret, label, (int) f.type); label = "description_text:"; ret = get_abp_contract_type_description_text(item, f.description_text); print_string(ret, label, f.description_text); printf("\n"); } if (item_cnt != no_items) { logprintf(LOG_ERR, "item_cnt != no_items\n"); break; } } delete_abp_contract_type(keys); abp_delete_objects(list); return success ? item_cnt : -1; }
/* ** list_ppkg_types: ** Print a list of packages. If package_id is 0, list all packages; otherwise ** list the single package specified. If successful, return the number of ** items listed; otherwise return -1. */ int list_ppkg_types(int package_id) { struct fields { int package_id; char display_value[80 + 1]; }; int success; int ret; int no_items; int item_cnt; ABP_PPKG_TYPE keys = NULL, item = NULL, list = NULL; for (success = 0; !success; success = 1) { keys = new_abp_ppkg_type(); if (keys == NULL) { logprintf(LOG_ERR, "new_abp_ppkg_type() failed\n"); break; } unset_abp_ppkg_type(keys); if (package_id > 0) { set_abp_ppkg_type_package_id(keys, package_id); } ret = list_abp_ppkg_types(g_dbhandle, keys, &list); if (ret < 0) { LOG_API_ERROR(g_dbhandle, ret); break; } no_items = ret; printf("\n"); printf("Product Package Type\n"); printf("--------------------\n"); for (item = list, item_cnt = 0; item != NULL; item = next_abp_ppkg_type(item), item_cnt++) { struct fields f; char *label; label = "package_id:"; ret = get_abp_ppkg_type_package_id(item, &f.package_id); print_int(ret, label, f.package_id); label = "display_value:"; ret = get_abp_ppkg_type_display_value(item, f.display_value); print_string(ret, label, f.display_value); printf("\n"); } if (item_cnt != no_items) { logprintf(LOG_ERR, "item_cnt != no_items\n"); break; } } delete_abp_ppkg_type(keys); abp_delete_objects(list); return success ? item_cnt : -1; }
/* ** list_ppkg_component_members: ** Print a list of component member info for the specified package_id and ** component_id. If successful, return the number of items found; otherwise ** return -1. */ int list_ppkg_component_members(int package_id, int component_id) { struct fields { int package_id; int component_id; unsigned char member_type; int member_id; int minimum_required; }; int success; int ret; int no_items; int item_cnt; ABP_PPKG_COMPONENT_MEMBER keys = NULL, item = NULL, list = NULL; for (success = 0; !success; success = 1) { keys = new_abp_ppkg_component_member(); if (keys == NULL) { logprintf(LOG_ERR, "new_abp_ppkg_component_member() failed\n"); break; } unset_abp_ppkg_component_member(keys); set_abp_ppkg_component_member_package_id(keys, package_id); set_abp_ppkg_component_member_component_id(keys, component_id); ret = list_abp_ppkg_component_members(g_dbhandle, keys, &list); if (ret < 0) { LOG_API_ERROR(g_dbhandle, ret); break; } no_items = ret; printf("\n"); printf("Product Package Component Member\n"); printf("--------------------------------\n"); for (item = list, item_cnt = 0; item != NULL; item = next_abp_ppkg_component_member(item), item_cnt++) { struct fields f; char *label; label = "package_id:"; ret = get_abp_ppkg_component_member_package_id(item, &f.package_id); print_int(ret, label, f.package_id); label = "component_id:"; ret = get_abp_ppkg_component_member_component_id(item, &f.component_id); print_int(ret, label, f.component_id); label = "member_type:"; ret = get_abp_ppkg_component_member_member_type(item, &f.member_type); print_int(ret, label, (int) f.member_type); label = "member_id:"; ret = get_abp_ppkg_component_member_member_id(item, &f.member_id); print_int(ret, label, f.member_id); label = "minimum_required:"; ret = get_abp_ppkg_component_member_minimum_required(item, &f.minimum_required); print_int(ret, label, f.minimum_required); printf("\n"); } if (item_cnt != no_items) { logprintf(LOG_ERR, "item_cnt != no_items\n"); break; } } delete_abp_ppkg_component_member(keys); abp_delete_objects(list); return success ? item_cnt : -1; }
/* ** list_ppkg_component_type: ** Print component type info for the specified component_id. ** If successful, return the number of items found; otherwise return -1. */ int list_ppkg_component_type(int component_id) { struct fields { int component_id; unsigned char component_level; char display_value[80 + 1]; }; int success; int ret; int no_items; int item_cnt; ABP_PPKG_COMPONENT_TYPE keys = NULL, item = NULL, list = NULL; for (success = 0; !success; success = 1) { keys = new_abp_ppkg_component_type(); if (keys == NULL) { logprintf(LOG_ERR, "new_abp_ppkg_component_type() failed\n"); break; } unset_abp_ppkg_component_type(keys); set_abp_ppkg_component_type_component_id(keys, component_id); ret = list_abp_ppkg_component_types(g_dbhandle, keys, &list); if (ret < 0) { LOG_API_ERROR(g_dbhandle, ret); break; } no_items = ret; for (item = list, item_cnt = 0; item != NULL; item = next_abp_ppkg_component_type(item), item_cnt++) { struct fields f; char *label; label = "component_id:"; ret = get_abp_ppkg_component_type_component_id(item, &f.component_id); print_int(ret, label, f.component_id); label = "component_level:"; ret = get_abp_ppkg_component_type_component_level(item, &f.component_level); print_int(ret, label, (int) f.component_level); label = "display_value:"; ret = get_abp_ppkg_component_type_display_value(item, f.display_value); print_string(ret, label, f.display_value); printf("\n"); } if (item_cnt != no_items) { logprintf(LOG_ERR, "item_cnt != no_items\n"); break; } } delete_abp_ppkg_component_type(keys); abp_delete_objects(list); return success ? item_cnt : -1; }
/* ** list_ppkg_components: ** Print a list of components for the given package_id. If successful, return ** the number of items listed; otherwise return -1. ** ** Note: The APIs provide a roundabout way to find the components of a ** package. First, list all the members in all the components in the package. ** Then, loop through this list to produce a list of distinct component_ids. ** Finally, find the component type info for each distinct component_id. */ int list_ppkg_components(int package_id) { int success; int ret; int no_items; int item_cnt; ABP_PPKG_COMPONENT_MEMBER keys = NULL, item = NULL, list = NULL; int component_id; int *component_id_list = NULL; int i; int component_cnt = 0; for (success = 0; !success; success = 1) { keys = new_abp_ppkg_component_member(); if (keys == NULL) { logprintf(LOG_ERR, "new_abp_ppkg_component_member() failed\n"); break; } unset_abp_ppkg_component_member(keys); set_abp_ppkg_component_member_package_id(keys, package_id); /* find all members of all components in the package */ ret = list_abp_ppkg_component_members(g_dbhandle, keys, &list); if (ret < 0) { LOG_API_ERROR(g_dbhandle, ret); break; } no_items = ret; /* now, produce a list of distinct component_ids */ component_id_list = (int *) calloc(no_items, sizeof(int)); if (component_id_list == NULL) { logprintf(LOG_ERR, "calloc failed on component_id_list\n"); break; } for (item = list, item_cnt = 0; item != NULL; item = next_abp_ppkg_component_member(item), item_cnt++) { ret = get_abp_ppkg_component_member_component_id(item, &component_id); if (ret != ABP_SET) { logprintf(LOG_ERR, "Couldn't get component_id\n"); goto CLEANUP; } if (!in_list(component_id_list, component_cnt, component_id)) { component_id_list[component_cnt] = component_id; component_cnt++; } } if (item_cnt != no_items) { logprintf(LOG_ERR, "item_cnt != no_items\n"); break; } printf("\n"); printf("Product Package Component Type\n"); printf("------------------------------\n"); /* now, process our list of component_ids */ for (i = 0; i < component_cnt; i++) { component_id = component_id_list[i]; ret = list_ppkg_component_type(component_id); if (ret != 1) { logprintf(LOG_ERR, "list_ppkg_component_type() failed\n"); goto CLEANUP; } } } CLEANUP: delete_abp_ppkg_component_member(keys); abp_delete_objects(list); free(component_id_list); return success ? component_cnt : -1; }
/* ** main: */ int main(int argc, char *argv[]) { ABP_SERV_INST serv_inst; char acct_external_id[ EXTERNAL_ID_LEN ]; int success; int ret; /* Process command line: acct */ if (argc != 2) { fprintf(stderr, "Usage: %s acct\n", argv[0]); exit(1); } strncpy(acct_external_id, argv[1], EXTERNAL_ID_LEN - 1); /* Connect to database (global g_dbhandle) and create log files */ init_db_and_logs(); for (success = 0; !success; success = 1) { short emf_config_id = 301; /* Internet User Id */ char serv_inst_external_id[ EXTERNAL_ID_LEN ]; serv_inst = new_abp_serv_inst(); if (serv_inst == NULL) { logprintf(LOG_FATAL, "new_abp_serv_inst() failed\n"); break; } set_serv_inst(serv_inst, acct_external_id, emf_config_id); /* ** No need for a user defined transaction here. However, the API ** wraps the insert in a transaction internally. You could see ** this by examining the sql log files. */ ret = insert_abp_serv_inst(g_dbhandle, serv_inst); if (ret != ABP_STATUS_OK) { LOG_API_ERROR(g_dbhandle, ret); break; } ret = get_abp_serv_inst_external_id(serv_inst, serv_inst_external_id); if (ret != ABP_SET) { logprintf(LOG_ERR, "get_abp_serv_inst_external_id() != ABP_SET\n"); break; } printf("serv inst %s added to account %s\n", serv_inst_external_id, acct_external_id); } delete_abp_serv_inst(serv_inst); if (!success) { printf("service instance insert failed - check log files!\n"); } /* Disconnect from database(s) */ logout_db(); return 0; }
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 handleSendResponse(INKCont pCont, INKHttpTxn pTxn) { LOG_SET_FUNCTION_NAME("handleSendResponse"); INKMBuffer respHdrBuf = NULL, newHttpHdrBuf = NULL, parseBuffer = NULL; INKMLoc respHttpHdrLoc = NULL, newHttpHdrLoc = NULL, parseHttpHdrLoc = NULL; INKHttpStatus oldHttpStatus, tmpHttpStatus; INKHttpType httpType; INKHttpParser httpRespParser = NULL; HdrInfo_T *pRespHdrInfo = NULL, *pNewRespHdrInfo = NULL; int iHttpHdrReasonLength, iOldHttpVersion, iTmpHttpVersion, iTmpHttpHdrReasonLength; const char *sHttpHdrReason = NULL, *sTmpHttpHdrReason = NULL, *pHttpParseStart = NULL, *pHttpParseEnd = NULL; char *sOldHttpReason = NULL; const char *sRespHdrStr1 = "HTTP/1.1 200 OK\r\nServer: Netscape-Enterprise/4.1\r\nDate: Tue, 31 Oct 2000 03:38:19 GMT\r\nContent-type: text/html\r\nAge: 3476\r\nContent-Length: 12440\r\nVia: HTTP/1.1 ts-sun14 (Traffic-Server/4.0.0 [cHs f ])\r\n\r\n"; const char *sRespHdrStr2 = "HTTP/1.1 404 Not Found \r\nServer: Netscape-Enterprise/4.1\r\nDate: Tue, 31 Oct 2000 03:38:19 GMT\r\nContent-type: text/html\r\nAge: 3476\r\nContent-Length: 12440\r\nVia: HTTP/1.1 ts-sun24 (Traffic-Server/4.0.0 [cHs f ])\r\n\r\n"; const char *sRespHdrStr3 = "HTTP/1.1 505 HTTP Version Not Supported \r\nServer: Netscape-Enterprise/4.1\r\nDate: Tue, 31 Oct 2000 03:38:19 GMT\r\nContent-type: text/html\r\nAge: 3476\r\nContent-Length: 12440\r\nVia: HTTP/1.1 ts-sun34 (Traffic-Server/4.0.0 [cHs f ])\r\n\r\n"; pRespHdrInfo = initHdr(); pNewRespHdrInfo = initHdr(); INKDebug(RESP, ">>> handleSendResponse <<<<\n"); /* Get Response Marshall Buffer */ if (!INKHttpTxnClientRespGet(pTxn, &respHdrBuf, &respHttpHdrLoc)) { LOG_API_ERROR_COMMENT("INKHttpTxnClientReqGet", "ERROR: Can't retrieve client req hdr"); goto done; } #ifdef DEBUG negTesting(respHdrBuf, respHttpHdrLoc); #endif /******* (1): Exercise all possible INK*GET and print the values **********/ INKDebug(RESP, "--------------------------------"); getHdrInfo(pRespHdrInfo, respHdrBuf, respHttpHdrLoc); printHttpHeader(respHdrBuf, respHttpHdrLoc, RESP, 1); /******* (2): Create a new header and check everything is copied correctly *********/ INKDebug(RESP, "--------------------------------"); if ((newHttpHdrBuf = INKMBufferCreate()) == INK_ERROR_PTR) { LOG_API_ERROR_COMMENT("INKMBufferCreate", "skipping to section(4)"); goto resp_4; } /*** INKHttpHdrCreate ***/ if ((newHttpHdrLoc = INKHttpHdrCreate(newHttpHdrBuf)) == INK_ERROR_PTR) { LOG_API_ERROR_COMMENT("INKMHTTPHdrCreate", "skipping to section(4)"); goto resp_4; } /* 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("INKMHTTPHdrCreate", "continuing"); } else if (httpType != INK_HTTP_TYPE_UNKNOWN) { LOG_AUTO_ERROR("INKHttpHdrCreate", "Newly created hdr not of type INK_HTTP_TYPE_UNKNOWN"); } /*** INKHttpHdrCopy ***/ if (INKHttpHdrCopy(newHttpHdrBuf, newHttpHdrLoc, respHdrBuf, respHttpHdrLoc) == INK_ERROR) { LOG_API_ERROR("INKHttpHdrCopy"); } getHdrInfo(pNewRespHdrInfo, newHttpHdrBuf, newHttpHdrLoc); printHttpHeader(newHttpHdrBuf, newHttpHdrLoc, RESP, 2); if (!identical_hdr(pRespHdrInfo, pNewRespHdrInfo)) { LOG_AUTO_ERROR("INKHttpHdrCopy", "copy of the resp header not identical to the original"); } /* Reuse: * newHttpHdrBuf, newHttHdrLoc */ /******* (3): Now excercise some INK..SETs on the new header ********/ INKDebug(RESP, "--------------------------------"); /*** INKHttpHdrTypeSet ***/ /* ERROR: * 1. Setting type other than INK_HTTP_TYPE_UNKNOWN, INK_HTTP_TYPE_REQUEST, * INK_HTTP_TYPE_RESPONSE, and, * 2. Setting the type twice. The hdr type has been already set during INKHttpHdrCopy * above, so setting it again is incorrect */ if (INKHttpHdrTypeSet(newHttpHdrBuf, newHttpHdrLoc, INK_HTTP_TYPE_RESPONSE) == INK_ERROR) { LOG_API_ERROR("INKHttpHdrTypeSet"); } /*** INKHttpHdrReasonSet ***/ /* save the original reason */ if ((sHttpHdrReason = INKHttpHdrReasonGet(newHttpHdrBuf, newHttpHdrLoc, &iHttpHdrReasonLength)) == INK_ERROR_PTR) { LOG_API_ERROR("INKHttpHdrReasonGet"); } else { sOldHttpReason = INKstrndup(sHttpHdrReason, iHttpHdrReasonLength); } /* Note: * INKHttpHdrReasonGet may return a NULL reason string (for e.g. I tried www.eyesong.8m.com). * Do NOT assume that INKstrndup always returns a null terminated string. INKstrndup does * not returns a NULL terminated string for a NULL ptr as i/p parameter. It simply returns * it backs. So functions like strlen() on the return value might cause TS to crash */ if (INKHttpHdrReasonSet(newHttpHdrBuf, newHttpHdrLoc, "dummy reason", strlen("dummy reason")) == INK_ERROR) { LOG_API_ERROR("INKHttpHdrReasonGet"); } else { if ((sTmpHttpHdrReason = INKHttpHdrReasonGet(newHttpHdrBuf, newHttpHdrLoc, &iTmpHttpHdrReasonLength)) == INK_ERROR_PTR) { LOG_API_ERROR("INKHttpHdrReasonGet"); } else if (sTmpHttpHdrReason && strncmp(sTmpHttpHdrReason, "dummy reason", iTmpHttpHdrReasonLength)) { LOG_AUTO_ERROR("INKHttpHdrReasonSet/Get", "GET reason different from the SET reason"); } STR_RELEASE(newHttpHdrBuf, newHttpHdrLoc, sTmpHttpHdrReason); } /*** INKHttpStatusSet ***/ /* save the original value */ if ((oldHttpStatus = INKHttpHdrStatusGet(newHttpHdrBuf, newHttpHdrLoc)) == INK_ERROR) { LOG_API_ERROR("INKHttpHdrStatusGet"); } /* change it to some unknown value */ if (INKHttpHdrStatusSet(newHttpHdrBuf, newHttpHdrLoc, INK_HTTP_STATUS_NONE) == INK_ERROR) { LOG_API_ERROR("INKHttpHdrStatusSet"); } else if ((tmpHttpStatus = INKHttpHdrStatusGet(newHttpHdrBuf, newHttpHdrLoc)) == INK_ERROR) { LOG_API_ERROR("INKHttpHdrStatusGet"); } else if (tmpHttpStatus != INK_HTTP_STATUS_NONE) { LOG_AUTO_ERROR("INKHttpHdrStatusGet/Set", "GET status different from the SET status"); } /*** INKHttpHdrVersionSet ***/ /* get the original version */ if ((iOldHttpVersion = INKHttpHdrVersionGet(newHttpHdrBuf, newHttpHdrLoc)) == INK_ERROR) { LOG_API_ERROR("INKHttpHdrVersionGet"); } /* change it to some unknown version */ if (INKHttpHdrVersionSet(newHttpHdrBuf, newHttpHdrLoc, INK_HTTP_VERSION(10, 10)) == INK_ERROR) { LOG_API_ERROR("INKHttpHdrVersionSet"); } else if ((iTmpHttpVersion = INKHttpHdrVersionGet(newHttpHdrBuf, newHttpHdrLoc)) == INK_ERROR) { LOG_API_ERROR("INKHttpHdrVersionGet"); } else if (INK_HTTP_MAJOR(iTmpHttpVersion) != 10 && INK_HTTP_MINOR(iTmpHttpVersion) != 10) { LOG_AUTO_ERROR("INKHttpHdrVersionSet", "GET version different from SET version"); } printHttpHeader(newHttpHdrBuf, newHttpHdrLoc, RESP, 3); /* Restore the original values */ /* Here we can't use strlen(sOldHttpReason) to set the length. This would crash TS if * sOldHttpReason happens to be NULL */ if (INKHttpHdrReasonSet(newHttpHdrBuf, newHttpHdrLoc, sOldHttpReason, iHttpHdrReasonLength) == INK_ERROR) { LOG_API_ERROR("INKHttpHdrReasonSet"); } /*INKHttpHdrReasonSet (newHttpHdrBuf, newHttpHdrLoc, sOldHttpReason, strlen(sOldHttpReason)); */ if (INKHttpHdrStatusSet(newHttpHdrBuf, newHttpHdrLoc, oldHttpStatus) == INK_ERROR) { LOG_API_ERROR("INKHttpHdrStatusSet"); } if (INKHttpHdrVersionSet(newHttpHdrBuf, newHttpHdrLoc, iOldHttpVersion) == INK_ERROR) { LOG_API_ERROR("INKHttpHdrStatusSet"); } if (!identical_hdr(pRespHdrInfo, pNewRespHdrInfo)) { LOG_AUTO_ERROR("INK..SET", "Hdr values not properly restored"); } /* (3): clean-up */ STR_RELEASE(newHttpHdrBuf, newHttpHdrLoc, sHttpHdrReason); FREE(sOldHttpReason); resp_4: /******* (4): Now excercise some SETs on the response header ********/ INKDebug(RESP, "--------------------------------"); /*** INKHttpHdrReasonSet ***/ /* save the original reason */ if ((sHttpHdrReason = INKHttpHdrReasonGet(respHdrBuf, respHttpHdrLoc, &iHttpHdrReasonLength)) == INK_ERROR_PTR) { LOG_API_ERROR("INKHttpHdrReasonGet"); } else { sOldHttpReason = INKstrndup(sHttpHdrReason, iHttpHdrReasonLength); } /* change the reason phrase */ if (INKHttpHdrReasonSet(respHdrBuf, respHttpHdrLoc, "dummy reason", strlen("dummy reason")) == INK_ERROR) { LOG_API_ERROR("INKHttpHdrReasonSet"); } if ((sTmpHttpHdrReason = INKHttpHdrReasonGet(respHdrBuf, respHttpHdrLoc, &iTmpHttpHdrReasonLength)) == INK_ERROR_PTR) { LOG_API_ERROR("INKHttpHdrReasonGet"); } else if (sTmpHttpHdrReason && strncmp(sTmpHttpHdrReason, "dummy reason", iTmpHttpHdrReasonLength)) { LOG_AUTO_ERROR("INKHttpHdrReasonSet/Get", "GET reason string different from SET reason"); } STR_RELEASE(respHdrBuf, respHttpHdrLoc, sTmpHttpHdrReason); /*** INKHttpStatusSet ***/ /* save the original value */ if ((oldHttpStatus = INKHttpHdrStatusGet(respHdrBuf, respHttpHdrLoc)) == INK_ERROR) { LOG_API_ERROR("INKHttpHdrStatusGet"); } /* change it to some unknown value */ if (INKHttpHdrStatusSet(respHdrBuf, respHttpHdrLoc, INK_HTTP_STATUS_NONE) == INK_ERROR) { LOG_API_ERROR("INKHttpHdrStatusSet"); } else if (INKHttpHdrStatusGet(respHdrBuf, respHttpHdrLoc) != INK_HTTP_STATUS_NONE) { LOG_AUTO_ERROR("INKHttpHdrStatusSet/GET", "GET status value different from SET status"); } /*** INKHttpHdrTypeSet ***/ /* ERROR: * 1. Setting type other than INK_HTTP_TYPE_UNKNOWN, INK_HTTP_TYPE_REQUEST, * INK_HTTP_TYPE_RESPONSE and, * 2. Setting the type twice. The hdr type has been already set during INKHttpTxnClientRespGet * above, so setting it again should fail */ if (INKHttpHdrTypeSet(respHdrBuf, respHttpHdrLoc, INK_HTTP_TYPE_RESPONSE) == INK_ERROR) { LOG_API_ERROR("INKHttpHdrTypeSet"); } if (INKHttpHdrTypeGet(respHdrBuf, respHttpHdrLoc) == INK_HTTP_TYPE_UNKNOWN) { LOG_AUTO_ERROR("INKHttpHdrTypeSet/Get", "respHdrBuf CAN be set to INK_HTTP_TYPE_UNKNOWN"); } /*** INKHttpHdrVersionSet ***/ /* get the original version */ if ((iOldHttpVersion = INKHttpHdrVersionGet(respHdrBuf, respHttpHdrLoc)) == INK_ERROR) { LOG_API_ERROR("INKHttpHdrVersionGet"); } /* change it to some unknown version */ if (INKHttpHdrVersionSet(respHdrBuf, respHttpHdrLoc, INK_HTTP_VERSION(10, 10)) == INK_ERROR) { LOG_API_ERROR("INKHttpHdrVersionSet"); } else if ((iTmpHttpVersion = INKHttpHdrVersionGet(respHdrBuf, respHttpHdrLoc)) == INK_ERROR) { LOG_API_ERROR("INKHttpHdrVersionGet"); } else if (INK_HTTP_MAJOR(iTmpHttpVersion) != 10 && INK_HTTP_MINOR(iTmpHttpVersion) != 10) { LOG_AUTO_ERROR("INKHttpHdrVersionGet/Set", "GET HTTP version different from SET version"); } printHttpHeader(respHdrBuf, respHttpHdrLoc, RESP, 4); /* restore the original values */ /* For INKHttpHdrReasonSet, do NOT use strlen(sOldHttpReason) to set the length. * This would crash TS if sOldHttpReason happened to be NULL */ if (INKHttpHdrReasonSet(respHdrBuf, respHttpHdrLoc, sOldHttpReason, iHttpHdrReasonLength) == INK_ERROR) { LOG_API_ERROR("INKHttpHdrReasonSet"); } /*INKHttpHdrReasonSet (respHdrBuf, respHttpHdrLoc, sOldHttpReason, strlen(sOldHttpReason)); */ if (INKHttpHdrStatusSet(respHdrBuf, respHttpHdrLoc, oldHttpStatus) == INK_ERROR) { LOG_API_ERROR("INKHttpHdrStatusSet"); } if (INKHttpHdrVersionSet(respHdrBuf, respHttpHdrLoc, iOldHttpVersion) == INK_ERROR) { LOG_API_ERROR("INKHttpHdrVersionSet"); } FREE(pNewRespHdrInfo->hdrReason); getHdrInfo(pNewRespHdrInfo, respHdrBuf, respHttpHdrLoc); if (!identical_hdr(pRespHdrInfo, pNewRespHdrInfo)) { LOG_AUTO_ERROR("INK..SET", "Hdr values not properly restored"); } /* (4): clean-up */ STR_RELEASE(respHdrBuf, respHttpHdrLoc, sHttpHdrReason); FREE(sOldHttpReason); /********************************/ /** (5): INKHttpHdrParseResp **/ /********************************/ INKDebug(RESP, "--------------------------------"); /* Create a parser Buffer and header location */ if ((parseBuffer = INKMBufferCreate()) == INK_ERROR_PTR || parseBuffer == NULL) { LOG_API_ERROR_COMMENT("INKMBufferCreate", "abnormal exit"); goto done; } else if ((parseHttpHdrLoc = INKHttpHdrCreate(parseBuffer)) == INK_ERROR_PTR || parseHttpHdrLoc == NULL) { LOG_API_ERROR_COMMENT("INKHttpHdrCreate", "abnormal exit"); goto done; } pHttpParseStart = sRespHdrStr1; pHttpParseEnd = pHttpParseStart + strlen(pHttpParseStart); httpRespParser = INKHttpParserCreate(); if (INKHttpHdrParseResp(httpRespParser, parseBuffer, parseHttpHdrLoc, &pHttpParseStart, pHttpParseEnd) == INK_PARSE_ERROR) { LOG_API_ERROR("INKHttpHdrParseResp"); } printHttpHeader(parseBuffer, parseHttpHdrLoc, RESP, 5.1); if (INKHttpParserClear(httpRespParser) == INK_ERROR) { LOG_API_ERROR("INKHttpParseClear"); } INKDebug(RESP, "--------------------------------"); pHttpParseStart = sRespHdrStr2; pHttpParseEnd = pHttpParseStart + strlen(pHttpParseStart); /* httpRespParser = INKHttpParserCreate(); */ if (INKHttpHdrParseResp(httpRespParser, parseBuffer, parseHttpHdrLoc, &pHttpParseStart, pHttpParseEnd) == INK_PARSE_ERROR) { LOG_API_ERROR("INKHttpHdrParseResp"); } printHttpHeader(parseBuffer, parseHttpHdrLoc, RESP, 5.2); if (INKHttpParserClear(httpRespParser) == INK_ERROR) { LOG_API_ERROR("INKHttpParseClear"); } INKDebug(RESP, "--------------------------------"); pHttpParseStart = sRespHdrStr3; pHttpParseEnd = pHttpParseStart + strlen(pHttpParseStart); /* httpRespParser = INKHttpParserCreate(); */ if (INKHttpHdrParseResp(httpRespParser, parseBuffer, parseHttpHdrLoc, &pHttpParseStart, pHttpParseEnd) == INK_PARSE_ERROR) { LOG_API_ERROR("INKHttpHdrParseResp"); } printHttpHeader(parseBuffer, parseHttpHdrLoc, RESP, 5.3); done: /* Clean-up */ freeHdr(pRespHdrInfo); freeHdr(pNewRespHdrInfo); /* release hdrLoc */ HANDLE_RELEASE(respHdrBuf, INK_NULL_MLOC, respHttpHdrLoc); HANDLE_RELEASE(newHttpHdrBuf, INK_NULL_MLOC, newHttpHdrLoc); HANDLE_RELEASE(parseBuffer, INK_NULL_MLOC, parseHttpHdrLoc); /* destroy hdrLoc */ HDR_DESTROY(respHdrBuf, respHttpHdrLoc); HDR_DESTROY(parseBuffer, parseHttpHdrLoc); /* destroy mbuffer */ BUFFER_DESTROY(newHttpHdrBuf); BUFFER_DESTROY(parseBuffer); /* destroy the parser */ if (INKHttpParserDestroy(httpRespParser) == INK_ERROR) { LOG_API_ERROR("INKHttpParserDestroy"); } if (INKHttpTxnReenable(pTxn, INK_EVENT_HTTP_CONTINUE) == INK_ERROR) { LOG_API_ERROR("INKHttpTxnReenable"); } INKDebug(RESP, "......... exiting handleRespResponse .............\n"); } /* handleSendResponse */
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); }