本文整理汇总了C++中q_memchr函数的典型用法代码示例。如果您正苦于以下问题:C++ q_memchr函数的具体用法?C++ q_memchr怎么用?C++ q_memchr使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了q_memchr函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: parse_algo_hdr
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);
}
示例2: strtime
static int strtime(const str *time, int *ihrs, int *imin)
{
char *colon = q_memchr(time->s, FRD_TIME_SEP, time->len);
if (colon == NULL)
goto parse_error;
str hrs = {time->s, colon - time->s};
str min = {colon + 1, time->len - hrs.len - 1};
if (hrs.len == 0 || min.len == 0)
goto parse_error;
unsigned int uhrs, umin;
if (str2int(&hrs, &uhrs) || str2int(&min, &umin))
goto parse_error;
if (uhrs > 23 || umin >= 60)
goto parse_error;
*imin = umin;
*ihrs = uhrs;
return 0;
parse_error:
LM_ERR("cannot parse time-value <%.*s>", time->len, time->s);
return -1;
}
示例3: parse_cmd
static int parse_cmd(str* res, str* buffer)
{
char* cmd_end;
if (!res || !buffer) {
LOG(L_ERR, "parse_cmd: Invalid parameter value\n");
return -1;
}
if (buffer->len < 3) {
LOG(L_ERR, "parse_cmd: Message too short\n");
return -1;
}
if (buffer->s[0] != CMD_SEPARATOR) {
LOG(L_ERR, "parse_cmd: Command must start with %c\n",
CMD_SEPARATOR);
return -1;
}
cmd_end = q_memchr(buffer->s + 1, CMD_SEPARATOR, buffer->len - 1);
if (!cmd_end) {
LOG(L_ERR, "parse_cmd: Closing '%c' missing\n", CMD_SEPARATOR);
return -1;
}
res->s = buffer->s + 1;
res->len = cmd_end - res->s;
return 0;
}
示例4: select_nameaddr_uri
int select_nameaddr_uri(str* res, select_t* s, struct sip_msg* msg)
{
char *p;
p=find_not_quoted(res, '<');
if (!p) {
LM_DBG("no < found, string up to first semicolon is uri\n");
p = q_memchr(res->s, ';', res->len);
if (p)
res->len = p-res->s;
return 0;
}
res->len=res->len - (p-res->s) -1;
res->s=p +1;
p=find_not_quoted(res, '>');
if (!p) {
LM_ERR("no > found, invalid nameaddr value\n");
return -1;
}
res->len=p-res->s;
return 0;
}
示例5: do_acc_parse
static unsigned long long
do_acc_parse(str* in, do_acc_parser parser)
{
char* found=NULL;
str token;
unsigned long long fret=0, ret;
if (!in || !in->s || !in->len)
return -1;
do {
found=q_memchr(in->s, DO_ACC_PARAM_DELIMITER, in->len);
if (found) {
token.s = in->s;
token.len = found - in->s;
in->len -= (found - in->s) + 1;
in->s = found + 1;
} else {
token = *in;
}
if ((ret=parser(&token)) < 0) {
LM_ERR("Invalid token <%.*s>!\n", token.len, token.s);
return -1;
}
fret |= ret;
} while(found);
return fret;
}
示例6: parse_quoted
/*
* Parse quoted string in a parameter body
* return the string without quotes in r
* parameter and update s to point behind the
* closing quote
*/
static inline int parse_quoted(str* s, str* r)
{
char* end_quote;
/* The string must have at least surrounding quotes */
if (s->len < 2)
return -1;
/* Skip opening quote */
s->s++;
s->len--;
/* Find closing quote */
end_quote = q_memchr(s->s, '\"', s->len);
/* Not found, return error */
if (!end_quote)
return -2;
/* Let r point to the string without surrounding quotes */
r->s = s->s;
r->len = end_quote - s->s;
/* Update s parameter to point behind the closing quote */
s->len -= (end_quote - s->s + 1);
s->s = end_quote + 1;
/* Everything went OK */
return 0;
}
示例7: extract_node_list
/**
* extract the node list from the body of a notification request SIP message
* the SIP request will look something like:
* KDMQ sip:10.0.0.0:5062
* To: ...
* From: ...
* Max-Forwards: ...
* Content-Length: 22
*
* sip:host1:port1;param1=value1
* sip:host2:port2;param2=value2
* ...
*/
int extract_node_list(dmq_node_list_t* update_list, struct sip_msg* msg)
{
int content_length, total_nodes = 0;
str body;
str tmp_uri;
dmq_node_t *cur = NULL;
char *tmp, *end, *match;
if(!msg->content_length) {
LM_ERR("no content length header found\n");
return -1;
}
content_length = get_content_length(msg);
if(!content_length) {
LM_DBG("content length is 0\n");
return total_nodes;
}
body.s = get_body(msg);
body.len = content_length;
tmp = body.s;
end = body.s + body.len;
/* acquire big list lock */
lock_get(&update_list->lock);
while(tmp < end) {
match = q_memchr(tmp, '\n', end - tmp);
if(match) {
match++;
} else {
/* for the last line - take all of it */
match = end;
}
/* create the orig_uri from the parsed uri line and trim it */
tmp_uri.s = tmp;
tmp_uri.len = match - tmp - 1;
tmp = match;
/* trim the \r, \n and \0's */
trim_r(tmp_uri);
if(!find_dmq_node_uri(update_list, &tmp_uri)) {
LM_DBG("found new node %.*s\n", STR_FMT(&tmp_uri));
cur = build_dmq_node(&tmp_uri, 1);
if(!cur) {
LM_ERR("error creating new dmq node\n");
goto error;
}
cur->next = update_list->nodes;
update_list->nodes = cur;
update_list->count++;
total_nodes++;
}
}
/* release big list lock */
lock_release(&update_list->lock);
return total_nodes;
error:
lock_release(&update_list->lock);
return -1;
}
示例8: q_memchr
/*
* Returns the class part of the URI
*/
str *parseurl(const str* url) {
static str cn;
cn.s = q_memchr(url->s,':',url->len);
if (cn.s && ((cn.s+1)<(url->s+url->len)) ) {
cn.s++;
cn.len = url->len - (cn.s-url->s);
return &cn;
}
return NULL;
}
示例9: mk_net_str
/** initializes a net structure from a string.
* @param dst - net structure that will be filled
* @param s - string of the form "ip", "ip/mask_len" or "ip/ip_mak".
* @return -1 on error, 0 on succes
*/
int mk_net_str(struct net* dst, str* s)
{
struct ip_addr* t;
char* p;
struct ip_addr ip;
str addr;
str mask;
unsigned int bitlen;
/* test for ip only */
t = str2ip(s);
if (unlikely(t == 0))
t = str2ip6(s);
if (likely(t))
return mk_net_bitlen(dst, t, t->len*8);
/* not a simple ip, maybe an ip/netmask pair */
p = q_memchr(s->s, '/', s->len);
if (likely(p)) {
addr.s = s->s;
addr.len = (int)(long)(p - s->s);
mask.s = p + 1;
mask.len = s->len - (addr.len + 1);
/* allow '/' enclosed by whitespace */
trim_trailing(&addr);
trim_leading(&mask);
t = str2ip(&addr);
if (likely(t)) {
/* it can be a number */
if (str2int(&mask, &bitlen) == 0)
return mk_net_bitlen(dst, t, bitlen);
ip = *t;
t = str2ip(&mask);
if (likely(t))
return mk_net(dst, &ip, t);
/* error */
return -1;
}
else {
t = str2ip6(&addr);
if (likely(t)) {
/* it can be a number */
if (str2int(&mask, &bitlen) == 0)
return mk_net_bitlen(dst, t, bitlen);
ip = *t;
t = str2ip6(&mask);
if (likely(t))
return mk_net(dst, &ip, t);
/* error */
return -1;
}
}
}
return -1;
}
示例10: check_ftag
static int check_ftag(struct sip_msg* msg, str* uri)
{
param_hooks_t hooks;
param_t* params;
char* semi;
struct to_body* from;
str t;
t = *uri;
params = 0;
semi = q_memchr(t.s, ';', t.len);
if (!semi) {
DBG("No ftag parameter found\n");
return -1;
}
t.len -= semi - uri->s + 1;
t.s = semi + 1;
trim_leading(&t);
if (parse_params(&t, CLASS_URI, &hooks, ¶ms) < 0) {
ERR("Error while parsing parameters\n");
return -1;
}
if (!hooks.uri.ftag) {
DBG("No ftag parameter found\n");
goto err;
}
from = get_from(msg);
if (!from || !from->tag_value.len || !from->tag_value.s) {
DBG("No from tag parameter found\n");
goto err;
}
if (from->tag_value.len == hooks.uri.ftag->body.len &&
!strncmp(from->tag_value.s, hooks.uri.ftag->body.s, hooks.uri.ftag->body.len)) {
DBG("Route ftag and From tag are same\n");
free_params(params);
return 0;
} else {
DBG("Route ftag and From tag are NOT same\n");
free_params(params);
return 1;
}
err:
if (params) free_params(params);
return -1;
}
示例11: eat_line
/** @brief returns pointer to next line or after the end of buffer */
char* eat_line(char* buffer, unsigned int len)
{
char* nl;
/* jku .. replace for search with a library function; not conforming
as I do not care about CR
*/
nl=(char *)q_memchr( buffer, '\n', len );
if ( nl ) {
if ( nl + 1 < buffer+len) nl++;
if (( nl+1<buffer+len) && * nl=='\r') nl++;
} else nl=buffer+len;
return nl;
}
示例12: parse_username
/*
* Parse username for user and domain parts
*/
static inline void parse_username(struct username* u)
{
char* d;
u->user = u->whole;
if (u->whole.len <= 2)
return;
d = q_memchr(u->whole.s, '@', u->whole.len);
if (d)
{
u->domain.s = d + 1;
u->domain.len = u->whole.len - (d - u->whole.s) - 1;
u->user.len = d - u->user.s;
}
}
示例13: parse_quoted_param
/*! \brief
* Parse quoted string in a parameter body
* return the string without quotes in _r
* parameter and update _s to point behind the
* closing quote
*/
static inline int parse_quoted_param(str *_s, str *_r)
{
char *end_quote;
char quote;
/* The string must have at least
* surrounding quotes
*/
if(_s->len < 2) {
return -1;
}
/* Store the kind of quoting (single or double)
* which we're handling with
*/
quote = (_s->s)[0];
/* Skip opening quote */
_s->s++;
_s->len--;
/* Find closing quote */
end_quote = q_memchr(_s->s, quote, _s->len);
/* Not found, return error */
if(!end_quote) {
return -2;
}
/* Let _r point to the string without
* surrounding quotes
*/
_r->s = _s->s;
_r->len = end_quote - _s->s;
/* Update _s parameter to point
* behind the closing quote
*/
_s->len -= (end_quote - _s->s + 1);
_s->s = end_quote + 1;
/* Everything went OK */
return 0;
}
示例14: parse_param_name
int parse_param_name(str* _s, dig_par_t* _type)
{
register char* p;
register int val;
char* end;
end = _s->s + _s->len;
p = _s->s;
val = READ(p);
if (_s->len < 4) {
goto other;
}
switch(LOWER_DWORD(val)) {
FIRST_QUATERNIONS;
default:
PARSE_SHORT;
goto other;
}
end:
_s->len -= p - _s->s;
_s->s = p;
trim_leading(_s);
if (_s->s[0] == '=') {
return 0;
}
other:
p = q_memchr(p, '=', end - p);
if (!p) {
return -1; /* Parse error */
} else {
*_type = PAR_OTHER;
_s->len -= p - _s->s;
_s->s = p;
return 0;
}
}
示例15: db_delete_ucontact
/*
* Delete contact from the database
*/
int db_delete_ucontact(ucontact_t* _c)
{
char b[256];
char* dom;
db_key_t keys[3];
db_val_t vals[3];
keys[0] = user_col;
keys[1] = contact_col;
keys[2] = domain_col;
vals[0].type = DB_STR;
vals[0].nul = 0;
vals[0].val.str_val = *_c->aor;
vals[1].type = DB_STR;
vals[1].nul = 0;
vals[1].val.str_val = _c->c;
if (use_domain) {
dom = q_memchr(_c->aor->s, '@', _c->aor->len);
vals[0].val.str_val.len = dom - _c->aor->s;
vals[2].type = DB_STR;
vals[2].nul = 0;
vals[2].val.str_val.s = dom + 1;
vals[2].val.str_val.len = _c->aor->s + _c->aor->len - dom - 1;
}
/* FIXME */
memcpy(b, _c->domain->s, _c->domain->len);
b[_c->domain->len] = '\0';
db_use_table(db, b);
if (db_delete(db, keys, 0, vals, (use_domain) ? (3) : (2)) < 0) {
LOG(L_ERR, "db_del_ucontact(): Error while deleting from database\n");
return -1;
}
return 0;
}