コード例 #1
0
ファイル: srv_clamav.c プロジェクト: p1rate5s/c-icap
void generate_error_page(av_req_data_t * data, ci_request_t * req)
{
     int new_size = 0;
     ci_membuf_t *error_page;
     char buf[128];

     snprintf(buf, 128, "X-Infection-Found: Type=0; Resolution=2; Threat=%s;",
              data->virus_name);
     buf[127] = '\0';
     ci_icap_add_xheader(req, buf);
     new_size =
         strlen(clamav_error_message) + strlen(clamav_tail_message) +
         strlen(data->virus_name) + 10;
     if ( ci_http_response_headers(req))
          ci_http_response_reset_headers(req);
     else
          ci_http_response_create(req, 1, 1);
     ci_http_response_add_header(req, "HTTP/1.0 403 Forbidden");
     ci_http_response_add_header(req, "Server: C-ICAP");
     ci_http_response_add_header(req, "Connection: close");
     ci_http_response_add_header(req, "Content-Type: text/html");
     ci_http_response_add_header(req, "Content-Language: en");


     error_page = ci_membuf_new_sized(new_size);
     ((av_req_data_t *) data)->error_page = error_page;

     ci_membuf_write(error_page, (char *) clamav_error_message,
                     strlen(clamav_error_message), 0);
     ci_membuf_write(error_page, (char *) data->virus_name,
                     strlen(data->virus_name), 0);
     ci_membuf_write(error_page, (char *) clamav_tail_message, strlen(clamav_tail_message), 1); /*And here is the eof.... */
}
コード例 #2
0
ファイル: simple_api.c プロジェクト: Shield-Firewall/c-icap
ci_off_t ci_http_content_length(ci_request_t * req)
{
     ci_headers_list_t *heads;
     const char *val;
     ci_off_t res = 0;
     char *e;
     if (!(heads =  ci_http_response_headers(req))) {
          /*Then maybe is a reqmod reauest, try to get request headers */
          if (!(heads = ci_http_request_headers(req)))
               return 0;
     }
     if (!(val = ci_headers_value(heads, "Content-Length")))
          return -1;
 
     errno = 0;
     res = ci_strto_off_t(val, &e, 10);
     if (errno == ERANGE && (res == CI_STRTO_OFF_T_MAX || res == CI_STRTO_OFF_T_MIN)) {
         ci_debug_printf(4, "Content-Length: overflow\n");
         return -2;
     }
     if (val == e) {
         ci_debug_printf(4, "Content-Length: not valid value: '%s' \n", val);
         return -2;
     }
     return res;
}
コード例 #3
0
static void createImageGroupClassificationHeaders(image_session_t *mySession, image_detected_count_t *count)
{
image_detected_count_t *current;
char header[myMAX_HEADER + 1];
const char *rating = "#########+";
uint16_t current_category;

	// modify headers
	if (!ci_http_response_headers(mySession->req))
		ci_http_response_create(mySession->req, 1, 1);
	snprintf(header, myMAX_HEADER, "X-IMAGE-GROUP-CATEGORIES:");
	// Loop through categories
	for(current_category = 0; current_category < num_image_categories; current_category++) {
		current = &count[current_category];
		// add each category to header
		if(current->count)
		{
			char *oldHeader = myStrDup(header);
			snprintf(header, myMAX_HEADER, "%s %s(%.*s)", oldHeader, current->category->name, (current->count > 10 ? 10 : current->count), rating);
			free(oldHeader);
		}
		mySession->featuresDetected += current->count;
	}
	// add IMAGE-CATEGORIES header
	header[myMAX_HEADER] = '\0';
	if(mySession->featuresDetected)
	{
		ci_http_response_add_header(mySession->req, header);
		ci_debug_printf(10, "Added header: %s\n", header);

		// Add other headers
		addReferrerHeaders(mySession->req, mySession->referrer_fhs_classification, mySession->referrer_fnb_classification);
	}
}
コード例 #4
0
static void addImageErrorHeaders(ci_request_t *req, int error)
{
char header[myMAX_HEADER + 1];

	// modify headers
	if (!ci_http_response_headers(req))
		ci_http_response_create(req, 1, 1);

	switch(error)
	{
		case IMAGE_NO_MEMORY:
			snprintf(header, myMAX_HEADER, "X-IMAGE-ERROR: OUT OF MEMORY");
			break;
		case IMAGE_NO_CATEGORIES:
			snprintf(header, myMAX_HEADER, "X-IMAGE-ERROR: NO CATEGORIES PROVIDED, CAN'T PROCESS");
			break;
		case IMAGE_FAILED_LOAD:
			snprintf(header, myMAX_HEADER, "X-IMAGE-ERROR: FAILED TO LOAD IMAGE (Corrupted or Unknown Format)");
			break;
		default:
			snprintf(header, myMAX_HEADER, "X-IMAGE-ERROR: UNKNOWN ERROR");
			break;
	}
	// add IMAGE-CATEGORIES header
	header[myMAX_HEADER] = '\0';
	ci_http_response_add_header(req, header);
	ci_debug_printf(3, "Added error header: %s\n", header);
}
コード例 #5
0
ファイル: txt_format.c プロジェクト: p1rate5s/c-icap
int fmt_http_res_head_o(ci_request_t *req, char *buf,int len, char *param)
{
  char *s = NULL;
  int i;
  ci_headers_list_t *http_resp_headers;

  if (!len)
     return 0;

  if (!param || param[0] == '\0') {
      http_resp_headers = ci_http_response_headers(req);
      if (http_resp_headers && http_resp_headers->used)
          s = http_resp_headers->headers[0];
  } else {
      s = ci_http_response_get_header(req, param);
  }

  if (s) {
     for (i=0;i<len && *s!= '\0' && *s != '\r' && *s!='\n'; i++,s++)
        buf[i] = *s;
     return i;
  } else {
     *buf = '-';
     return 1;
  }
}
コード例 #6
0
ファイル: simple_api.c プロジェクト: Shield-Firewall/c-icap
int ci_http_response_reset_headers(ci_request_t * req)
{
     ci_headers_list_t *heads;
     if (!(heads =  ci_http_response_headers(req)))
          return 0;
     ci_headers_reset(heads);
     return 1;
}
コード例 #7
0
ファイル: simple_api.c プロジェクト: Shield-Firewall/c-icap
int ci_http_response_remove_header(ci_request_t * req, const char *header)
{
     ci_headers_list_t *heads;
     if(req->packed)   /*Not in edit mode*/
	  return 0;
     if (!(heads =  ci_http_response_headers(req)))
          return 0;
     return ci_headers_remove(heads, header);
}
コード例 #8
0
ファイル: simple_api.c プロジェクト: Shield-Firewall/c-icap
const char *ci_http_response_add_header(ci_request_t * req, const char *header)
{
     ci_headers_list_t *heads;
     if(req->packed)   /*Not in edit mode*/
	  return NULL;
     if (!(heads =  ci_http_response_headers(req)))
          return NULL;
     return ci_headers_add(heads, header);
}
コード例 #9
0
ファイル: simple_api.c プロジェクト: Shield-Firewall/c-icap
const char *ci_http_response_get_header(ci_request_t * req, const char *head_name)
{
     ci_headers_list_t *heads;
     const char *val;
     if (!(heads =  ci_http_response_headers(req)))
          return NULL;
     if (!(val = ci_headers_value(heads, head_name)))
          return NULL;
     return val;
}
コード例 #10
0
static void createImageClassificationHeaders(image_session_t *mySession)
{
image_detected_t *current;
char header[myMAX_HEADER + 1];
const char *rating = "#########+";
int i;
uint16_t current_category;

	// modify headers
	if (!ci_http_response_headers(mySession->req))
		ci_http_response_create(mySession->req, 1, 1);
	snprintf(header, myMAX_HEADER, "X-IMAGE-CATEGORIES:");
	// Loop through categories
	for(current_category = 0; current_category < num_image_categories; current_category++) {
		current = &mySession->detected[current_category];
		if(current->detected)
		{
			// Loop the number of detected objects
			for(i = 0; i < current->detected->total; i++ )
			{
				// Reset rectangles to original size
				CvRect* r = (CvRect*)cvGetSeqElem( current->detected, i );
				r->x = (int)(r->x * mySession->scale);
				r->y = (int)(r->y * mySession->scale);
				r->height = (int)(r->height * mySession->scale);
				r->width = (int)(r->width * mySession->scale);
			}
			// add each category to header
			if(current->detected->total)
			{
				char *oldHeader = myStrDup(header);
				snprintf(header, myMAX_HEADER, "%s %s(%.*s)", oldHeader, current->category->name, (current->detected->total > 10 ? 10 : current->detected->total), rating);
				free(oldHeader);
			}
			mySession->featuresDetected += current->detected->total;
		}
	}
	// add IMAGE-CATEGORIES header
	header[myMAX_HEADER] = '\0';
	if(mySession->featuresDetected)
	{
		ci_http_response_add_header(mySession->req, header);
		ci_debug_printf(10, "Added header: %s\n", header);

		// Add other headers
		addReferrerHeaders(mySession->req, mySession->referrer_fhs_classification, mySession->referrer_fnb_classification);
	}
}
コード例 #11
0
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");
     }
}
コード例 #12
0
ファイル: acl.c プロジェクト: Shield-Firewall/c-icap
void free_http_resp_header(ci_request_t *req, void *param)
{
    ci_headers_list_t *heads;
    heads = ci_http_response_headers(req);
    release_header_value(heads, param);
}
コード例 #13
0
ファイル: acl.c プロジェクト: Shield-Firewall/c-icap
void *get_http_resp_header(ci_request_t *req, char *param)
{
    ci_headers_list_t *heads;
    heads = ci_http_response_headers(req);
    return (void *)get_header(heads, param);
}
コード例 #14
0
ファイル: c-icap-java.c プロジェクト: syakesaba/c-icap-java
/**
 * 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;
}