Beispiel #1
0
void *info_init_request_data(ci_request_t * req)
{
     struct info_req_data *info_data;

     info_data = malloc(sizeof(struct info_req_data));

     info_data->body = ci_membuf_new(4096);
     info_data->childs = 0;
     info_data->child_pids = malloc(childs_queue->size * sizeof(int));
     info_data->free_servers = 0;
     info_data->used_servers = 0;
     info_data->closing_childs = 0;
     info_data->closing_child_pids = malloc(childs_queue->size * sizeof(int));
     info_data->started_childs = 0;
     info_data->closed_childs = 0;
     info_data->crashed_childs = 0;
     info_data->txt_mode = 0;
     if (req->args) {
          if (strstr(req->args, "view=text"))
              info_data->txt_mode = 1;
     }
     
     info_data->collect_stats = malloc(ci_stat_memblock_size());
     info_data->collect_stats->sig = 0xFAFA;
     stat_memblock_fix(info_data->collect_stats);
     ci_stat_memblock_reset(info_data->collect_stats);

     return info_data;
}
Beispiel #2
0
void endof_data_vir_mode(av_req_data_t *data,request_t *req){
      ci_membuf_t *error_page;

     if(data->virus_name && data->body){
	  error_page=ci_membuf_new();
	  ((av_req_data_t *)data)->error_page=error_page;	  
	  ci_membuf_write(error_page,e_message,strlen(e_message),0);
	  ci_membuf_write(error_page,(char *)data->virus_name,strlen(data->virus_name),0);
	  ci_membuf_write(error_page,t_message,strlen(t_message),0);/*And here is the eof....*/
	  ci_membuf_write(data->error_page,(char *)msg,strlen(msg),0);
	  ci_membuf_write(data->error_page,data->body->filename,strlen(data->body->filename),0);
	  ci_membuf_write(data->error_page,(char *)msg2,strlen(msg2),1);
	  fchmod(data->body->fd,0);    
     }
     else
	  if(data->body){
	       fchmod(data->body->fd,S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH);    
	  }
}
Beispiel #3
0
void *echo_init_request_data(service_module_t *serv,request_t *req){

     if(ci_req_hasbody(req))
	  return ci_membuf_new();
     return NULL;
}
Beispiel #4
0
/**
 * 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;
}