static int phone_call(struct ast_channel *ast, char *dest, int timeout) { struct phone_pvt *p; PHONE_CID cid; time_t UtcTime; struct tm tm; time(&UtcTime); localtime_r(&UtcTime,&tm); memset(&cid, 0, sizeof(PHONE_CID)); if(&tm != NULL) { snprintf(cid.month, sizeof(cid.month), "%02d",(tm.tm_mon + 1)); snprintf(cid.day, sizeof(cid.day), "%02d", tm.tm_mday); snprintf(cid.hour, sizeof(cid.hour), "%02d", tm.tm_hour); snprintf(cid.min, sizeof(cid.min), "%02d", tm.tm_min); } /* the standard format of ast->callerid is: "name" <number>, but not always complete */ if (!ast->callerid || ast_strlen_zero(ast->callerid)){ strncpy(cid.name, DEFAULT_CALLER_ID, sizeof(cid.name) - 1); cid.number[0]='\0'; } else { char *n, *l; char callerid[256] = ""; strncpy(callerid, ast->callerid, sizeof(callerid) - 1); ast_callerid_parse(callerid, &n, &l); if (l) { ast_shrink_phone_number(l); if (!ast_isphonenumber(l)) l = NULL; } if (l) strncpy(cid.number, l, sizeof(cid.number) - 1); if (n) strncpy(cid.name, n, sizeof(cid.name) - 1); } p = ast->pvt->pvt; if ((ast->_state != AST_STATE_DOWN) && (ast->_state != AST_STATE_RESERVED)) { ast_log(LOG_WARNING, "phone_call called on %s, neither down nor reserved\n", ast->name); return -1; } if (option_debug) ast_log(LOG_DEBUG, "Ringing %s on %s (%d)\n", dest, ast->name, ast->fds[0]); IXJ_PHONE_RING_START(cid); ast_setstate(ast, AST_STATE_RINGING); ast_queue_control(ast, AST_CONTROL_RINGING); return 0; }
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; }
int ast_callerid_parse(char *input_str, char **name, char **location) { char *ls; char *le; char *name_start; char *instr; int quotes_stripped = 0; /* Handle surrounding quotes */ input_str = ast_strip(input_str); instr = ast_strip_quoted(input_str, "\"", "\""); if (instr != input_str) { quotes_stripped = 1; } /* Try "name" <location> format or name <location> format or with a missing > */ if ((ls = strrchr(instr, '<'))) { if ((le = strrchr(ls, '>'))) { *le = '\0'; /* location found, trim off the brackets */ } *ls = '\0'; *location = ls + 1; /* and this is the result */ name_start = ast_strip_quoted(instr, "\"", "\""); } else { /* no valid brackets */ char tmp[256]; ast_copy_string(tmp, instr, sizeof(tmp)); ast_shrink_phone_number(tmp); if (!quotes_stripped && ast_isphonenumber(tmp)) { /* Assume it's just a location */ name_start = 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; name_start = ast_strip_quoted(instr, "\"", "\""); } } if (name_start) { ast_unescape_quoted(name_start); } *name = name_start; return 0; }