int client_create_request(ci_request_t * req, char *servername, char *service, int reqtype) { char buf[256]; if (reqtype != ICAP_OPTIONS && reqtype != ICAP_REQMOD && reqtype != ICAP_RESPMOD) return CI_ERROR; req->type = reqtype; snprintf(buf, 255, "%s icap://%s/%s ICAP/1.0", ci_method_string(reqtype), servername, service); buf[255] = '\0'; ci_headers_add(req->request_header, buf); snprintf(buf, 255, "Host: %s", servername); buf[255] = '\0'; ci_headers_add(req->request_header, buf); ci_headers_add(req->request_header, "User-Agent: C-ICAP-Client-Library/0.01"); if (ci_allow204(req)) ci_headers_add(req->request_header, "Allow: 204"); if (!ci_headers_is_empty(req->xheaders)) { ci_headers_addheaders(req->request_header, req->xheaders); } return CI_OK; }
void print_headers(request_t *req){ int i; int type; ci_headers_list_t *headers; ci_debug_printf(1,"\nICAP HEADERS:\n"); for(i=0;i<req->head->used;i++){ ci_debug_printf(1,"\t%s\n",req->head->headers[i]); } ci_debug_printf(1,"\n"); if((headers=ci_respmod_headers(req))==NULL){ headers=ci_reqmod_headers(req); type=ICAP_REQMOD; }else type=ICAP_RESPMOD; if(headers){ ci_debug_printf(1,"%s HEADERS:\n",ci_method_string(type)); for(i=0;i<req->head->used;i++){ if(headers->headers[i]) ci_debug_printf(1,"\t%s\n",headers->headers[i]); } ci_debug_printf(1,"\n"); } }
int fmt_icapmethod(ci_request_t *req, char *buf,int len, char *param) { int i; const char *s = ci_method_string(req->type); for(i=0;i<len && *s;i++,s++) buf[i] = *s; return i; }
void print_headers(ci_request_t * req) { int type; ci_headers_list_t *headers; ci_debug_printf(1, "\nICAP HEADERS:\n"); ci_headers_iterate(req->response_header, NULL, printhead); ci_debug_printf(1, "\n"); if ((headers = ci_http_response_headers(req)) == NULL) { headers = ci_http_request_headers(req); type = ICAP_REQMOD; } else type = ICAP_RESPMOD; if (headers) { ci_debug_printf(1, "%s HEADERS:\n", ci_method_string(type)); ci_headers_iterate(headers, NULL, printhead); ci_debug_printf(1, "\n"); } }
void *get_reqtype(ci_request_t *req, char *param){ return (void *)ci_method_string(req->type); }
/** * initialize ICAP Request.<br> * prev = recv Request<br> * next = java_check_preview_handler(char * preview_data, int preview_data_len, ci_request_t * req)<br> * * @see java_check_preview_handler(char * preview_data, int preview_data_len, ci_request_t * req) * @param req a pointer of request data. * @return service_data instance if OK else returns NULL(pass) */ void * java_init_request_data(ci_request_t * req) { const int REQ_TYPE = ci_req_type(req); const char * METHOD_TYPE = ci_method_string(REQ_TYPE);//Don't free! ci_headers_list_t *hdrs = NULL; //identify reqmod or respmod or else if (REQ_TYPE == ICAP_REQMOD) { hdrs = ci_http_request_headers(req); } else if (REQ_TYPE == ICAP_RESPMOD) { hdrs = ci_http_response_headers(req); } else if (REQ_TYPE == ICAP_OPTIONS){ cij_debug_printf(CIJ_INFO_LEVEL, "ICAP OPTIONS comes. ignoring..."); return NULL;//pass } else { //UNKNOWN ICAP METHOD cij_debug_printf(CIJ_INFO_LEVEL, "INVALID ICAP METHOD (NO. %d) has come. ignoring...", REQ_TYPE); return NULL;//pass } //Create service_data jServiceData_t * jServiceData = NULL; jServiceData = (jServiceData_t *)malloc(sizeof(jServiceData_t)); if (jServiceData == NULL) { cij_debug_printf(CIJ_ERROR_LEVEL, "Unable to allocate memory for jServiceData_t !"); cij_debug_printf(CIJ_ERROR_LEVEL, "Dropping request..."); return NULL; } //Get Java environment from mod_name const char * mod_name = (req->current_service_mod)->mod_name; jData_t * jdata = (jData_t *)ci_dyn_array_search(environments, mod_name); if (jdata == NULL) { cij_debug_printf(CIJ_ERROR_LEVEL, "Invalid mod_name %s is not in environments array.", mod_name); free(jServiceData); return NULL; } //Attach service instance to JVM jServiceData->jdata = jdata; JNIEnv * jni = jdata->jni; //Create new HTTP headers array for java jclass jClass_String = (*jni)->FindClass(jni, "java/lang/String"); jobjectArray jHeaders = (*jni)->NewObjectArray(jni, hdrs->used, jClass_String, NULL); if (jHeaders == NULL) { cij_debug_printf(CIJ_ERROR_LEVEL, "Could not allocate memory for http headers. ignoring..."); return NULL; } (*jni)->DeleteLocalRef(jni, jClass_String); int i; for(i=0;i<hdrs->used;i++) { jstring buf = (*jni)->NewStringUTF(jni, hdrs->headers[i]); if (buf == NULL) { cij_debug_printf(CIJ_ERROR_LEVEL, "Could not allocate memory for http headers string. ignoring..."); return NULL; } (*jni)->SetObjectArrayElement(jni, jHeaders, i, buf); (*jni)->DeleteLocalRef(jni, buf); } //Create instance. jobject jInstance = (*jni)->NewObject(jni, jdata->jIcapClass, jdata->jServiceConstructor,METHOD_TYPE,jHeaders); (*jni)->DeleteLocalRef(jni, jHeaders); if (jInstance == NULL) { cij_debug_printf(CIJ_ERROR_LEVEL, "Could not create instance of the class '%s'. Method='%s'. ignoring...", mod_name, METHOD_TYPE); return NULL; } jServiceData->instance = jInstance;//+REF ci_membuf_t * buffer = ci_membuf_new(); if (buffer == NULL) { cij_debug_printf(CIJ_ERROR_LEVEL, "Could not allocate memory for http body ignoring..."); return NULL; } return (void *)jServiceData; }