Exemplo n.º 1
0
void
settings_dump()
{
    int i;
    for (i = 1; i < SETTING_COUNT; i++) {
        printf("SettingId: %d\t SettingName: %-20s Value: %s\n", i,
               setting_name(i),
               setting_get_value(i));
    }
}
Exemplo n.º 2
0
Arquivo: sip.c Projeto: irontec/sngrep
void
sip_init(int limit, int only_calls, int no_incomplete)
{
    int match_flags, reg_rule_len, reg_rule_err;
    char reg_rule[SIP_ATTR_MAXLEN];
    const char *setting = NULL;

    // Store capture limit
    calls.limit = limit;
    calls.only_calls = only_calls;
    calls.ignore_incomplete = no_incomplete;
    calls.last_index = 0;

    // Create a vector to store calls
    calls.list = vector_create(200, 50);
    vector_set_destroyer(calls.list, call_destroyer);
    vector_set_sorter(calls.list, sip_list_sorter);
    calls.active = vector_create(10, 10);

    // Create hash table for callid search
    calls.callids = htable_create(calls.limit);

    // Set default sorting field
    if (sip_attr_from_name(setting_get_value(SETTING_CL_SORTFIELD)) >= 0) {
        calls.sort.by = sip_attr_from_name(setting_get_value(SETTING_CL_SORTFIELD));
        calls.sort.asc = (!strcmp(setting_get_value(SETTING_CL_SORTORDER), "asc"));
    } else {
        // Fallback to default sorting field
        calls.sort.by = SIP_ATTR_CALLINDEX;
        calls.sort.asc = true;
    }

    // Initialize payload parsing regexp
    match_flags = REG_EXTENDED | REG_ICASE | REG_NEWLINE;
    regcomp(&calls.reg_method, "^([a-zA-Z]+) [a-zA-Z]+:.+ SIP/2.0[ ]*\r", match_flags & ~REG_NEWLINE);
    regcomp(&calls.reg_callid, "^(Call-ID|i):[ ]*([^ ]+)[ ]*\r$", match_flags);
    setting = setting_get_value(SETTING_SIP_HEADER_X_CID);
    reg_rule_len = strlen(setting) + 22;
    if (reg_rule_len >= SIP_ATTR_MAXLEN) {
        setting = "X-Call-ID|X-CID";
        reg_rule_len = strlen(setting) + 22;
        fprintf(stderr, "%s setting too long, using default.\n",
            setting_name(SETTING_SIP_HEADER_X_CID));
    }
    snprintf(reg_rule, reg_rule_len, "^(%s):[ ]*([^ ]+)[ ]*\r$", setting);
    reg_rule_err = regcomp(&calls.reg_xcallid, reg_rule, match_flags);
    if(reg_rule_err != 0) {
        regerror(reg_rule_err, &calls.reg_xcallid, reg_rule, SIP_ATTR_MAXLEN);
        regfree(&calls.reg_xcallid);
        fprintf(stderr, "%s setting produces regex compilation error: %s"
            "using default value instead\n",
            setting_name(SETTING_SIP_HEADER_X_CID), reg_rule);
        regcomp(&calls.reg_xcallid,
            "^(X-Call-ID|X-CID):[ ]*([^ ]+)[ ]*\r$", match_flags);
    }
    regcomp(&calls.reg_response, "^SIP/2.0[ ]*(([0-9]{3}) [^\r]*)[ ]*\r", match_flags & ~REG_NEWLINE);
    regcomp(&calls.reg_cseq, "^CSeq:[ ]*([0-9]{1,10}) .+\r$", match_flags);
    regcomp(&calls.reg_from, "^(From|f):[ ]*[^:]*:(([^@>]+)@?[^\r>;]+)", match_flags);
    regcomp(&calls.reg_to, "^(To|t):[ ]*[^:]*:(([^@>]+)@?[^\r>;]+)", match_flags);
    regcomp(&calls.reg_valid, "^([A-Z]+ [a-zA-Z]+:|SIP/2.0 [0-9]{3})", match_flags & ~REG_NEWLINE);
    regcomp(&calls.reg_cl, "^(Content-Length|l):[ ]*([0-9]+)[ ]*\r$", match_flags);
    regcomp(&calls.reg_body, "\r\n\r\n(.*)", match_flags & ~REG_NEWLINE);
    regcomp(&calls.reg_reason, "Reason:[ ]*[^\r]*;text=\"([^\r]+)\"", match_flags);
    regcomp(&calls.reg_warning, "Warning:[ ]*([0-9]*)", match_flags);

}