/
mms_task_send.c
160 lines (149 loc) · 4.69 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
150
151
152
153
154
155
156
157
158
159
160
/*
* Copyright (C) 2013-2016 Jolla Ltd.
* Contact: Slava Monich <slava.monich@jolla.com>
*
* 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 GLOG_MODULE_NAME mms_task_send_log
#include "mms_lib_log.h"
#include "mms_error.h"
GLOG_MODULE_DEFINE2("mms-task-send", MMS_TASK_HTTP_LOG);
/* 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, NULL);
}
static
void
mms_task_send_paused(
MMSTaskHttp* http)
{
mms_handler_message_send_state_changed(http->task.handler,
http->task.id, MMS_SEND_STATE_DEFERRED, NULL);
}
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;
const char* details = 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;
GINFO("Message ID %s", pdu->sc.msgid);
} else {
GERR("Missing Message-ID");
}
} else {
GERR("MMSC responded with %u", pdu->sc.rsp_status);
details = pdu->sc.rsp_text;
switch (pdu->sc.rsp_status) {
case MMS_MESSAGE_RSP_STATUS_ERR_SERVICE_DENIED:
case MMS_MESSAGE_RSP_STATUS_ERR_CONTENT_NOT_ACCEPTED:
case MMS_MESSAGE_RSP_STATUS_ERR_UNSUPPORTED_MESSAGE:
case MMS_MESSAGE_RSP_STATUS_ERR_PERM_SERVICE_DENIED:
case MMS_MESSAGE_RSP_STATUS_ERR_PERM_LACK_OF_PREPAID:
case MMS_MESSAGE_RSP_STATUS_ERR_PERM_CONTENT_NOT_ACCEPTED:
state = MMS_SEND_STATE_REFUSED;
break;
default:
break;
}
}
} else {
GERR("Unexpected response from MMSC");
}
} else {
GERR("Failed to parse MMSC response");
}
g_mapped_file_unref(map);
} else {
GERR("%s", GERRMSG(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, details);
}
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(
MMSTask* parent,
MMSTransferList* transfers)
{
return mms_task_http_alloc_with_parent(MMS_TYPE_TASK_SEND, parent,
transfers, MMS_TRANSFER_TYPE_SEND, NULL, MMS_SEND_CONF_FILE,
MMS_SEND_REQ_FILE);
}
/*
* Local Variables:
* mode: C
* c-basic-offset: 4
* indent-tabs-mode: nil
* End:
*/