static int control_stream_parse(struct control_stream *s, char *line) { int ovec[60]; int ret; char **out; struct control_tcp *c = s->control; str *output = NULL; ret = pcre_exec(c->parse_re, c->parse_ree, line, strlen(line), 0, 0, ovec, G_N_ELEMENTS(ovec)); if (ret <= 0) { ilog(LOG_WARNING, "Unable to parse command line from " DF ": %s", DP(s->inaddr), line); return -1; } ilog(LOG_INFO, "Got valid command from " DF ": %s", DP(s->inaddr), line); pcre_get_substring_list(line, ovec, ret, (const char ***) &out); if (out[RE_TCP_RL_CALLID]) log_info_c_string(out[RE_TCP_RL_CALLID]); else if (out[RE_TCP_D_CALLID]) log_info_c_string(out[RE_TCP_D_CALLID]); if (!strcmp(out[RE_TCP_RL_CMD], "request")) output = call_request_tcp(out, c->callmaster); else if (!strcmp(out[RE_TCP_RL_CMD], "lookup")) output = call_lookup_tcp(out, c->callmaster); else if (!strcmp(out[RE_TCP_D_CMD], "delete")) call_delete_tcp(out, c->callmaster); else if (!strcmp(out[RE_TCP_DIV_CMD], "status")) calls_status_tcp(c->callmaster, s); else if (!strcmp(out[RE_TCP_DIV_CMD], "build") | !strcmp(out[RE_TCP_DIV_CMD], "version")) control_stream_printf(s, "Version: %s\n", RTPENGINE_VERSION); else if (!strcmp(out[RE_TCP_DIV_CMD], "controls")) control_list(c, s); else if (!strcmp(out[RE_TCP_DIV_CMD], "quit") || !strcmp(out[RE_TCP_DIV_CMD], "exit")) ; if (output) { mutex_lock(&s->lock); streambuf_write_str(s->outbuf, output); mutex_unlock(&s->lock); free(output); } pcre_free(out); log_info_clear(); return -1; }
void calls_status_tcp(struct callmaster *m, struct control_stream *s) { GQueue q = G_QUEUE_INIT; struct call *c; callmaster_get_all_calls(m, &q); control_stream_printf(s, "proxy %u "UINT64F"/%i/%i\n", g_queue_get_length(&q), atomic64_get(&m->stats.bytes), 0, 0); while (q.head) { c = g_queue_pop_head(&q); call_status_iterator(c, s); obj_put(c); } }
static void call_status_iterator(struct call *c, struct control_stream *s) { // GList *l; // struct callstream *cs; // struct peer *p; // struct streamrelay *r1, *r2; // struct streamrelay *rx1, *rx2; // struct callmaster *m; // char addr1[64], addr2[64], addr3[64]; // m = c->callmaster; // mutex_lock(&c->master_lock); control_stream_printf(s, "session "STR_FORMAT" - - - - %i\n", STR_FMT(&c->callid), (int) (poller_now - c->created)); /* XXX restore function */ // mutex_unlock(&c->master_lock); }
void calls_status_tcp(struct callmaster *m, struct control_stream *s) { struct stats st; GQueue q = G_QUEUE_INIT; struct call *c; mutex_lock(&m->statslock); st = m->stats; mutex_unlock(&m->statslock); callmaster_get_all_calls(m, &q); control_stream_printf(s, "proxy %u "UINT64F"/"UINT64F"/"UINT64F"\n", g_queue_get_length(&q), st.bytes, st.bytes - st.errors, st.bytes * 2 - st.errors); while (q.head) { c = g_queue_pop_head(&q); call_status_iterator(c, s); obj_put(c); } }