Beispiel #1
0
static struct dlr_entry *dlr_pgsql_get(const Octstr *smsc, const Octstr *ts, const Octstr *dst)
{
    struct dlr_entry *res = NULL;
    Octstr *sql, *like;
    List *result, *row;

    if (dst)
        like = octstr_format("AND \"%S\" LIKE '%%%S'", fields->field_dst, dst);
    else
        like = octstr_imm("");

    sql = octstr_format("SELECT \"%S\", \"%S\", \"%S\", \"%S\", \"%S\", "
          "\"%S\" FROM \"%S\" WHERE \"%S\"='%S' AND \"%S\"='%S' %S LIMIT 1;",
          fields->field_mask, fields->field_serv, fields->field_url,
          fields->field_src, fields->field_dst, fields->field_boxc,
          fields->table, fields->field_smsc, smsc, fields->field_ts, ts, like);

    result = pgsql_select(sql);
    octstr_destroy(sql);
    octstr_destroy(like);

    if (result == NULL || gwlist_len(result) < 1) {
        debug("dlr.pgsql", 0, "no rows found");
        gwlist_destroy(result, NULL);
        return NULL;
    }

    row = gwlist_get(result, 0);

    debug("dlr.pgsql", 0, "Found entry, col1=%s, col2=%s, col3=%s, col4=%s, col5=%s col6=%s",
		    octstr_get_cstr(gwlist_get(row, 0)),
		    octstr_get_cstr(gwlist_get(row, 1)),
		    octstr_get_cstr(gwlist_get(row, 2)),
		    octstr_get_cstr(gwlist_get(row, 3)),
		    octstr_get_cstr(gwlist_get(row, 4)),
		    octstr_get_cstr(gwlist_get(row, 5))
	 );

    res = dlr_entry_create();
    gw_assert(res != NULL);
    res->mask        = atoi(octstr_get_cstr(gwlist_get(row, 0)));
    res->service     = octstr_duplicate(gwlist_get(row, 1));
    res->url         = octstr_duplicate(gwlist_get(row, 2));
    res->source      = octstr_duplicate(gwlist_get(row, 3));
    res->destination = octstr_duplicate(gwlist_get(row, 4));
    res->boxc_id     = octstr_duplicate(gwlist_get(row, 5));
    res->smsc        = octstr_duplicate(smsc);

    while((row = gwlist_extract_first(result)))
        gwlist_destroy(row, octstr_destroy_item);
    gwlist_destroy(result, NULL);

    return res;
}
Beispiel #2
0
static struct dlr_entry *dlr_pgsql_get(const Octstr *smsc, const Octstr *ts, const Octstr *dst)
{
    struct dlr_entry *res = NULL;
    Octstr *sql;
    List *result, *row;

    sql = octstr_format("SELECT %s, %s, %s, %s, %s, %s FROM %s WHERE %s='%s' AND %s='%s' LIMIT 1;",
                        octstr_get_cstr(fields->field_mask), octstr_get_cstr(fields->field_serv),
                        octstr_get_cstr(fields->field_url), octstr_get_cstr(fields->field_src),
                        octstr_get_cstr(fields->field_dst), octstr_get_cstr(fields->field_boxc),
                        octstr_get_cstr(fields->table), octstr_get_cstr(fields->field_smsc),
                        octstr_get_cstr(smsc), octstr_get_cstr(fields->field_ts), octstr_get_cstr(ts));


    result = pgsql_select(sql);
    octstr_destroy(sql);

    if (result == NULL || gwlist_len(result) < 1) {
        debug("dlr.pgsql", 0, "no rows found");
        while((row = gwlist_extract_first(result)))
            gwlist_destroy(row, octstr_destroy_item);
        gwlist_destroy(result, NULL);
        return NULL;
    }
    
    row = gwlist_get(result, 0);

    debug("dlr.pgsql", 0, "Found entry, col1=%s, col2=%s, col3=%s, col4=%s, col5=%s col6=%s",
		    octstr_get_cstr(gwlist_get(row, 0)),
		    octstr_get_cstr(gwlist_get(row, 1)),
		    octstr_get_cstr(gwlist_get(row, 2)),
		    octstr_get_cstr(gwlist_get(row, 3)),
		    octstr_get_cstr(gwlist_get(row, 4)),
		    octstr_get_cstr(gwlist_get(row, 5))
	 );

    res = dlr_entry_create();
    gw_assert(res != NULL);
    res->mask        = atoi(octstr_get_cstr(gwlist_get(row, 0)));
    res->service     = octstr_duplicate(gwlist_get(row, 1));
    res->url         = octstr_duplicate(gwlist_get(row, 2));
    res->source      = octstr_duplicate(gwlist_get(row, 3));
    res->destination = octstr_duplicate(gwlist_get(row, 4));
    res->boxc_id     = octstr_duplicate(gwlist_get(row, 5));
    res->smsc        = octstr_duplicate(smsc);

    while((row = gwlist_extract_first(result)))
        gwlist_destroy(row, octstr_destroy_item);
    gwlist_destroy(result, NULL);
    
    return res;
}
Beispiel #3
0
static long dlr_pgsql_messages(void)
{
    Octstr *sql;
    long ret;
    List *res;

    sql = octstr_format("SELECT count(*) FROM %s;", octstr_get_cstr(fields->table));

    res = pgsql_select(sql);
    octstr_destroy(sql);

    if (res == NULL || gwlist_len(res) < 1) {
        error(0, "PGSQL: Could not get count of DLR table");
        ret = -1;
    } else {
        ret = atol(octstr_get_cstr(gwlist_get(gwlist_get(res, 0), 0)));
    }

    gwlist_destroy(gwlist_extract_first(res), octstr_destroy_item);
    gwlist_destroy(res, NULL);
        
    return ret;
}