示例#1
0
/*
 * Processes a 'for' element.
 */
static apr_status_t process_for (parser_rec *p, const char *element,
		int states, apr_table_t *attrs) {
	template_node_t *n;
	block_t *block;
	apr_status_t status;
	const char *names;
	char *name, *last;
	const char *sep = ", \t";

	if ((states & TEMPLATE_SOPEN) != 0) {
		n = (template_node_t *) apr_array_push(p->t);
		n->type = TEMPLATE_TFOR_INIT;
		n->for_init_in = apr_table_get(attrs, "in");
		if (n->for_init_in == NULL) {
			return parse_error(p, "missing attribute 'in'");
		}
		if ((status = compile_exp(p, n->for_init_in,
				&n->for_init_index)) != APR_SUCCESS) {
			return status;
		}

		block = (block_t *) apr_array_push(p->b);
		block->type = TEMPLATE_TFOR_NEXT;
		block->for_start = p->t->nelts;

		n = (template_node_t *) apr_array_push(p->t);
		n->type = TEMPLATE_TFOR_NEXT;
		n->for_next_names = apr_array_make(p->pool, 2,
				sizeof(const char *));
		names = apr_table_get(attrs, "names");
		if (names == NULL) {
			return parse_error(p, "missing attribute 'names'");
		}
		name = apr_strtok(apr_pstrdup(p->pool, names), sep, &last);
		while (name != NULL) {
			*((char **) apr_array_push(n->for_next_names)) = name;	
			name = apr_strtok(NULL, sep, &last);
		}
		if (n->for_next_names->nelts == 0) {
			return parse_error(p, "empty 'names'");
		}
		n->for_next_next = -1;
	}

	if ((states & TEMPLATE_SCLOSE) != 0) {
		block = (block_t *) apr_array_pop(p->b);
                if (block == NULL || block->type != TEMPLATE_TFOR_NEXT) {
                        return parse_error(p, "no 'for' to close");
		}

		n = (template_node_t *) apr_array_push(p->t);
		n->type = TEMPLATE_TJUMP;
		n->jump_next = block->for_start;

                n = ((template_node_t *) p->t->elts) + block->for_start;
                n->for_next_next = p->t->nelts;
        }

	return APR_SUCCESS;
}
/* Initialise the requisite data structs for the real dos rule
 * @param word1 The "dos rule name: subrule" format
 * @param word2 The threshold rate
 * @param word3 Time (epoch) till blockage
 * */
static void *dosblockrule_config(cmd_parms *cmd, void *mconfig, char *word1, char *word2, char *word3) {
    server_rec *s = cmd->server;
    char  *dosrulename, *subrule, *saveptr1;
    dosblock_cfg *cfg = (dosblock_cfg *)ap_get_module_config(s->module_config, &mod_dosblock_module);

    if(word1 !=NULL && word2 !=NULL && word3 !=NULL)
      {
       dosrulename = apr_strtok(word1, ":", &saveptr1);
       subrule = apr_strtok(NULL, ":", &saveptr1);
       dosrulestruct *d = NULL;
       d = apr_palloc(cmd->pool, sizeof(dosrulestruct));
       d->subrule = subrule;
       d->threshold = word2;
       d->timetoblock = word3;
       /* apr_table_set ensures that the same rule is over-written, while for
        * apr_hash_set we employ the following hack
        */
       apr_table_set(cfg->dosrulemap, dosrulename, subrule);
       if (apr_hash_get(cfg->dosrules, dosrulename, APR_HASH_KEY_STRING) != NULL) {
         /* There is an entry. Delete it. This is a hack so that we only store
          * the latest entry of the same rule
          */
            apr_hash_set(cfg->dosrules, dosrulename, APR_HASH_KEY_STRING, NULL);

        }
       apr_hash_set(cfg->dosrules, dosrulename, APR_HASH_KEY_STRING, d);
     }
    return NULL;
}
/* Parse x-www-url-formencoded args */
apr_table_t *parse_args(request_rec *r, char *args) {

  char* pair;
  char* last = NULL;
  char* eq;
  char *delim = "&";

  apr_table_t *vars = apr_table_make(r->pool, 10);
  for (pair = apr_strtok(r->args, delim, &last); pair; pair = apr_strtok(NULL, delim, &last)) {

    for (eq = pair; *eq; ++eq)
      if (*eq == '+')
        *eq = ' ';

    ap_unescape_url(pair);
    eq = strchr(pair, '=');
    if (eq) {
      *eq++ = 0;
      apr_table_merge(vars, pair, eq);
    } else {
      apr_table_merge(vars, pair, "");
    }

  }

  return vars;

}
示例#4
0
// returns the payload version, 0 if error msg, -1 if header not found
int extract_payload_from_header(apr_pool_t *pool, apr_table_t *headers, const char **payload3, const char **payload1) {
    *payload3 = NULL;
    *payload1 = NULL;
    const char *header_value = apr_table_get(headers, MOBILE_SDK_HEADER);
    if (header_value) {
        char *rest;
        char *header_cpy = apr_pstrdup(pool, header_value);
        const char *prefix = apr_strtok(header_cpy, ":", &rest);
        if (prefix == NULL) {
            // Setting payload to "" so it will fail on decryption
            *payload3 = "";
            return 0;
        }
        const char *postfix = apr_strtok(NULL, "", &rest);
        // if postfix is empty, use prefix as payload number, in this case version will be 0
        if (postfix == NULL) {
            *payload3 = prefix;
            return 0;
        }
        int version = apr_atoi64(prefix);
        switch (version) {
            case 1:
                *payload1 = postfix;
                break;
            case 3:
                *payload3 = postfix;
                break;
            default:
                return -1;
        }
        return version;
    }
    return -1;
}
示例#5
0
/**
 * \private \memberof mapcache_source_wms
 * \sa mapcache_source::configuration_parse()
 */
void _mapcache_source_wms_configuration_parse_xml(mapcache_context *ctx, ezxml_t node, mapcache_source *source)
{
  ezxml_t cur_node;
  mapcache_source_wms *src = (mapcache_source_wms*)source;


  if ((cur_node = ezxml_child(node,"getmap")) != NULL) {
    ezxml_t gm_node;
    if ((gm_node = ezxml_child(cur_node,"params")) != NULL) {
      for(gm_node = gm_node->child; gm_node; gm_node = gm_node->sibling) {
        apr_table_set(src->getmap_params, gm_node->name, gm_node->txt);
      }
    } else {
      ctx->set_error(ctx,400,"wms source %s <getmap> has no <params> block (should contain at least <LAYERS> child)",source->name);
      return;
    }
  } else {
    ctx->set_error(ctx,400,"wms source %s has no <getmap> block",source->name);
    return;
  }
  if ((cur_node = ezxml_child(node,"getfeatureinfo")) != NULL) {
    ezxml_t fi_node;
    if ((fi_node = ezxml_child(cur_node,"info_formats")) != NULL) {
      char *key,*last;
      char *iformats;
      source->info_formats = apr_array_make(ctx->pool,3,sizeof(char*));
      iformats = apr_pstrdup(ctx->pool,fi_node->txt);

      for (key = apr_strtok(iformats, "," , &last); key != NULL;
           key = apr_strtok(NULL, ",", &last)) {
        APR_ARRAY_PUSH(source->info_formats,char*) = key;
      }
    } else {
示例#6
0
/* parse parameter */
static apr_hash_t *parse_parameter(request_rec *r) {
    char *str = apr_pstrdup(r->pool, r->args);
    if( str == NULL ) {
        return NULL;
    }
    
    apr_hash_t *hash = NULL;
    const char *del = "&";
    char *items, *last, *st;
    hash = apr_hash_make(r->pool);

    // set hash
    for ( items = apr_strtok(str, del, &last); items != NULL; items = apr_strtok(NULL, del, &last) ){
        st = strchr(items, '=');
        if (st) {
            *st++ = '\0';
            ap_unescape_url(items);
            ap_unescape_url(st);
        } else {
            st = "";
            ap_unescape_url(items);
        }
        apr_hash_set( hash, items, APR_HASH_KEY_STRING, st );
    }
    return hash;
}
示例#7
0
static void
argstr_to_table(apr_pool_t *p, char *str, apr_table_t *parms)
{
    char *key;
    char *value;
    char *strtok_state;

    key = apr_strtok(str, "&", &strtok_state);
    while (key) {
        value = strchr(key, '=');
        if (value) {
            *value = '\0';      /* Split the string in two */
            value++;            /* Skip passed the = */
        }
        else {
            value = "1";
        }
        ap_unescape_url(key);
        ap_unescape_url(value);
        apr_table_set(parms, key, value);
        /*
         ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r,
         "Found query arg: %s = %s", key, value);
         */
        key = apr_strtok(NULL, "&", &strtok_state);
    }
}
static int check_for_cookie(void *rec, const char *key, const char *value) {
    if (strcasecmp("Cookie", key) == 0) {
        check_for_cookie_data_t *data = rec;
        if (data->cookie_name == NULL) {
            crowd_cookie_config_t *cookie_config = crowd_get_cookie_config(data->r, data->config->crowd_config);
            if (cookie_config == NULL || cookie_config->cookie_name == NULL || (cookie_config->secure && !is_https(data->r))) {
                return 0;
            }
            data->cookie_name = log_ralloc(data->r, apr_pstrcat(data->r->pool, cookie_config->cookie_name, "=", NULL));
            if (data->cookie_name == NULL) {
                return 0;
            }
            data->cookie_name_len = strlen(data->cookie_name);
        }
        char *cookies = log_ralloc(data->r, apr_pstrdup(data->r->pool, value));
        if (cookies == NULL) {
            return 0;
        }
        apr_collapse_spaces(cookies, cookies);
        char *last;
        char *cookie = apr_strtok(cookies, ";,", &last);
        while (cookie != NULL) {
            if (strncasecmp(cookie, data->cookie_name, data->cookie_name_len) == 0) {
                data->token = log_ralloc(data->r, apr_pstrdup(data->r->pool, cookie + data->cookie_name_len));
                return 0;
            }
            cookie = apr_strtok(NULL, ";,", &last);
        }
    }
    return 1;
}
示例#9
0
static int
valid_domain(request_rec *r, const char *value)
{
  int  len;
  char *name;
  char *val;
  char *pstat;
  char *p = apr_pstrdup(r->pool, value);
  const char *host = apr_table_get(r->headers_in, HTTP_HOST);

  DBG(r, "start valid_domain() value:[%s]", value);
  DBG(r, "host:[%s]", host);
  if (!host)
    return CHXJ_TRUE;

  name = apr_strtok(p,"=", &pstat);
  name = qs_trim_string(r->pool, name);
  val = apr_strtok(NULL, "=", &pstat);
  val = qs_trim_string(r->pool, val);
  len = strlen(host);
  if (len) {
    if (chxj_strcasenrcmp(r->pool, host, val, strlen(val))) {
      DBG(r, "not match domain. host domain:[%s] vs value:[%s]", host, val);
      return CHXJ_FALSE;
    }
  }
  DBG(r, "end valid_domain() value:[%s]", value);
  return CHXJ_TRUE;
}
示例#10
0
/**
 * Copied from httpd/trunk/modules/cluster/mod_heartbeat.c.
 *
 * Copyright 2009 The Apache Software Foundation.
 *
 * The following function is licensed under the Apache
 * License, Version 2.0. See COPYING for more details.
 */
static void qs_to_table(const char *input, apr_table_t *parms,
                        apr_pool_t *p)
{
    char *key;
    char *value;
    char *query_string;
    char *strtok_state;

    if (input == NULL) {
        return;
    }

    query_string = apr_pstrdup(p, input);

    key = apr_strtok(query_string, "&", &strtok_state);
    while (key) {
        value = strchr(key, '=');
        if (value) {
            *value = '\0';      /* Split the string in two */
            value++;            /* Skip passed the = */
        }
        else {
            value = "1";
        }
        ap_unescape_url(key);
        ap_unescape_url(value);
        apr_table_set(parms, key, value);
        /*
           ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r,
           "Found query arg: %s = %s", key, value);
         */
        key = apr_strtok(NULL, "&", &strtok_state);
    }
}
示例#11
0
文件: utils.c 项目: petarov/strelko
strtokens_t* utils_strsplit(char *str, const char *sep, apr_pool_t *mp) {

	strtokens_t 		*tokens = apr_palloc(mp, sizeof(strtokens_t));
    tokens->size = 0;
    tokens->token = NULL;
    
	apr_array_header_t 	*arr 	= apr_array_make(mp, TOKEN_ARRAY_INIT_SIZE, sizeof(const char *));
	char *state 	= NULL;
	char *next 		= apr_strtok(str, sep, &state);

	while (next != NULL ) {
		*(char **)apr_array_push(arr) = next; // apr_pstrdup(mp, next);
		next = apr_strtok(NULL, sep, &state);
	}
	// copy once again the values into strtokens_st
	// ...hey, I know it's slow, but I don't want to deal with APR arrays :(
	tokens->size = arr->nelts;
	if (arr->nelts) {
		tokens->token = (char **)apr_palloc(mp, sizeof(char **) * arr->nelts);
		for (int i = 0; i < arr->nelts; i++) {
			const char *s = ((const char**)arr->elts)[i];
			tokens->token[i] = apr_pstrdup(mp, s);
		}
	}
	return tokens;
}
示例#12
0
static void _mapcache_dimension_values_parse_xml(mapcache_context *ctx, mapcache_dimension *dim,
        ezxml_t node) {
    int count = 1;
    mapcache_dimension_values *dimension;
    const char *case_sensitive;
    char *key,*last;
    char *values;
    const char *entry = node->txt;
    if(!entry || !*entry) {
        ctx->set_error(ctx,400,"failed to parse dimension values: none supplied");
        return;
    }

    dimension = (mapcache_dimension_values*)dim;
    case_sensitive = ezxml_attr(node,"case_sensitive");
    if(case_sensitive && !strcasecmp(case_sensitive,"true")) {
        dimension->case_sensitive = 1;
    }

    values = apr_pstrdup(ctx->pool,entry);
    for(key=values; *key; key++) if(*key == ',') count++;

    dimension->values = (char**)apr_pcalloc(ctx->pool,count*sizeof(char*));

    for (key = apr_strtok(values, ",", &last); key != NULL;
            key = apr_strtok(NULL, ",", &last)) {
        dimension->values[dimension->nvalues]=key;
        dimension->nvalues++;
    }
    if(!dimension->nvalues) {
        ctx->set_error(ctx, 400, "<dimension> \"%s\" has no values",dim->name);
        return;
    }
}
示例#13
0
/* Given a string like "HTTP/1.1 500 (status)" in BUF, parse out the numeric
   status code into *STATUS_CODE_OUT.  Ignores leading whitespace. */
static svn_error_t *
parse_status_line(int *status_code_out,
                  const char **reason,
                  const char *status_line,
                  apr_pool_t *result_pool,
                  apr_pool_t *scratch_pool)
{
  svn_error_t *err;
  const char *token;
  char *tok_status;
  svn_stringbuf_t *temp_buf = svn_stringbuf_create(status_line, scratch_pool);

  svn_stringbuf_strip_whitespace(temp_buf);
  token = apr_strtok(temp_buf->data, " \t\r\n", &tok_status);
  if (token)
    token = apr_strtok(NULL, " \t\r\n", &tok_status);
  if (!token)
    return svn_error_createf(SVN_ERR_RA_DAV_MALFORMED_DATA, NULL,
                             _("Malformed DAV:status '%s'"),
                             status_line);
  err = svn_cstring_atoi(status_code_out, token);
  if (err)
    return svn_error_createf(SVN_ERR_RA_DAV_MALFORMED_DATA, err,
                             _("Malformed DAV:status '%s'"),
                             status_line);

  token = apr_strtok(NULL, " \t\r\n", &tok_status);

  *reason = apr_pstrdup(result_pool, token);

  return SVN_NO_ERROR;
}
示例#14
0
static apt_bool_t cmdline_process(char *cmdline)
{
	apt_bool_t running = TRUE;
	char *name;
	char *last;
	name = apr_strtok(cmdline, " ", &last);

	if(strcasecmp(name,"loglevel") == 0) {
		char *priority = apr_strtok(NULL, " ", &last);
		if(priority) {
			apt_log_priority_set(atol(priority));
		}
	}
	else if(strcasecmp(name,"exit") == 0 || strcmp(name,"quit") == 0) {
		running = FALSE;
	}
	else if(strcasecmp(name,"help") == 0) {
		printf("usage:\n");
		printf("- loglevel [level] (set loglevel, one of 0,1...7)\n");
		printf("- quit, exit\n");
	}
	else {
		printf("unknown command: %s (input help for usage)\n",name);
	}
	return running;
}
示例#15
0
celix_status_t deploymentAdmin_readVersions(deployment_admin_pt admin, array_list_pt *versions) {
	celix_status_t status = CELIX_SUCCESS;
	arrayList_create(versions);
	CURL *curl;
	CURLcode res;
	curl = curl_easy_init();
	struct MemoryStruct chunk;
	chunk.memory = calloc(1, sizeof(char));
	chunk.size = 0;
	if (curl) {
		curl_easy_setopt(curl, CURLOPT_URL, admin->pollUrl);
		curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, deploymentAdmin_parseVersions);
		curl_easy_setopt(curl, CURLOPT_WRITEDATA, &chunk);
		curl_easy_setopt(curl, CURLOPT_FAILONERROR, true);
		res = curl_easy_perform(curl);
		if (res != CURLE_OK) {
			status = CELIX_BUNDLE_EXCEPTION;
		}
		/* always cleanup */
		curl_easy_cleanup(curl);

		char *last;
		char *token = apr_strtok(chunk.memory, "\n", &last);
		while (token != NULL) {
			arrayList_add(*versions, apr_pstrdup(admin->pool, token));
			token = apr_strtok(NULL, "\n", &last);
		}
	}



	return status;
}
static char* netepi_crypt(request_rec *r, char *password, char *encrypted_password_with_salt)
{
	/* We do this ourselves, because platform crypt() implementations vary too
	 * much, and we'd like our data to be portable.
	 *
	 * We need to extract the salt from the encrypted_password_with_salt string
	 * prefixed by $S$xxxxxxxx$.
	 * We know it starts with '$' at this point.
     */
	char *saltcopy;
	char *salt;
	char *saveptr;
	char *salted_password;
	char sha1hash[APR_SHA1PW_IDLEN + APR_SHA1_DIGESTSIZE + 1];
	char *final_hash;

	saltcopy = apr_pstrdup(r->pool, encrypted_password_with_salt);
	if (saltcopy == NULL)
		return NULL;
	salt = apr_strtok(saltcopy, "$", &saveptr);
	if (salt == NULL || strcmp(salt, "S"))
		return NULL;	/* Wrong hash method */
	salt = apr_strtok(NULL, "$", &saveptr);
	if (salt == NULL)
		return NULL;	/* No salt! */
	salted_password = apr_pstrcat(r->pool, salt, password, NULL);
	if (salted_password == NULL)
		return NULL;
	apr_sha1_base64(salted_password, strlen(salted_password), sha1hash);
	/* We want to skip over the "{SHA1}" in the hash and allow room for $S$...$...\0 */
	final_hash = apr_pstrcat(r->pool, "$S$", salt, "$", &sha1hash[APR_SHA1PW_IDLEN], NULL);
	return final_hash;
}
static const char *set_memc_addr(cmd_parms *parms, void *mconfig, const char *arg)
{
    const char *err;
    char *next, *last, *memc_addr_str;
    memc_addr_ilimit_entry *memc_addr;
    interval_limit_config *conf = mconfig;
    if (!conf){
        return "IntervalLimitModule: Failed to retrieve configuration for mod_interval_limit";
    }

    /*
    * split memc_addr string into each server addr
    */
    memc_addr_str = (char*)apr_pstrdup(parms->pool, (char*)arg);
    next =  (char*)apr_strtok( memc_addr_str, ",", &last);
    while (next) {
        apr_collapse_spaces (next, next);
        memc_addr = (memc_addr_ilimit_entry *)apr_array_push(conf->memc_addrs);
        if( (err = parse_memc_addr(parms->pool, next, memc_addr))!=NULL ) {
            return apr_psprintf(parms->pool, "IntervalLimitModule: %s", err);
        }
        next = (char*)apr_strtok(NULL, ",", &last);
    }
    return NULL;
}
示例#18
0
static void fill_gmi(Ganglia_25metric* gmi, py_metric_init_t* minfo)
{
    char *s, *lasts;
    int i;
    const apr_array_header_t *arr = apr_table_elts(minfo->extra_data);
    const apr_table_entry_t *elts = (const apr_table_entry_t *)arr->elts;

    /* gmi->key will be automatically assigned by gmond */
    gmi->name = apr_pstrdup (pool, minfo->mname);
    gmi->tmax = minfo->tmax;
    if (!strcasecmp(minfo->vtype, "string")) {
        gmi->type = GANGLIA_VALUE_STRING;
        gmi->msg_size = UDP_HEADER_SIZE+MAX_G_STRING_SIZE;
    }
    else if (!strcasecmp(minfo->vtype, "uint")) {
        gmi->type = GANGLIA_VALUE_UNSIGNED_INT;
        gmi->msg_size = UDP_HEADER_SIZE+8;
    }
    else if (!strcasecmp(minfo->vtype, "int")) {
        gmi->type = GANGLIA_VALUE_INT;
        gmi->msg_size = UDP_HEADER_SIZE+8;
    }
    else if (!strcasecmp(minfo->vtype, "float")) {
        gmi->type = GANGLIA_VALUE_FLOAT;
        gmi->msg_size = UDP_HEADER_SIZE+8;
    }
    else if (!strcasecmp(minfo->vtype, "double")) {
        gmi->type = GANGLIA_VALUE_DOUBLE;
        gmi->msg_size = UDP_HEADER_SIZE+16;
    }
    else {
        gmi->type = GANGLIA_VALUE_UNKNOWN;
        gmi->msg_size = UDP_HEADER_SIZE+8;
    }

    gmi->units = apr_pstrdup(pool, minfo->units);
    gmi->slope = apr_pstrdup(pool, minfo->slope);
    gmi->fmt = apr_pstrdup(pool, minfo->format);
    gmi->desc = apr_pstrdup(pool, minfo->desc);

    MMETRIC_INIT_METADATA(gmi, pool);
    for (s=(char *)apr_strtok(minfo->groups, ",", &lasts);
          s!=NULL; s=(char *)apr_strtok(NULL, ",", &lasts)) {
        char *d = s;
        /* Strip the leading white space */
        while (d && *d && apr_isspace(*d)) {
            d++;
        }
        MMETRIC_ADD_METADATA(gmi,MGROUP,d);
    }

    /* transfer any extra data as metric metadata */
    for (i = 0; i < arr->nelts; ++i) {
        if (elts[i].key == NULL)
            continue;
        MMETRIC_ADD_METADATA(gmi, elts[i].key, elts[i].val);
    }
}
示例#19
0
/* Iterate through the cookies, isolate our cookie and then remove it.
 *
 * If our cookie appears two or more times, but with different values,
 * remove it twice and set the duplicated flag to true. Remove any
 * $path or other attributes following our cookie if present. If we end
 * up with an empty cookie, remove the whole header.
 */
static int extract_cookie_line(ap_cookie_do * v, const char *key, const char *val)
{
    char *last1, *last2;
    char *cookie = apr_pstrdup(v->r->pool, val);
    const char *name = apr_pstrcat(v->r->pool, v->name ? v->name : "", "=", NULL);
    apr_size_t len = strlen(name);
    const char *new_cookie = "";
    const char *comma = ",";
    char *next1;
    const char *semi = ";";
    char *next2;
    const char *sep = "";
    int cookies = 0;

    /* find the cookie called name */
    int eat = 0;
    next1 = apr_strtok(cookie, comma, &last1);
    while (next1) {
        next2 = apr_strtok(next1, semi, &last2);
        while (next2) {
            char *trim = next2;
            while (apr_isspace(*trim)) {
                trim++;
            }
            if (!strncmp(trim, name, len)) {
                if (v->encoded) {
                    if (strcmp(v->encoded, trim + len)) {
                        v->duplicated = 1;
                    }
                }
                v->encoded = apr_pstrdup(v->r->pool, trim + len);
                eat = 1;
            }
            else {
                if (*trim != '$') {
                    cookies++;
                    eat = 0;
                }
                if (!eat) {
                    new_cookie = apr_pstrcat(v->r->pool, new_cookie, sep, next2, NULL);
                }
            }
            next2 = apr_strtok(NULL, semi, &last2);
            sep = semi;
        }

        next1 = apr_strtok(NULL, comma, &last1);
        sep = comma;
    }

    /* any cookies left over? */
    if (cookies) {
        apr_table_addn(v->new_cookies, key, new_cookie);
    }

    return 1;
}
示例#20
0
文件: add.c 项目: vocho/openqnx
/* For one auto-props config entry (NAME, VALUE), if the filename pattern
   NAME matches BATON->filename case insensitively then add the properties
   listed in VALUE into BATON->properties.
   BATON must point to an auto_props_baton_t.
*/
static svn_boolean_t
auto_props_enumerator(const char *name,
                      const char *value,
                      void *baton,
                      apr_pool_t *pool)
{
  auto_props_baton_t *autoprops = baton;
  char *property;
  char *last_token;

  /* nothing to do here without a value */
  if (strlen(value) == 0)
    return TRUE;

  /* check if filename matches and return if it doesn't */
  if (apr_fnmatch(name, autoprops->filename, APR_FNM_CASE_BLIND) == APR_FNM_NOMATCH)
    return TRUE;

  /* parse the value (we dup it first to effectively lose the
     'const', and to avoid messing up the original value) */
  property = apr_pstrdup(autoprops->pool, value);
  property = apr_strtok(property, ";", &last_token);
  while (property)
    {
      int len;
      const char *this_value;
      char *equal_sign = strchr(property, '=');

      if (equal_sign)
        {
          *equal_sign = '\0';
          equal_sign++;
          trim_string(&equal_sign);
          this_value = equal_sign;
        }
      else
        {
          this_value = "";
        }
      trim_string(&property);
      len = strlen(property);
      if (len > 0)
        {
          svn_string_t *propval = svn_string_create(this_value,
                                                    autoprops->pool);

          apr_hash_set(autoprops->properties, property, len, propval);
          if (strcmp(property, SVN_PROP_MIME_TYPE) == 0)
            autoprops->mimetype = this_value;
          else if (strcmp(property, SVN_PROP_EXECUTABLE) == 0)
            autoprops->have_executable = TRUE;
        }
      property = apr_strtok(NULL, ";", &last_token);
    }
  return TRUE;
}
示例#21
0
static apr_hash_t *parse_form_from_string(request_rec *r, char *args) {
  apr_hash_t *form;
  /*  apr_array_header_t *values = NULL;*/
  char *pair;
  char *eq;
  const char *delim = "&";
  char *last;
  char *values;

  if(args == NULL) {
    return NULL;
  }

  form = apr_hash_make(r->pool);
  
  /* Split the input on '&' */
  for (pair = apr_strtok(args, delim, &last); pair != NULL;
       pair = apr_strtok(NULL, delim, &last)) {
    for (eq = pair; *eq; ++eq) {
      if (*eq == '+') {
	*eq = ' ';
      }
    }

    /* split into key value and unescape it */
    eq = strchr(pair, '=');
    
    if(eq) {
      *eq++ = '\0';
      ap_unescape_url(pair);
      ap_unescape_url(eq);
    } else {
      eq = "";
      ap_unescape_url(pair);
    }

    /* Store key/value pair in out form hash. Given that there
     * may be many values for the same key, we store values
     * in an array (which we'll have to create the first
     * time we encounter the key in question).
     */
    values = apr_hash_get(form, pair, APR_HASH_KEY_STRING);
    if(values != NULL) {
      values = apr_pstrcat(r->pool, values, "&", eq, NULL);
      /*      values = apr_array_make(r->pool, 1, sizeof(const char*));
	      apr_hash_set(form, pair, APR_HASH_KEY_STRING, values);*/
    } else {
      values = apr_pstrdup(r->pool, eq);
    }
    apr_hash_set(form, pair, APR_HASH_KEY_STRING, values);
  }

  return form;
  
}
示例#22
0
static apt_bool_t mpf_codec_manager_codec_parse(const mpf_codec_manager_t *codec_manager, mpf_codec_list_t *codec_list, char *codec_desc_str, apr_pool_t *pool)
{
	const mpf_codec_t *codec;
	mpf_codec_descriptor_t *descriptor;
	const char *separator = "/";
	char *state;
	/* parse codec name */
	char *str = apr_strtok(codec_desc_str, separator, &state);
	codec_desc_str = NULL; /* make sure we pass NULL on subsequent calls of apr_strtok() */
	if(str) {
		apt_str_t name;
		apt_string_assign(&name,str,pool);
		/* find codec by name */
		codec = mpf_codec_manager_codec_find(codec_manager,&name);
		if(!codec) {
			apt_log(APT_LOG_MARK,APT_PRIO_WARNING,"No Such Codec [%s]",str);
			return FALSE;
		}

		descriptor = mpf_codec_list_add(codec_list);
		descriptor->name = name;

		/* set defualt attributes */
		if(codec->static_descriptor) {
			descriptor->payload_type = codec->static_descriptor->payload_type;
			descriptor->sampling_rate = codec->static_descriptor->sampling_rate;
			descriptor->channel_count = codec->static_descriptor->channel_count;
		}
		else {
			descriptor->payload_type = 96;
			descriptor->sampling_rate = 8000;
			descriptor->channel_count = 1;
		}

		/* parse optional payload type */
		str = apr_strtok(codec_desc_str, separator, &state);
		if(str) {
			descriptor->payload_type = (apr_byte_t)atol(str);

			/* parse optional sampling rate */
			str = apr_strtok(codec_desc_str, separator, &state);
			if(str) {
				descriptor->sampling_rate = (apr_uint16_t)atol(str);

				/* parse optional channel count */
				str = apr_strtok(codec_desc_str, separator, &state);
				if(str) {
					descriptor->channel_count = (apr_byte_t)atol(str);
				}
			}
		}
	}
	return TRUE;
}
示例#23
0
static ftpd_chroot_status_t ftpd_dbm_map_chroot(const request_rec *r,
										const char **chroot,
										const char **initroot)
{
	apr_status_t res;
	apr_dbm_t *file;
	ftpd_chroot_status_t ret = FTPD_CHROOT_USER_NOT_FOUND;
	apr_datum_t key,val = { 0 };
	char *value, *tok, *tok_ses;
	ftpd_user_rec *ur  __attribute__ ((unused))= ftpd_get_user_rec(r);
	ftpd_dbm_server_conf *pConfig = ap_get_module_config(r->server->module_config,
										&ftpd_dbm_module);

	if ((res = apr_dbm_open_ex(&file, pConfig->dbtype, pConfig->chrootdb_path,
								APR_DBM_READONLY, APR_OS_DEFAULT, r->pool))
								!= APR_SUCCESS) {
		ap_log_rerror(APLOG_MARK, APLOG_ERR, res, r,
			"Error opening DBM file: %s",pConfig->chrootdb_path);
		ret = FTPD_CHROOT_FAIL;
	} else {
		if (file != NULL) {
			/* search the DB */
			key.dptr = r->user;
			key.dsize = strlen(key.dptr);

			if (apr_dbm_exists(file, key)) {
				if (apr_dbm_fetch(file, key, &val) == APR_SUCCESS) {
					value = apr_pstrndup(r->pool, val.dptr, val.dsize);
					tok = apr_strtok(value, ":", &tok_ses);
					if (tok != NULL) {
						*chroot = apr_pstrdup(r->pool, tok);
						tok = apr_strtok(NULL, ":", &tok_ses);
						if (tok != NULL) {
							*initroot = apr_pstrdup(r->pool, tok);
						}
						ret = FTPD_CHROOT_USER_FOUND;
					} else {
						ret = FTPD_CHROOT_FAIL;
					}
				}
			}

			apr_dbm_close(file);
		} else {
			ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r,
				"File open failed: %s",pConfig->chrootdb_path);
			ret = FTPD_CHROOT_FAIL;
		}
	}
	return ret;
}
示例#24
0
文件: sub_command.c 项目: jawi/celix
void subCommand_execute(command_pt command, char *line, void (*out)(char *), void (*err)(char *)) {
	celix_status_t status = CELIX_SUCCESS;
    service_reference_pt calculatorService = NULL;
    apr_pool_t *memory_pool = NULL;
    apr_pool_t *bundle_memory_pool = NULL;

    status = bundleContext_getServiceReference(command->bundleContext, (char *) CALCULATOR_SERVICE, &calculatorService);
    if (status == CELIX_SUCCESS) {
    	char *token;
		char *commandStr = apr_strtok(line, " ", &token);
		char *aStr = apr_strtok(NULL, " ", &token);
		bool numeric;
		subCommand_isNumeric(command, aStr, &numeric);
		if (aStr != NULL && numeric) {
			char *bStr = apr_strtok(NULL, " ", &token);
			subCommand_isNumeric(command, bStr, &numeric);
			if (bStr != NULL && numeric) {
				calculator_service_pt calculator = NULL;
				status = bundleContext_getService(command->bundleContext, calculatorService, (void *) &calculator);
				if (status == CELIX_SUCCESS) {
					double a = atof(aStr);
					double b = atof(bStr);
					double result = 0;
					status = calculator->sub(calculator->calculator, a, b, &result);
					if (status == CELIX_SUCCESS) {
						char line[256];
						sprintf(line, "CALCULATOR_SHELL: Sub: %f - %f = %f\n", a, b, result);
						out(line);
					} else {
						out("SUB: Unexpected exception in Calc service\n");
					}
				} else {
					out("No calc service available\n");
				}
			} else {
				out("SUB: Requires 2 numerical parameter\n");
			}
		} else {
			out("SUB: Requires 2 numerical parameter\n");
			status = CELIX_ILLEGAL_ARGUMENT;
		}

        double a;
        double b;
    } else {
        out("No calc service available\n");
    }

    //return status;
}
示例#25
0
static void _mapcache_dimension_intervals_parse_xml(mapcache_context *ctx, mapcache_dimension *dim,
        ezxml_t node) {
    mapcache_dimension_intervals *dimension;
    char *key,*last;
    char *values;
    const char *entry = node->txt;
    int count = 1;
    if(!entry || !*entry) {
        ctx->set_error(ctx,400,"failed to parse dimension values: none supplied");
        return;
    }
    dimension = (mapcache_dimension_intervals*)dim;
    values = apr_pstrdup(ctx->pool,entry);

    for(key=values; *key; key++) if(*key == ',') count++;

    dimension->intervals = (mapcache_interval*)apr_pcalloc(ctx->pool,count*sizeof(mapcache_interval));

    for (key = apr_strtok(values, ",", &last); key != NULL;
            key = apr_strtok(NULL, ",", &last)) {
        char *endptr;
        mapcache_interval *interval = &dimension->intervals[dimension->nintervals];
        interval->start = strtod(key,&endptr);
        if(*endptr != '/') {
            ctx->set_error(ctx,400,"failed to parse min dimension value \"%s\" in \"%s\" for dimension %s",key,entry,dim->name);
            return;
        }
        key = endptr+1;

        interval->end = strtod(key,&endptr);
        if(*endptr != '/') {
            ctx->set_error(ctx,400,"failed to parse max dimension value \"%s\" in \"%s\" for dimension %s",key,entry,dim->name);
            return;
        }
        key = endptr+1;
        interval->resolution = strtod(key,&endptr);
        if(*endptr != '\0') {
            ctx->set_error(ctx,400,"failed to parse resolution dimension value \"%s\" in \"%s\" for dimension %s",key,entry,dim->name);
            return;
        }
        dimension->nintervals++;
    }

    if(!dimension->nintervals) {
        ctx->set_error(ctx, 400, "<dimension> \"%s\" has no intervals",dim->name);
        return;
    }
}
示例#26
0
static int
valid_path(request_rec *r, const char *value)
{
  char *p = apr_pstrdup(r->pool, value);
  char *uri;
  char *tmp;
  char *name;
  char *val;
  char *pstat;

  DBG(r, "start valid_path() unparsed_uri:[%s] value:[%s]", r->unparsed_uri, value);
  if (chxj_starts_with(r->unparsed_uri, "http://")) {
    uri = strchr(&r->unparsed_uri[sizeof("http://")], '/');
    if (uri != NULL) {
      uri = apr_pstrdup(r->pool, uri);
    }
  }
  else if (chxj_starts_with(r->unparsed_uri, "https://")) {
    uri = strchr(&r->unparsed_uri[sizeof("https://")], '/');
    if (uri != NULL) {
      uri = apr_pstrdup(r->pool, uri);
    }
  }
  else if (chxj_starts_with(r->unparsed_uri, "/")) {
    uri = apr_pstrdup(r->pool, r->unparsed_uri);
  }
  else {
    uri = apr_pstrdup(r->pool, "/");
  }
  
  if ((tmp = strchr(uri, '?'))) {
    *tmp = '\0';
  }
  DBG(r, "uri=[%s]", uri);
  name = apr_strtok(p, "=", &pstat);
  val = apr_strtok(NULL, "=", &pstat);
  name = qs_trim_string(r->pool, name);
  val = qs_trim_string(r->pool, val);
  DBG(r, "name=[%s] val=[%s]", name, val);
  
  DBG(r, "val:[%s] vs uri:[%s]", val, uri);
  if (! chxj_starts_with(uri, val)) {
    DBG(r, "end valid_path() unparsed_uri:[%s] value:[%s] (false)", r->unparsed_uri, value);
    return CHXJ_FALSE;
  }
  DBG(r, "end valid_path() unparsed_uri:[%s] value:[%s] (true)", r->unparsed_uri, value);
  return CHXJ_TRUE;
}
示例#27
0
apr_status_t apr_filepath_list_split_impl(apr_array_header_t **pathelts,
                                          const char *liststr,
                                          char separator,
                                          apr_pool_t *p)
{
    char *path, *part, *ptr;
    char separator_string[2] = { '\0', '\0' };
    apr_array_header_t *elts;
    int nelts;

    separator_string[0] = separator;
    /* Count the number of path elements. We know there'll be at least
       one even if path is an empty string. */
    path = apr_pstrdup(p, liststr);
    for (nelts = 0, ptr = path; ptr != NULL; ++nelts)
    {
        ptr = strchr(ptr, separator);
        if (ptr)
            ++ptr;
    }

    /* Split the path into the array. */
    elts = apr_array_make(p, nelts, sizeof(char*));
    while ((part = apr_strtok(path, separator_string, &ptr)) != NULL)
    {
        if (*part == '\0')      /* Ignore empty path components. */
            continue;

        *(char**)apr_array_push(elts) = part;
        path = NULL;            /* For the next call to apr_strtok */
    }

    *pathelts = elts;
    return APR_SUCCESS;
}
示例#28
0
/** Create factory of MRCPv2 connection agents */
static mrcp_ca_factory_t* unimrcp_client_ca_factory_create(unimrcp_client_loader_t *loader, const apr_xml_elem *elem)
{
	mrcp_ca_factory_t *ca_factory = NULL;
	mrcp_connection_agent_t *agent;
	char *name;
	char *state;
	char *list_str = apr_pstrdup(loader->pool,cdata_text_get(elem));
	do {
		name = apr_strtok(list_str, ",", &state);
		if(name) {
			agent = mrcp_client_connection_agent_get(loader->client,name);
			if(agent) {
				if(!ca_factory)
					ca_factory = mrcp_ca_factory_create(loader->pool);

				mrcp_ca_factory_agent_add(ca_factory,agent);
			}
			else {
				apt_log(APT_LOG_MARK,APT_PRIO_WARNING,"Unknown MRCPv2-UAC Name <%s>",name);
			}
		}
		list_str = NULL; /* make sure we pass NULL on subsequent calls of apr_strtok() */
	}
	while(name);
	return ca_factory;
}
示例#29
0
static void test_strtok(CuTest *tc)
{
    struct {
        char *input;
        char *sep;
    }
    cases[] = {
        {
            "",
            "Z"
        },
        {
            "      asdf jkl; 77889909            \r\n\1\2\3Z",
            " \r\n\3\2\1"
        },
        {
            NULL,  /* but who cares if apr_strtok() segfaults? */
            " \t"
        },
#if 0     /* don't do this... you deserve to segfault */
        {
            "a b c              ",
            NULL
        },
#endif
        {
            "   a       b        c   ",
            ""
        },
        {
            "a              b c         ",
            " "
        }
    };
    int curtc;

    for (curtc = 0; curtc < sizeof cases / sizeof cases[0]; curtc++) {
        char *retval1, *retval2;
        char *str1, *str2;
        char *state;

        str1 = apr_pstrdup(p, cases[curtc].input);
        str2 = apr_pstrdup(p, cases[curtc].input);

        do {
            retval1 = apr_strtok(str1, cases[curtc].sep, &state);
            retval2 = strtok(str2, cases[curtc].sep);

            if (!retval1) {
                CuAssertTrue(tc, retval2 == NULL);
            }
            else {
                CuAssertTrue(tc, retval2 != NULL);
                CuAssertStrEquals(tc, retval2, retval1);
            }

            str1 = str2 = NULL; /* make sure we pass NULL on subsequent calls */
        } while (retval1);
    }
}
示例#30
0
/** Create factory of media engines */
static mpf_engine_factory_t* unimrcp_client_mpf_factory_create(unimrcp_client_loader_t *loader, const apr_xml_elem *elem)
{
	mpf_engine_factory_t *mpf_factory = NULL;
	mpf_engine_t *media_engine;

	char *name;
	char *state;
	char *list_str = apr_pstrdup(loader->pool,cdata_text_get(elem));
	do {
		name = apr_strtok(list_str, ",", &state);
		if(name) {
			media_engine = mrcp_client_media_engine_get(loader->client,name);
			if(media_engine) {
				if(!mpf_factory)
					mpf_factory = mpf_engine_factory_create(loader->pool);

				mpf_engine_factory_engine_add(mpf_factory,media_engine);
			}
			else {
				apt_log(APT_LOG_MARK,APT_PRIO_WARNING,"Unknown Media Engine Name <%s>",name);
			}
		}
		list_str = NULL; /* make sure we pass NULL on subsequent calls of apr_strtok() */
	}
	while(name);

	return mpf_factory;
}