static int database_del(int fd, int argc, char *argv[]) { int res; if (argc != 4) return RESULT_SHOWUSAGE; res = cw_db_del(argv[2], argv[3]); if (res) { cw_cli(fd, "Database entry does not exist.\n"); } else { cw_cli(fd, "Database entry removed.\n"); } return RESULT_SUCCESS; }
static int database_put(int fd, int argc, char *argv[]) { int res; if (argc != 5) return RESULT_SHOWUSAGE; res = cw_db_put(argv[2], argv[3], argv[4]); if (res) { cw_cli(fd, "Failed to update entry\n"); } else { cw_cli(fd, "Updated database successfully\n"); } return RESULT_SUCCESS; }
static int database_get(int fd, int argc, char *argv[]) { int res; char tmp[256]; if (argc != 4) return RESULT_SHOWUSAGE; res = cw_db_get(argv[2], argv[3], tmp, sizeof(tmp)); if (res) { cw_cli(fd, "Database entry not found.\n"); } else { cw_cli(fd, "Value: %s\n", tmp); } return RESULT_SUCCESS; }
static int database_deltree(int fd, int argc, char *argv[]) { int res; if ((argc < 3) || (argc > 4)) return RESULT_SHOWUSAGE; if (argc == 4) { res = cw_db_deltree(argv[2], argv[3]); } else { res = cw_db_deltree(argv[2], NULL); } if (res) { cw_cli(fd, "Database entries do not exist.\n"); } else { cw_cli(fd, "Database entries removed.\n"); } return RESULT_SUCCESS; }
static int show_callback(void *pArg, int argc, char **argv, char **columnNames) { int *fdp = pArg; int fd = *fdp; cw_cli(fd, "/%s/%-50s: %-25s\n", argv[0], argv[1], argv[2]); return 0; }
static int show_keys(int fd, int argc, char *argv[]) { struct cw_key *key; char sum[16 * 2 + 1]; int count_keys = 0; cw_mutex_lock(&keylock); key = keys; cw_cli(fd, "%-18s %-8s %-16s %-33s\n", "Key Name", "Type", "Status", "Sum"); while(key) { cw_hash_to_hex(sum, key->md_value, key->md_len); cw_cli(fd, "%-18s %-8s %-16s %-33s\n", key->name, (key->ktype & 0xf) == CW_KEY_PUBLIC ? "PUBLIC" : "PRIVATE", key->ktype & KEY_NEEDS_PASSCODE ? "[Needs Passcode]" : "[Loaded]", sum); key = key->next; count_keys++; } cw_mutex_unlock(&keylock); cw_cli(fd, "%d known RSA keys.\n", count_keys); return RESULT_SUCCESS; }
static int originate_cli(int fd, int argc, char *argv[]) { char *chan_name_1,*context,*exten,*tech,*data,*callerid; int pri=0,to=60000; struct fast_originate_helper *in; pthread_t thread; pthread_attr_t attr; int result; char *num = NULL; if(argc < 3) { cw_cli(fd,USAGE); return -1; } chan_name_1 = argv[1]; exten = cw_strdupa(argv[2]); if((context = strchr(exten,'@'))) { *context = 0; context++; } if(! (context && exten)) { cw_cli(fd,CGUSAGE); return -1; } pri = argv[3] ? atoi(argv[3]) : 1; if(!pri) pri = 1; tech = cw_strdupa(chan_name_1); if((data = strchr(tech,'/'))) { *data = '\0'; data++; } if(!(tech && data)) { cw_cli(fd,USAGE); return -1; } in = malloc(sizeof(struct fast_originate_helper)); if(!in) { cw_cli(fd,"No Memory!\n"); return -1; } memset(in,0,sizeof(struct fast_originate_helper)); callerid = (argc > 4) ? argv[4] : NULL; to = (argc > 5) ? atoi(argv[5]) : 60000; strncpy(in->tech,tech,sizeof(in->tech)); strncpy(in->data,data,sizeof(in->data)); in->timeout=to; if(callerid) { if((num = strchr(callerid,':'))) { *num = '\0'; num++; strncpy(in->cid_num,num,sizeof(in->cid_num)); } strncpy(in->cid_name,callerid,sizeof(in->cid_name)); } strncpy(in->context,context,sizeof(in->context)); strncpy(in->exten,exten,sizeof(in->exten)); in->priority = pri; cw_cli(fd,"Originating Call %s/%s %s %s %d\n",in->tech,in->data,in->context,in->exten,in->priority); result = pthread_attr_init(&attr); pthread_attr_setschedpolicy(&attr, SCHED_RR); pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); result = cw_pthread_create(&thread, &attr,originate,in); result = pthread_attr_destroy(&attr); return 0; }
static int changrab_cli(int fd, int argc, char *argv[]) { char *chan_name_1, *chan_name_2 = NULL, *context,*exten,*flags=NULL; char *pria = NULL; struct cw_channel *xferchan_1, *xferchan_2; int pri=0,x=1; if(argc < 3) { cw_cli(fd,CGUSAGE); return -1; } chan_name_1 = argv[x++]; if(chan_name_1[0] == '-') { flags = cw_strdupa(chan_name_1); if (strchr(flags,'h')) { chan_name_1 = argv[x++]; if((xferchan_1 = my_cw_get_channel_by_name_locked(chan_name_1))) { cw_mutex_unlock(&xferchan_1->lock); cw_hangup(xferchan_1); cw_verbose("OK, good luck!\n"); return 0; } else return -1; } else if (strchr(flags,'m') || strchr(flags,'M')) { chan_name_1 = argv[x++]; if((xferchan_1 = my_cw_get_channel_by_name_locked(chan_name_1))) { cw_mutex_unlock(&xferchan_1->lock); strchr(flags,'m') ? cw_moh_start(xferchan_1,NULL) : cw_moh_stop(xferchan_1); } else return 1; return 0; } if(argc < 4) { cw_cli(fd,CGUSAGE); return -1; } chan_name_1 = argv[x++]; } exten = cw_strdupa(argv[x++]); if((context = strchr(exten,'@'))) { *context = 0; context++; if(!(context && exten)) { cw_cli(fd,CGUSAGE); return -1; } if((pria = strchr(context,':'))) { *pria = '\0'; pria++; pri = atoi(pria); } else { pri = argv[x] ? atoi(argv[x++]) : 1; } if(!pri) pri = 1; } else if (strchr(exten,'/')) { chan_name_2 = exten; } xferchan_1 = my_cw_get_channel_by_name_locked(chan_name_1); if(!xferchan_1) { cw_log(LOG_WARNING, "No Such Channel: %s\n",chan_name_1); return -1; } cw_mutex_unlock(&xferchan_1->lock); if(flags && strchr(flags,'b')) { if(cw_bridged_channel(xferchan_1)) { xferchan_1 = cw_bridged_channel(xferchan_1); } } if(chan_name_2) { struct cw_frame *f; struct cw_channel *newchan_1, *newchan_2; if (!(newchan_1 = cw_channel_alloc(0))) { cw_log(LOG_WARNING, "Memory Error!\n"); cw_hangup(newchan_1); return -1; } else { snprintf(newchan_1->name, sizeof (newchan_1->name), "ChanGrab/%s", xferchan_1->name); newchan_1->readformat = xferchan_1->readformat; newchan_1->writeformat = xferchan_1->writeformat; cw_channel_masquerade(newchan_1, xferchan_1); if ((f = cw_read(newchan_1))) { cw_fr_free(f); } else { cw_hangup(newchan_1); return -1; } } if(!(xferchan_2 = my_cw_get_channel_by_name_locked(chan_name_2))) { cw_log(LOG_WARNING, "No Such Channel: %s\n",chan_name_2); cw_hangup(newchan_1); return -1; } cw_mutex_unlock(&xferchan_2->lock); if(flags && strchr(flags, 'B')) { if(cw_bridged_channel(xferchan_2)) { xferchan_2 = cw_bridged_channel(xferchan_2); } } if(!(newchan_2 = cw_channel_alloc(0))) { cw_log(LOG_WARNING, "Memory Error!\n"); cw_hangup(newchan_1); return -1; } else { snprintf(newchan_2->name, sizeof (newchan_2->name), "ChanGrab/%s", xferchan_2->name); newchan_2->readformat = xferchan_2->readformat; newchan_2->writeformat = xferchan_2->writeformat; cw_channel_masquerade(newchan_2, xferchan_2); if ((f = cw_read(newchan_2))) { cw_fr_free(f); } else { cw_hangup(newchan_1); cw_hangup(newchan_2); return -1; } } cw_bridge_call_thread_launch(newchan_1, newchan_2); } else { cw_verbose("Transferring_to context %s, extension %s, priority %d\n", context, exten, pri); cw_async_goto(xferchan_1, context, exten, pri); if(xferchan_1) cw_mutex_unlock(&xferchan_1->lock); } return 0; }
static int show_osp(int fd, int argc, char *argv[]) { struct osp_provider *osp; char *search = NULL; int x; int found = 0; char *tokenalgo; if ((argc < 2) || (argc > 3)) return RESULT_SHOWUSAGE; if (argc > 2) search = argv[2]; if (!search) { switch (tokenformat) { case TOKEN_ALGO_BOTH: tokenalgo = "Both"; break; case TOKEN_ALGO_UNSIGNED: tokenalgo = "Unsigned"; break; case TOKEN_ALGO_SIGNED: default: tokenalgo = "Signed"; break; } cw_cli(fd, "OSP: %s %s %s\n", initialized ? "Initialized" : "Uninitialized", hardware ? "Accelerated" : "Normal", tokenalgo); } cw_mutex_lock(&osplock); osp = providers; while(osp) { if (!search || !strcasecmp(osp->name, search)) { if (found) cw_cli(fd, "\n"); cw_cli(fd, " == OSP Provider '%s' ==\n", osp->name); cw_cli(fd, "Local Private Key: %s\n", osp->localpvtkey); cw_cli(fd, "Local Certificate: %s\n", osp->localcert); for (x=0;x<osp->cacount;x++) cw_cli(fd, "CA Certificate %d: %s\n", x + 1, osp->cacerts[x]); for (x=0;x<osp->spcount;x++) cw_cli(fd, "Service Point %d: %s\n", x + 1, osp->servicepoints[x]); cw_cli(fd, "Max Connections: %d\n", osp->maxconnections); cw_cli(fd, "Retry Delay: %d seconds\n", osp->retrydelay); cw_cli(fd, "Retry Limit: %d\n", osp->retrylimit); cw_cli(fd, "Timeout: %d milliseconds\n", osp->timeout); cw_cli(fd, "Source: %s\n", strlen(osp->source) ? osp->source : "<unspecified>"); cw_cli(fd, "OSP Handle: %d\n", osp->handle); found++; } osp = osp->next; } cw_mutex_unlock(&osplock); if (!found) { if (search) cw_cli(fd, "Unable to find OSP provider '%s'\n", search); else cw_cli(fd, "No OSP providers configured\n"); } return RESULT_SUCCESS; }