static int write_metadata( FILE *logfile, char *signalling_type, struct ast_channel *chan) { int res = 0; time_t t; struct tm now; char *cl,*cn; char workstring[80]; char timestamp[80]; /* Extract the caller ID location */ if (chan->cid.cid_num) ast_copy_string(workstring, chan->cid.cid_num, sizeof(workstring)); workstring[sizeof(workstring) - 1] = '\0'; ast_callerid_parse(workstring, &cn, &cl); if (cl) ast_shrink_phone_number(cl); /* Get the current time */ time(&t); ast_localtime(&t, &now, NULL); /* Format the time */ strftime(timestamp, sizeof(timestamp), time_stamp_format, &now); res = fprintf(logfile, "\n\n[metadata]\n\n"); if(res >= 0) res = fprintf(logfile, "PROTOCOL=%s\n", signalling_type); if(res >= 0) res = fprintf(logfile, "CALLINGFROM=%s\n", (!cl) ? "<unknown>" : cl); if(res >- 0) res = fprintf(logfile, "CALLERNAME=%s\n", (!cn) ? "<unknown>" : cn); if(res >= 0) res = fprintf(logfile, "TIMESTAMP=%s\n\n", timestamp); if(res >= 0) res = fprintf(logfile, "[events]\n\n"); if(res < 0){ ast_verbose(VERBOSE_PREFIX_4 "AlarmReceiver: can't write metadata\n"); ast_log(LOG_DEBUG,"AlarmReceiver: can't write metadata\n"); } else res = 0; return res; }
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_split(const char *buf, char *name, int namelen, char *num, int numlen) { char *tmp; char *l = NULL, *n = NULL; tmp = ast_strdupa(buf); ast_callerid_parse(tmp, &n, &l); if (n) ast_copy_string(name, n, namelen); else name[0] = '\0'; if (l) { ast_shrink_phone_number(l); ast_copy_string(num, l, numlen); } else num[0] = '\0'; return 0; }
void ast_ari_channels_originate(struct ast_variable *headers, struct ast_ari_channels_originate_args *args, struct ast_ari_response *response) { char *dialtech; char dialdevice[AST_CHANNEL_NAME]; char *caller_id = NULL; char *cid_num = NULL; char *cid_name = NULL; int timeout = 30000; char *stuff; struct ast_channel *chan; RAII_VAR(struct ast_channel_snapshot *, snapshot, NULL, ao2_cleanup); if (ast_strlen_zero(args->endpoint)) { ast_ari_response_error(response, 400, "Bad Request", "Endpoint must be specified"); return; } dialtech = ast_strdupa(args->endpoint); if ((stuff = strchr(dialtech, '/'))) { *stuff++ = '\0'; ast_copy_string(dialdevice, stuff, sizeof(dialdevice)); } if (ast_strlen_zero(dialtech) || ast_strlen_zero(dialdevice)) { ast_ari_response_error(response, 400, "Bad Request", "Invalid endpoint specified"); return; } if (args->timeout > 0) { timeout = args->timeout * 1000; } else if (args->timeout == -1) { timeout = -1; } if (!ast_strlen_zero(args->caller_id)) { caller_id = ast_strdupa(args->caller_id); ast_callerid_parse(caller_id, &cid_name, &cid_num); if (ast_is_shrinkable_phonenumber(cid_num)) { ast_shrink_phone_number(cid_num); } } if (!ast_strlen_zero(args->app)) { const char *app = "Stasis"; RAII_VAR(struct ast_str *, appdata, ast_str_create(64), ast_free); if (!appdata) { ast_ari_response_alloc_failed(response); return; } ast_str_set(&appdata, 0, "%s", args->app); if (!ast_strlen_zero(args->app_args)) { ast_str_append(&appdata, 0, ",%s", args->app_args); } /* originate a channel, putting it into an application */ if (ast_pbx_outgoing_app(dialtech, NULL, dialdevice, timeout, app, ast_str_buffer(appdata), NULL, 0, cid_num, cid_name, NULL, NULL, &chan)) { ast_ari_response_alloc_failed(response); return; } } else if (!ast_strlen_zero(args->extension)) {
static void ari_channels_handle_originate_with_id(const char *args_endpoint, const char *args_extension, const char *args_context, long args_priority, const char *args_app, const char *args_app_args, const char *args_caller_id, int args_timeout, struct ast_variable *variables, const char *args_channel_id, const char *args_other_channel_id, struct ast_ari_response *response) { char *dialtech; char dialdevice[AST_CHANNEL_NAME]; char *caller_id = NULL; char *cid_num = NULL; char *cid_name = NULL; int timeout = 30000; RAII_VAR(struct ast_format_cap *, cap, ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_NOLOCK), ast_format_cap_destroy); struct ast_format tmp_fmt; char *stuff; struct ast_channel *chan; RAII_VAR(struct ast_channel_snapshot *, snapshot, NULL, ao2_cleanup); struct ast_assigned_ids assignedids = { .uniqueid = args_channel_id, .uniqueid2 = args_other_channel_id, }; if (!cap) { ast_ari_response_alloc_failed(response); return; } ast_format_cap_add(cap, ast_format_set(&tmp_fmt, AST_FORMAT_SLINEAR, 0)); if ((assignedids.uniqueid && AST_MAX_PUBLIC_UNIQUEID < strlen(assignedids.uniqueid)) || (assignedids.uniqueid2 && AST_MAX_PUBLIC_UNIQUEID < strlen(assignedids.uniqueid2))) { ast_ari_response_error(response, 400, "Bad Request", "Uniqueid length exceeds maximum of %d\n", AST_MAX_PUBLIC_UNIQUEID); return; } if (ast_strlen_zero(args_endpoint)) { ast_ari_response_error(response, 400, "Bad Request", "Endpoint must be specified"); return; } dialtech = ast_strdupa(args_endpoint); if ((stuff = strchr(dialtech, '/'))) { *stuff++ = '\0'; ast_copy_string(dialdevice, stuff, sizeof(dialdevice)); } if (ast_strlen_zero(dialtech) || ast_strlen_zero(dialdevice)) { ast_ari_response_error(response, 400, "Bad Request", "Invalid endpoint specified"); return; } if (args_timeout > 0) { timeout = args_timeout * 1000; } else if (args_timeout == -1) { timeout = -1; } if (!ast_strlen_zero(args_caller_id)) { caller_id = ast_strdupa(args_caller_id); ast_callerid_parse(caller_id, &cid_name, &cid_num); if (ast_is_shrinkable_phonenumber(cid_num)) { ast_shrink_phone_number(cid_num); } } if (!ast_strlen_zero(args_app)) { const char *app = "Stasis"; RAII_VAR(struct ast_str *, appdata, ast_str_create(64), ast_free); if (!appdata) { ast_ari_response_alloc_failed(response); return; } ast_str_set(&appdata, 0, "%s", args_app); if (!ast_strlen_zero(args_app_args)) { ast_str_append(&appdata, 0, ",%s", args_app_args); } /* originate a channel, putting it into an application */ if (ast_pbx_outgoing_app(dialtech, cap, dialdevice, timeout, app, ast_str_buffer(appdata), NULL, 0, cid_num, cid_name, variables, NULL, &chan, &assignedids)) { ast_ari_response_alloc_failed(response); return; } } else if (!ast_strlen_zero(args_extension)) {