Exemple #1
0
static inline void parse_algo_hdr(struct hdr_field* algo_hdr, int* algo, int* b64_required)
{
	int rc;
	char* delim=NULL;

	str tok;
	str s_tok;

	s_tok.s = algo_hdr->body.s;
	s_tok.len = algo_hdr->body.len;

	do {
		delim = q_memchr(s_tok.s, ATTR_DELIM[0], s_tok.len);

		if (delim==NULL) {
			trim_spaces_lr(s_tok);
			rc = get_algo(&s_tok);
		} else {
			tok.s = s_tok.s;
			tok.len = delim - s_tok.s;

			s_tok.s = delim+1;
			s_tok.len = (delim-tok.s+1);

			trim_spaces_lr(tok);
			rc = get_algo(&tok);
		}

		if (rc < 2 && rc >=0)
			*algo = rc;
		else
			*b64_required = rc;
	} while(delim);
}
Exemple #2
0
int httpd_register_httpdcb(const char *module, str *http_root,
			httpd_acces_handler_cb f1,
			httpd_flush_data_cb f2,
			enum HTTPD_CONTENT_TYPE type,
			httpd_init_proc_cb f3)
{
	int i;
	struct httpd_cb *cb;

	if (!module) {
		LM_ERR("NULL module name\n"); return -1;
	}
	if (!http_root) {
		LM_ERR("NULL http root path\n"); return -1;
	}
	if (!f1) {
		LM_ERR("NULL acces handler cb\n"); return -1;
	}
	if (!f2) {
		LM_ERR("NULL flush data cb\n"); return -1;
	}

	trim_spaces_lr(*http_root);
	if (!http_root->len) {
		LM_ERR("invalid http root path from module [%s]\n", module);
		return -1;
	}
	for(i=0;i<http_root->len;i++) {
		if ( !isalnum(http_root->s[i]) && http_root->s[i]!='_') {
			LM_ERR("bad mi_http_root param [%.*s], char [%c] "
				"- use only alphanumerical characters\n",
				http_root->len, http_root->s, http_root->s[i]);
			return -1;
		}
	}
	cb = (struct httpd_cb*)shm_malloc(sizeof(struct httpd_cb));
	if (cb==NULL) {
		LM_ERR("no more shm mem\n");
		return -1;
	}

	cb->module = module;
	cb->type = type;
	cb->http_root = http_root;
	cb->callback = f1;
	cb->flush_data_callback = f2;
	cb->init_proc_callback = f3;
	cb->next = httpd_cb_list;
	httpd_cb_list = cb;

	LM_DBG("got root_path [%s][%.*s]\n",
		cb->module, cb->http_root->len, cb->http_root->s);
	return 0;
}
Exemple #3
0
/*!
 * \brief Add profile definitions to the global list
 * \see new_dlg_profile
 * \param profiles profile name
 * \param has_value set to 0 for a profile without value, otherwise it has a value
 * \return 0 on success, -1 on failure
 */
int add_profile_definitions( char* profiles, unsigned int has_value)
{
	char *p;
	char *d;
	str name;
	unsigned int i;

	if (profiles==NULL || strlen(profiles)==0 )
		return 0;

	p = profiles;
	do {
		/* locate name of profile */
		name.s = p;
		d = strchr( p, ';');
		if (d) {
			name.len = d-p;
			d++;
		} else {
			name.len = strlen(p);
		}

		/* we have the name -> trim it for spaces */
		trim_spaces_lr( name );

		/* check len name */
		if (name.len==0)
			/* ignore */
			continue;

		/* check the name format */
		for(i=0;i<name.len;i++) {
			if ( !isalnum(name.s[i]) && name.s[i] != '_' ) {
				LM_ERR("bad profile name <%.*s>, char %c - use only "
					"alphanumerical characters or '_'\n", name.len,name.s,name.s[i]);
				return -1;
			}
		}

		/* name ok -> create the profile */
		LM_DBG("creating profile <%.*s>\n",name.len,name.s);

		if (new_dlg_profile( &name, PROFILE_HASH_SIZE, has_value)==NULL) {
			LM_ERR("failed to create new profile <%.*s>\n",name.len,name.s);
			return -1;
		}

	}while( (p=d)!=NULL );

	return 0;
}
Exemple #4
0
static int parse_week_days(const str *week_days, unsigned short *day_set)
{
	static const str str_days[] = {
		str_init("sun"), str_init("mon"), str_init("tue"), str_init("wed"),
		str_init("thu"), str_init("fri"), str_init("sat")
	};

	static const char interval_delim = '-';
	static const char list_delim = ',';

	if (week_days->len == 0)
		return 0;

	char *p = week_days->s, *np, *dash;
	int rem_len = week_days->len, token_len, i, j, n = 0;
	str t1, t2;

	do {
		np = q_memchr(p, list_delim, rem_len);
		token_len = np ? np - p : rem_len;
		rem_len -= token_len + 1;

		if (token_len < 3)
			goto parse_error;

		/* Now we see if it is an interval */
		dash = q_memchr(p, interval_delim, token_len);

		if (dash){
			/* It is an interval */
			t1.s = p;
			t1.len = dash - p;
			trim_spaces_lr(t1);

			t2.s = dash + 1;
			t2.len = token_len - t1.len - 1;
			trim_spaces_lr(t2);

			if (t1.len != 3 || t2.len != 3)
				goto parse_error;

			for (i = 0; i < 7; ++i)
				if (strcmp_case_insensitive(str_days[i].s, t1.s, 3) == 0)
					break;
			if (i == 7)
				goto parse_error;

			for (j = 0; j < 7; ++j)
				if (strcmp_case_insensitive(str_days[j].s, t2.s, 3) == 0)
					break;
			if (j == 7)
				goto parse_error;

			/* We increase the size of the days set */
			n += (j - i + 7) % 7 + 1;

			for (; i <= j; i = (i + 1) % 7)
				*day_set |= 1 << i;
		}
		else {
			/* Just one value */
			t1.s = p;
			t1.len = token_len;
			trim_spaces_lr(t1);

			if (t1.len != 3)
				goto parse_error;

			for (i = 0; i < 7; ++i)
				if (strcmp_case_insensitive(str_days[i].s, t1.s, 3) == 0)
					break;
			if (i == 7)
				goto parse_error;

			*day_set |= 1 << i;
			++n;
		}

		p = np + 1;
	} while (rem_len > 0);

	return n;

parse_error:
	LM_ERR("Cannot parse week day list <%.*s>", week_days->len, week_days->s);
	return -1;
}
Exemple #5
0
static int fixup_scriptroute_fetch(void **param, int param_no)
{
	char *end, *p, *e;
	str s, name;
	int index = 0;
	struct scriptroute_params *list = NULL;
	struct scriptroute_params *elem = NULL;
	struct scriptroute_params *next = NULL;


	if (param_no != 1) {
		LM_ERR("BUG: No such parameters %d\n", param_no);
		return E_BUG;
	}

	p = (char*)(*param);
	end = p + strlen(p);

	while (p < end) {
		name.s = 0;
		s.s = p;
		while (p < end && *p != ';')
			p++;

		// check if equal is found
		for (e = s.s; e < p && *e != '='; e++);
		// avoid old gcc versions warning
		name.len = 0;
		if (e == p) {
			s.len = e - s.s;
			trim_spaces_lr(s);
			if (s.len <= 0) {
				LM_WARN("No pvar specified near <%.*s>\n",
						(int)(p - s.s), s.s);
				goto next;
			}
			index++;
			name.s = 0;
			// the pvar is in s
		} else {
			name.s = s.s;
			name.len = e - s.s;
			trim_spaces_lr(name);
			if (name.len <= 0) {
				LM_WARN("No name specified near <%.*s>\n",
						(int)(p - s.s), s.s);
				goto next;
			}
			s.s = e + 1;
			s.len = p - s.s;
			trim_spaces_lr(s);
			if (s.len <= 0) {
				LM_WARN("No pvar specified near %.*s\n",
						(int)(p - s.s), s.s);
				goto next;
			}
		}
		elem = shm_malloc(sizeof(struct scriptroute_params));
		if (!elem) {
			LM_ERR("no more shm memory\n");
			return E_OUT_OF_MEM;
		}
		memset(elem, 0, sizeof(struct scriptroute_params));
		if (pv_parse_spec(&s, &elem->spec) < 0) {
			LM_ERR("cannot parse spec <%.*s>\n", s.len, s.s);
			shm_free(elem);
			goto error;
		}
		/* if name specified, use it - otherwise param index */
		if (name.s) {
			elem->name = name;
			LM_DBG("Parameter %.*s will be set in %.*s\n",
				   name.len, name.s, s.len, s.s);
		} else {
			elem->index = index;
			LM_DBG("Parameter %d will be set in %.*s\n", index,
				   s.len, s.s);
		}
		/* link it to parameters list */
		elem->next = list;
		list = elem;

next:
		p++;
	}

	*param = (void*)list;
	return 0;
error:
	for (elem = list; elem; elem = next) {
		next = elem->next;
		shm_free(elem);
	}
	return E_CFG;
}