int ast_callerid_parse(char *instr, char **name, char **location) { char *ns, *ne, *ls, *le; /* Try "name" <location> format or name <location> format */ if ((ls = strrchr(instr, '<')) && (le = strrchr(ls, '>'))) { *ls = *le = '\0'; /* location found, trim off the brackets */ *location = ls + 1; /* and this is the result */ if ((ns = strchr(instr, '"')) && (ne = strchr(ns + 1, '"'))) { *ns = *ne = '\0'; /* trim off the quotes */ *name = ns + 1; /* and this is the name */ } else if (ns) { /* An opening quote was found but no closing quote was. The closing * quote may actually be after the end of the bracketed number */ if (strchr(le + 1, '\"')) { *ns = '\0'; *name = ns + 1; ast_trim_blanks(*name); } else { *name = NULL; } } else { /* no quotes, trim off leading and trailing spaces */ *name = ast_skip_blanks(instr); ast_trim_blanks(*name); } } else { /* no valid brackets */ char tmp[256]; ast_copy_string(tmp, instr, sizeof(tmp)); ast_shrink_phone_number(tmp); if (ast_isphonenumber(tmp)) { /* Assume it's just a location */ *name = NULL; strcpy(instr, tmp); /* safe, because tmp will always be the same size or smaller than instr */ *location = instr; } else { /* Assume it's just a name. */ *location = NULL; if ((ns = strchr(instr, '"')) && (ne = strchr(ns + 1, '"'))) { *ns = *ne = '\0'; /* trim off the quotes */ *name = ns + 1; /* and this is the name */ } else { /* no quotes, trim off leading and trailing spaces */ *name = ast_skip_blanks(instr); ast_trim_blanks(*name); } } } return 0; }
static int user_event_hook_cb(int category, const char *event, char *body) { char *parse; char *kvp; if (strcmp(event, "UserEvent")) { return -1; } parse = ast_strdupa(body); while ((kvp = strsep(&parse, "\r\n"))) { char *key, *value; kvp = ast_trim_blanks(kvp); if (ast_strlen_zero(kvp)) { continue; } key = strsep(&kvp, ":"); value = ast_skip_blanks(kvp); verify_user_event_fields(received_user_events, key, value); } received_user_events++; ast_mutex_lock(&user_event_lock); if (received_user_events == expected_user_events) { ast_cond_signal(&user_event_cond); } ast_mutex_unlock(&user_event_lock); return 0; }
/*! * \internal \brief The cURL header callback function */ static size_t curl_header_callback(char *buffer, size_t size, size_t nitems, void *data) { struct curl_bucket_file_data *cb_data = data; size_t realsize; char *value; char *header; realsize = size * nitems; if (realsize > MAX_HEADER_LENGTH) { ast_log(LOG_WARNING, "cURL header length of '%zu' is too large: max %d\n", realsize, MAX_HEADER_LENGTH); return 0; } /* buffer may not be NULL terminated */ header = ast_alloca(realsize + 1); memcpy(header, buffer, realsize); header[realsize] = '\0'; value = strchr(header, ':'); if (!value) { /* Not a header we care about; bail */ return realsize; } *value++ = '\0'; if (strcasecmp(header, "ETag") && strcasecmp(header, "Cache-Control") && strcasecmp(header, "Last-Modified") && strcasecmp(header, "Content-Type") && strcasecmp(header, "Expires")) { return realsize; } value = ast_trim_blanks(ast_skip_blanks(value)); header = ast_str_to_lower(header); ast_bucket_file_metadata_set(cb_data->bucket_file, header, value); return realsize; }
/*! \brief * the string is 'prefix:data' or prefix:fmt:data' * with ':' being invalid in strings. */ static int do_say(say_args_t *a, const char *s, const char *options, int depth) { struct ast_variable *v; char *lang, *x, *rule = NULL; int ret = 0; struct varshead head = { .first = NULL, .last = NULL }; struct ast_var_t *n; ast_debug(2, "string <%s> depth <%d>\n", s, depth); if (depth++ > 10) { ast_log(LOG_WARNING, "recursion too deep, exiting\n"); return -1; } else if (!say_cfg) { ast_log(LOG_WARNING, "no say.conf, cannot spell '%s'\n", s); return -1; } /* scan languages same as in file.c */ if (a->language == NULL) a->language = "en"; /* default */ ast_debug(2, "try <%s> in <%s>\n", s, a->language); lang = ast_strdupa(a->language); for (;;) { for (v = ast_variable_browse(say_cfg, lang); v ; v = v->next) { if (ast_extension_match(v->name, s)) { rule = ast_strdupa(v->value); break; } } if (rule) break; if ( (x = strchr(lang, '_')) ) *x = '\0'; /* try without suffix */ else if (strcmp(lang, "en")) lang = "en"; /* last resort, try 'en' if not done yet */ else break; } if (!rule) return 0; /* skip up to two prefixes to get the value */ if ( (x = strchr(s, ':')) ) s = x + 1; if ( (x = strchr(s, ':')) ) s = x + 1; ast_debug(2, "value is <%s>\n", s); n = ast_var_assign("SAY", s); if (!n) { ast_log(LOG_ERROR, "Memory allocation error in do_say\n"); return -1; } AST_LIST_INSERT_HEAD(&head, n, entries); /* scan the body, one piece at a time */ while ( !ret && (x = strsep(&rule, ",")) ) { /* exit on key */ char fn[128]; const char *p, *fmt, *data; /* format and data pointers */ /* prepare a decent file name */ x = ast_skip_blanks(x); ast_trim_blanks(x); /* replace variables */ pbx_substitute_variables_varshead(&head, x, fn, sizeof(fn)); ast_debug(2, "doing [%s]\n", fn); /* locate prefix and data, if any */ fmt = strchr(fn, ':'); if (!fmt || fmt == fn) { /* regular filename */ ret = s_streamwait3(a, fn); continue; } fmt++; data = strchr(fmt, ':'); /* colon before data */ if (!data || data == fmt) { /* simple prefix-fmt */ ret = do_say(a, fn, options, depth); continue; } /* prefix:fmt:data */ for (p = fmt; p < data && ret <= 0; p++) { char fn2[sizeof(fn)]; if (*p == ' ' || *p == '\t') /* skip blanks */ continue; if (*p == '\'') {/* file name - we trim them */ char *y; strcpy(fn2, ast_skip_blanks(p+1)); /* make a full copy */ y = strchr(fn2, '\''); if (!y) { p = data; /* invalid. prepare to end */ break; } *y = '\0'; ast_trim_blanks(fn2); p = strchr(p+1, '\''); ret = s_streamwait3(a, fn2); } else { int l = fmt-fn; strcpy(fn2, fn); /* copy everything */ /* after prefix, append the format */ fn2[l++] = *p; strcpy(fn2 + l, data); ret = do_say(a, fn2, options, depth); } if (ret) { break; } } } ast_var_delete(n); return ret; }