int
handle_get_stats(struct cfg *cf, struct rtpp_command *cmd, int verbose)
{
    int len, i, rval;

    len = 0;
    for (i = 1; i < cmd->argc && len < (sizeof(cmd->buf_t) - 2); i++) {
        if (i > 1) {
            CHECK_OVERFLOW();
            len += snprintf(cmd->buf_t + len, sizeof(cmd->buf_t) - len, " ");
        }
        if (verbose != 0) {
            CHECK_OVERFLOW();
            len += snprintf(cmd->buf_t + len, sizeof(cmd->buf_t) - len, "%s=", \
              cmd->argv[i]);
        }
        CHECK_OVERFLOW();
        rval = CALL_METHOD(cf->stable->rtpp_stats, nstr, cmd->buf_t + len,
          sizeof(cmd->buf_t) - len, cmd->argv[i]);
        if (rval < 0) {
            return (ECODE_STSFAIL);
        }
        len += rval;
    }
    CHECK_OVERFLOW();
    len += snprintf(cmd->buf_t + len, sizeof(cmd->buf_t) - len, "\n");
    rtpc_doreply(cf, cmd->buf_t, len, cmd, 0);
    return (0);
}
Example #2
0
void
reply_error(struct cfg *cf, struct rtpp_command *cmd,
  int ecode)
{
    int len;

    len = snprintf(cmd->buf_t, sizeof(cmd->buf_t), "E%d\n", ecode);
    rtpc_doreply(cf, cmd->buf_t, len, cmd, 1);
}
Example #3
0
static void
reply_number(struct cfg *cf, struct rtpp_command *cmd,
  int number)
{
    int len;

    len = snprintf(cmd->buf_t, sizeof(cmd->buf_t), "%d\n", number);
    rtpc_doreply(cf, cmd->buf_t, len, cmd, 0);
}
Example #4
0
void
ul_reply_port(struct cfg *cf, struct rtpp_command *cmd, struct ul_reply *ulr)
{
    int len, rport;

    if (ulr == NULL || ulr->ia == NULL || ishostnull(ulr->ia)) {
        rport = (ulr == NULL) ? 0 : ulr->port;
        len = snprintf(cmd->buf_t, sizeof(cmd->buf_t), "%d\n", rport);
    } else {
        if (ulr->ia_ov == NULL) {
            len = snprintf(cmd->buf_t, sizeof(cmd->buf_t), "%d %s%s\n", ulr->port,
              addr2char(ulr->ia), (ulr->ia->sa_family == AF_INET) ? "" : "6");
        } else {
            len = snprintf(cmd->buf_t, sizeof(cmd->buf_t), "%d %s %s\n", ulr->port,
              ulr->ia_ov, (ulr->ia->sa_family == AF_INET) ? "" : "6");
        }
    }

    rtpc_doreply(cf, cmd->buf_t, len, cmd, (ulr != NULL) ? 0 : 1);
}
Example #5
0
void
ul_reply_port(struct rtpp_command *cmd, struct ul_reply *ulr)
{
    int len, rport;
    char saddr[MAX_ADDR_STRLEN];

    if (ulr == NULL || ulr->ia == NULL || ishostnull(ulr->ia)) {
        rport = (ulr == NULL) ? 0 : ulr->port;
        len = snprintf(cmd->buf_t, sizeof(cmd->buf_t), "%d\n", rport);
    } else {
        if (ulr->ia_ov == NULL) {
            addr2char_r(ulr->ia, saddr, sizeof(saddr));
            len = snprintf(cmd->buf_t, sizeof(cmd->buf_t), "%d %s%s\n", ulr->port,
              saddr, (ulr->ia->sa_family == AF_INET) ? "" : " 6");
        } else {
            len = snprintf(cmd->buf_t, sizeof(cmd->buf_t), "%d %s%s\n", ulr->port,
              ulr->ia_ov, (ulr->ia->sa_family == AF_INET) ? "" : " 6");
        }
    }

    rtpc_doreply(cmd, cmd->buf_t, len, (ulr != NULL) ? 0 : 1);
}
Example #6
0
static void
handle_info(struct cfg *cf, struct rtpp_command *cmd,
  const char *opts)
{
#if 0
    struct rtpp_session *spa, *spb;
    char addrs[4][256];
#endif
    int len, i, brief, load;
    char buf[1024 * 8];
    unsigned long long packets_in, packets_out;

    brief = 0;
    load = 0;
    for (i = 0; opts[i] != '\0'; i++) {
        switch (opts[i]) {
        case 'b':
        case 'B':
            brief = 1;
            break;

        case 'l':
        case 'L':
            load = 1;
            break;

        default:
            rtpp_log_write(RTPP_LOG_ERR, cf->stable->glog, "command syntax error");
            reply_error(cf, cmd, ECODE_PARSE_7);
            return;
        }
    }

    packets_in = CALL_METHOD(cf->stable->rtpp_stats, getlvalbyname, "npkts_rcvd");
    packets_out = CALL_METHOD(cf->stable->rtpp_stats, getlvalbyname, "npkts_relayed") +
      CALL_METHOD(cf->stable->rtpp_stats, getlvalbyname, "npkts_played");
    pthread_mutex_lock(&cf->sessinfo.lock);
    len = snprintf(buf, sizeof(buf), "sessions created: %llu\nactive sessions: %d\n"
      "active streams: %d\npackets received: %llu\npackets transmitted: %llu\n",
      cf->sessions_created, cf->sessions_active, cf->sessinfo.nsessions,
      packets_in, packets_out);
    if (load != 0) {
          len += snprintf(buf + len, sizeof(buf) - len, "average load: %f\n",
            CALL_METHOD(cf->stable->rtpp_cmd_cf, get_aload));
    }
#if 0
XXX this needs work to fix it after rtp/rtcp split 
    for (i = 0; i < cf->sessinfo.nsessions && brief == 0; i++) {
        spa = cf->sessinfo.sessions[i];
        if (spa == NULL || spa->sidx[0] != i)
            continue;
        /* RTCP twin session */
        if (spa->rtcp == NULL) {
            spb = spa->rtp;
            buf[len++] = '\t';
        } else {
            spb = spa->rtcp;
            buf[len++] = '\t';
            buf[len++] = 'C';
            buf[len++] = ' ';
        }

        addr2char_r(spb->laddr[1], addrs[0], sizeof(addrs[0]));
        if (spb->addr[1] == NULL) {
            strcpy(addrs[1], "NONE");
        } else {
            sprintf(addrs[1], "%s:%d", addr2char(spb->addr[1]),
              addr2port(spb->addr[1]));
        }
        addr2char_r(spb->laddr[0], addrs[2], sizeof(addrs[2]));
        if (spb->addr[0] == NULL) {
            strcpy(addrs[3], "NONE");
        } else {
            sprintf(addrs[3], "%s:%d", addr2char(spb->addr[0]),
              addr2port(spb->addr[0]));
        }

        len += snprintf(buf + len, sizeof(buf) - len,
          "%s/%s: caller = %s:%d/%s, callee = %s:%d/%s, "
          "stats = %lu/%lu/%lu/%lu, ttl = %d/%d\n",
          spb->call_id, spb->tag, addrs[0], spb->ports[1], addrs[1],
          addrs[2], spb->ports[0], addrs[3], spa->pcount[0], spa->pcount[1],
          spa->pcount[2], spa->pcount[3], spb->ttl[0], spb->ttl[1]);
        if (len + 512 > sizeof(buf)) {
            rtpc_doreply(cf, buf, len, cmd);
            len = 0;
        }
    }
#endif
    pthread_mutex_unlock(&cf->sessinfo.lock);
    if (len > 0) {
        rtpc_doreply(cf, buf, len, cmd, 0);
    }
}