/* Create MMS retrieve task */
MMSTask*
mms_task_retrieve_new(
    MMSSettings* settings,
    MMSHandler* handler,
    const char* id,
    const char* imsi,
    const MMSPdu* pdu,
    GError** error)
{
    const time_t now = time(NULL);
    MMS_ASSERT(pdu);
    MMS_ASSERT(pdu->type == MMS_MESSAGE_TYPE_NOTIFICATION_IND);
    MMS_ASSERT(pdu->transaction_id);
    if (pdu->ni.expiry > now) {
        MMSTaskRetrieve* retrieve = mms_task_http_alloc(
                                        MMS_TYPE_TASK_RETRIEVE, settings, handler, "Retrieve",
                                        id, imsi, pdu->ni.location, MMS_RETRIEVE_CONF_FILE, NULL);
        if (retrieve->http.task.deadline > pdu->ni.expiry) {
            retrieve->http.task.deadline = pdu->ni.expiry;
        }
        retrieve->transaction_id = g_strdup(pdu->transaction_id);
        return &retrieve->http.task;
    } else {
        MMS_ERROR(error, MMS_LIB_ERROR_EXPIRED, "Message already expired");
    }
    return NULL;
}
Beispiel #2
0
static
const char*
mms_task_read_encode(
    const MMSConfig* config,
    const char* id,
    const char* message_id,
    const char* to,
    MMSReadStatus status,
    GError** err)
{
    const char* result = NULL;
    const char* file = MMS_READ_REC_IND_FILE;
    char* path = NULL;
    char* dir = mms_message_dir(config, id);
    int fd = mms_create_file(dir, file, &path, err);
    if (fd >= 0) {
        MMSPdu* pdu = g_new0(MMSPdu, 1);
        pdu->type = MMS_MESSAGE_TYPE_READ_REC_IND;
        pdu->version = MMS_VERSION;
        pdu->ri.rr_status = (status == MMS_READ_STATUS_DELETED) ?
            MMS_MESSAGE_READ_STATUS_DELETED : MMS_MESSAGE_READ_STATUS_READ;
        pdu->ri.msgid = g_strdup(message_id);
        pdu->ri.to = g_strdup(to);
        time(&pdu->ri.date);
        if (mms_message_encode(pdu, fd)) {
            result = file;
        } else {
            MMS_ERROR(err, MMS_LIB_ERROR_ENCODE, "Failed to encode %s", path);
        }
        mms_message_free(pdu);
        g_free(path);
        close(fd);
    }
    g_free(dir);
    return result;
}