/
mms_task_send.c
149 lines (138 loc) · 3.94 KB
/
mms_task_send.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
/*
* Copyright (C) 2013-2014 Jolla Ltd.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*/
#include "mms_task.h"
#include "mms_task_http.h"
#include "mms_file_util.h"
#include "mms_handler.h"
#include "mms_codec.h"
/* Logging */
#define MMS_LOG_MODULE_NAME mms_task_send_log
#include "mms_lib_log.h"
#include "mms_error.h"
MMS_LOG_MODULE_DEFINE("mms-task-send");
/* Class definition */
typedef MMSTaskHttpClass MMSTaskSendClass;
typedef MMSTaskHttp MMSTaskSend;
G_DEFINE_TYPE(MMSTaskSend, mms_task_send, MMS_TYPE_TASK_HTTP);
#define MMS_TYPE_TASK_SEND (mms_task_send_get_type())
#define MMS_TASK_SEND(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj),\
MMS_TYPE_TASK_SEND, MMSTaskSend))
static
void
mms_task_send_started(
MMSTaskHttp* http)
{
mms_handler_message_send_state_changed(http->task.handler,
http->task.id, MMS_SEND_STATE_SENDING);
}
static
void
mms_task_send_paused(
MMSTaskHttp* http)
{
mms_handler_message_send_state_changed(http->task.handler,
http->task.id, MMS_SEND_STATE_DEFERRED);
}
static
void
mms_task_send_done(
MMSTaskHttp* http,
const char* path,
SoupStatus status)
{
MMSPdu* pdu = NULL;
MMS_SEND_STATE state = MMS_SEND_STATE_SEND_ERROR;
const char* msgid = NULL;
if (SOUP_STATUS_IS_SUCCESSFUL(status)) {
/* Decode the result */
GError* error = NULL;
GMappedFile* map = g_mapped_file_new(path, FALSE, &error);
if (map) {
const void* data = g_mapped_file_get_contents(map);
const gsize len = g_mapped_file_get_length(map);
pdu = g_new0(MMSPdu, 1);
if (mms_message_decode(data, len, pdu)) {
if (pdu &&
pdu->type == MMS_MESSAGE_TYPE_SEND_CONF) {
if (pdu->sc.rsp_status == MMS_MESSAGE_RSP_STATUS_OK) {
if (pdu->sc.msgid && pdu->sc.msgid[0]) {
msgid = pdu->sc.msgid;
MMS_INFO("Message ID %s", pdu->sc.msgid);
} else {
MMS_ERR("Missing Message-ID");
}
} else {
MMS_ERR("MMSC responded with %u", pdu->sc.rsp_status);
state = MMS_SEND_STATE_REFUSED;
}
} else {
MMS_ERR("Unexpected response from MMSC");
}
} else {
MMS_ERR("Failed to parse MMSC response");
}
g_mapped_file_unref(map);
} else {
MMS_ERR("%s", MMS_ERRMSG(error));
g_error_free(error);
}
}
if (msgid) {
mms_handler_message_sent(http->task.handler, http->task.id, msgid);
} else {
mms_handler_message_send_state_changed(http->task.handler,
http->task.id, state);
}
if (pdu) mms_message_free(pdu);
}
/**
* Per class initializer
*/
static
void
mms_task_send_class_init(
MMSTaskSendClass* klass)
{
klass->fn_started = mms_task_send_started;
klass->fn_paused = mms_task_send_paused;
klass->fn_done = mms_task_send_done;
}
/**
* Per instance initializer
*/
static
void
mms_task_send_init(
MMSTaskSend* send)
{
}
/* Create MMS send task */
MMSTask*
mms_task_send_new(
const MMSConfig* config,
MMSHandler* handler,
const char* id,
const char* imsi)
{
return mms_task_http_alloc(
MMS_TYPE_TASK_SEND, config, handler, "Send", id, imsi,
NULL, MMS_SEND_CONF_FILE, MMS_SEND_REQ_FILE);
}
/*
* Local Variables:
* mode: C
* c-basic-offset: 4
* indent-tabs-mode: nil
* End:
*/