示例#1
0
static int read_msg(Msg **msg, Octstr *os, long *off)
{
    unsigned char buf[4];
    long i;
    Octstr *pack;

    gw_assert(*off >= 0);
    if (*off + 4 > octstr_len(os)) {
        error(0, "Packet too short while unpacking Msg.");
        return -1;
    }

    octstr_get_many_chars((char*)buf, os, *off, 4);
    i = decode_network_long(buf);
    *off  +=  4;
    
    pack = octstr_copy(os, *off, i);
    *off += octstr_len(pack);
    *msg = store_msg_unpack(pack);
    octstr_destroy(pack);
    
    if (!*msg)
        return -1;
    
    return 0;
}
示例#2
0
static int verified_file(const char *filename, const struct stat *sb, int tflag, struct FTW *ftwbuf)
{
    Octstr *os;
    Msg *msg;

    /* we need to check here if we have a regular file. */
    if (tflag != FTW_F)
    	return 0;
#else
static int verified_file(const char *filename, const struct stat *sb, int tflag, void *ftwbuf)
{
	Octstr *os;
	Msg *msg;
#endif

    if ((os = octstr_read_file(filename)) == NULL) {
    	return -1;
    }

    if ((msg = store_msg_unpack(os)) == NULL) {
        error(0, "Could not unpack DLR message `%s'", filename);
    	octstr_destroy(os);
    	return -1;
    }

    /* we could load and unpack, so this is verified */
    counter_increase(counter);
    octstr_destroy(os);
    msg_destroy(msg);

    return 0;
}
示例#3
0
/*
 * Find matching entry in our spool and return the dlr_entry.
 */
static struct dlr_entry *dlr_spool_get(const Octstr *smsc, const Octstr *ts, const Octstr *dst)
{
    struct dlr_entry *ret = NULL;
    Octstr *os, *hash, *dir, *filename = NULL;
    Msg *msg;

    /* determine target dir and filename via hash */
    os = octstr_duplicate(smsc);
    octstr_append(os, ts);
	hash = our_hash_func(os);
	octstr_destroy(os);

	/* determine target dir */
	dir = octstr_format("%S/%ld", spool_dir, octstr_hash_key(hash) % MAX_DIRS);

	/* get content of msg surrogate */
	os = get_msg_surrogate(dir, hash, dst, &filename);
    octstr_destroy(dir);
    octstr_destroy(hash);

    /* if there was no content */
    if (os == NULL) {
        octstr_destroy(filename);
    	return NULL;
    }

    /* unpack */
    if ((msg = store_msg_unpack(os)) == NULL) {
    	octstr_destroy(os);
        error(0, "Could not unpack DLR message `%s'", octstr_get_cstr(filename));
        octstr_destroy(filename);
        return ret;
    }

    octstr_destroy(os);
    octstr_destroy(filename);

#define MAP(to, from) \
	to = from; \
	from = NULL;

    /* map values to a struct dlr_entry */
    ret = dlr_entry_create();
	MAP(ret->smsc, msg->sms.smsc_id);
	MAP(ret->timestamp, msg->sms.foreign_id);
	MAP(ret->source, msg->sms.sender);
	MAP(ret->destination, msg->sms.receiver);
	MAP(ret->service, msg->sms.service);
	MAP(ret->url, msg->sms.dlr_url);
	MAP(ret->boxc_id, msg->sms.boxc_id);
	ret->mask = msg->sms.dlr_mask;

	msg_destroy(msg);

    return ret;
}
示例#4
0
static void status_cb(const Octstr *filename, void *d)
{
    struct status *data = d;
    Octstr *msg_s;
    Msg *msg;

    msg_s = octstr_read_file(octstr_get_cstr(filename));
    msg = store_msg_unpack(msg_s);
    octstr_destroy(msg_s);
    if (msg == NULL)
        return;

    data->callback_fn(msg, data->data);

    msg_destroy(msg);
}
示例#5
0
static void status_cb(const Octstr *filename, void *d)
{
    struct status *data = d;
    struct tm tm;
    char id[UUID_STR_LEN + 1];
    Octstr *msg_s;
    Msg *msg;

    msg_s = octstr_read_file(octstr_get_cstr(filename));
    msg = store_msg_unpack(msg_s);
    octstr_destroy(msg_s);
    if (msg == NULL)
        return;

    /* transform the time value */
#if LOG_TIMESTAMP_LOCALTIME
    tm = gw_localtime(msg->sms.time);
#else
    tm = gw_gmtime(msg->sms.time);
#endif
    if (msg->sms.udhdata)
        octstr_binary_to_hex(msg->sms.udhdata, 1);
    if (msg->sms.msgdata &&
        (msg->sms.coding == DC_8BIT || msg->sms.coding == DC_UCS2 ||
        (msg->sms.coding == DC_UNDEF && msg->sms.udhdata)))
        octstr_binary_to_hex(msg->sms.msgdata, 1);

    uuid_unparse(msg->sms.id, id);

    octstr_format_append(data->status, data->format,
        id,
        (msg->sms.sms_type == mo ? "MO" :
        msg->sms.sms_type == mt_push ? "MT-PUSH" :
        msg->sms.sms_type == mt_reply ? "MT-REPLY" :
        msg->sms.sms_type == report_mo ? "DLR-MO" :
        msg->sms.sms_type == report_mt ? "DLR-MT" : ""),
        tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday,
        tm.tm_hour, tm.tm_min, tm.tm_sec,
        (msg->sms.sender ? octstr_get_cstr(msg->sms.sender) : ""),
        (msg->sms.receiver ? octstr_get_cstr(msg->sms.receiver) : ""),
        (msg->sms.smsc_id ? octstr_get_cstr(msg->sms.smsc_id) : ""),
        (msg->sms.boxc_id ? octstr_get_cstr(msg->sms.boxc_id) : ""),
        (msg->sms.udhdata ? octstr_get_cstr(msg->sms.udhdata) : ""),
        (msg->sms.msgdata ? octstr_get_cstr(msg->sms.msgdata) : ""));

    msg_destroy(msg);
}
示例#6
0
static void dispatch(const Octstr *filename, void *data)
{
    Octstr *msg_s;
    Msg *msg;
    void(*receive_msg)(Msg*) = data;

    /* debug("", 0, "dispatch(%s,...) called", octstr_get_cstr(filename)); */

    msg_s = octstr_read_file(octstr_get_cstr(filename));
    if (msg_s == NULL)
        return;
    msg = store_msg_unpack(msg_s);
    octstr_destroy(msg_s);
    if (msg != NULL) {
        receive_msg(msg);
        counter_increase(counter);
    } else {
        error(0, "Could not unpack message `%s'", octstr_get_cstr(filename));
    }
}