void *mymalloc(malloc_zone_t *zone, size_t size)
{
  if (size >= KEEP_SIZE) { // big?
    if (tail > keep_list) { // available?
      void **entry;
      for (entry = tail - 1; entry >= keep_list; entry--) {
        if (zone->size(zone, *entry) >= size) {
          void *retval = *entry;
          tail--;
          *entry = *tail;
          //fprintf(stderr, "fulfill %d w/ %d, %d on list\n", size, zone->size(zone, *entry), keep_list - tail);
          return retval;
        }
      }
    }
  }
        
  //  fprintf(stderr, "malloc %d\n", size);
  return system_malloc(zone, size);
}
Esempio n. 2
0
static int handle_notification(Session *sn, 
                               Request *rq,
                               void* agent_config)
{
    int result;
    char *content_length_header;
    size_t content_length;

    /* fixme GETPOST use new getRequestBody() routine here.... */
    result = request_header(CONTENT_LENGTH_HDR, &content_length_header, sn,rq);
    if (REQ_PROCEED == result && NULL != content_length_header &&
        sscanf(content_length_header, "%u", &content_length) == 1) {
        char ch;
        size_t data_length = 0;
        char *buf = NULL;

        buf = system_malloc(content_length);
        if (buf != NULL) {
            for (data_length = 0; data_length < content_length; data_length++){
                ch = netbuf_getc(sn->inbuf);
                if (ch == IO_ERROR || ch == IO_EOF) {
                    break;
                }
                buf[data_length] = (char) ch;
            }
            am_web_handle_notification(buf, data_length, agent_config);
            system_free(buf);
        } else {
            am_web_log_error("handle_notification() unable to allocate memory "
            "for notification data, size = %u", content_length);
        }
        result = REQ_PROCEED;
    } else {
        am_web_log_error("handle_notification() %s content-length header",
                         (REQ_PROCEED == result &&
                         NULL != content_length_header) ?
                         "unparsable" : "missing");
    }

    return result;
}
Esempio n. 3
0
gpointer intercept_malloc(gsize size) {
	return system_malloc(size);
}
Esempio n. 4
0
static am_status_t set_header(const char *key, const char *values,
                              void **args) {
    Request *rq = (Request *)args[0];
    pb_param *hdr_pp = pblock_find("full-headers", rq->reqpb);
    const char *the_key = key;

    if (hdr_pp != NULL) {
	if(values != NULL && *values != '\0') { //Added by bn152013 for 6739097
            int append = 0;
            int length = strlen(the_key) + strlen(values) + 5;
            if (hdr_pp->value != NULL) {
                size_t len = strlen(hdr_pp->value);
                length += len;
                append = 1;
                hdr_pp->value = (char *) system_realloc(hdr_pp->value, length);
                hdr_pp->value[len] = '\0';
            } else {
                hdr_pp->value = (char *) system_malloc(length);
                hdr_pp->value[0]='\0';
            }

            if ( hdr_pp->value == NULL) {
                return (AM_NO_MEMORY);
            }

            if (append)
                strcat(hdr_pp->value, the_key);
            else
                strcpy(hdr_pp->value, the_key);


            strcat(hdr_pp->value, ": ");
            strcat(hdr_pp->value, values);
            strcat(hdr_pp->value, "\r\n");
        } else {
            if(key[0] != '\0' && hdr_pp->value != NULL) {
                char *ptr = strstr(hdr_pp->value, the_key);
                if(ptr != NULL) {
                    char *end_ptr = ptr + strlen(the_key);
                    while(*end_ptr != '\r' && *end_ptr != '\n')
                        ++end_ptr;

                    end_ptr += 2;

                    while(*end_ptr != '\0') {
                        *ptr = *end_ptr;
                        ptr += 1;
                        end_ptr += 1;
                    }
                    *ptr = '\0';
                }
            }
        }
    }

    if(values != NULL && *values != '\0') { //Added by bn152013 for 6739097
        pblock_nvinsert(the_key, (char *)values, rq->headers);
    } else {
        param_free(pblock_remove(the_key, rq->headers));
    }
    return (AM_SUCCESS);
}
Esempio n. 5
0
NSAPI_PUBLIC int web_agent_init(pblock *param, Session *sn, Request *rq)
{
    am_status_t status;
    int nsapi_status = REQ_PROCEED;
    char *temp_buf = NULL;
    char *agent_bootstrap_file = NULL;
    char *agent_config_file = NULL;

    initLock = crit_init();

    temp_buf = pblock_findval(DSAME_CONF_DIR, param);

    if (temp_buf != NULL) {
        agent_bootstrap_file = 
            system_malloc(strlen(temp_buf) + sizeof(AGENT_BOOTSTRAP_FILE));
        agent_config_file =
            system_malloc(strlen(temp_buf) + sizeof(AGENT_CONFIG_FILE));

        if (agent_bootstrap_file != NULL) {
            strcpy(agent_bootstrap_file, temp_buf);
            strcat(agent_bootstrap_file, AGENT_BOOTSTRAP_FILE);
        } else {
            log_error(LOG_FAILURE, "URL Access Agent: ", sn, rq,
                     "web_agent_init() unable to allocate memory for bootstrap "
                     "file name", DSAME_CONF_DIR);
            nsapi_status = REQ_ABORTED;
	}

        if (agent_config_file != NULL) {
            strcpy(agent_config_file, temp_buf);
            strcat(agent_config_file, AGENT_CONFIG_FILE);
        } else {
            log_error(LOG_FAILURE, "URL Access Agent: ", sn, rq,
                 "web_agent_init() unable to allocate memory for local config "
                 "file name", DSAME_CONF_DIR);
            nsapi_status = REQ_ABORTED;
        }

        status = am_properties_create(&agent_props.agent_bootstrap_props);
        if(status == AM_SUCCESS) {
            status = am_properties_load(agent_props.agent_bootstrap_props,
                                        agent_bootstrap_file);
            if(status == AM_SUCCESS) {
                //this is where the agent config info is passed from filter code
                //to amsdk. Not sure why agent_props is required.
                status = am_web_init(agent_bootstrap_file,
                                     agent_config_file);
                system_free(agent_bootstrap_file);
                system_free(agent_config_file);
                if (AM_SUCCESS != status) {
                    log_error(LOG_FAILURE, "URL Access Agent: ", sn, rq,
                             "Initialization of the agent failed: "
                             "status = %s (%d)", am_status_to_string(status),
                              status);
                    nsapi_status = REQ_ABORTED;
                 }
            } else {
                log_error(LOG_FAILURE, "web_agent_init():", sn, rq,
                         "Error while creating properties object= %s",
                          am_status_to_string(status));
                nsapi_status = REQ_ABORTED;
            }
        } else {
            log_error(LOG_FAILURE, "web_agent_init():", sn, rq,
                      "Error while creating properties object= %s",
                      am_status_to_string(status));
             nsapi_status = REQ_ABORTED;
        }
    } else {
        log_error(LOG_FAILURE, "URL Access Agent: ", sn, rq,
                 "web_agent_init() %s variable not defined in magnus.conf",
                  DSAME_CONF_DIR);
        nsapi_status = REQ_ABORTED;
    }

    if(nsapi_status == REQ_PROCEED) {
        daemon_atrestart(&agent_cleanup, NULL);
    }

    return nsapi_status;
}