|
|
|
@ -19,61 +19,53 @@
|
|
|
|
|
#define WAPPUSH_PORT 2948
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static HTTPCaller *httpcaller;
|
|
|
|
|
static MmsEnvelope edummy;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static MmsEnvelope *update_env_success(MmsEnvelope *env, MmsEnvelopeTo *xto)
|
|
|
|
|
static MmsEnvelope *update_env_success(MmsEnvelope *e, MmsEnvelopeTo *xto)
|
|
|
|
|
{
|
|
|
|
|
time_t tnow = time(NULL);
|
|
|
|
|
|
|
|
|
|
if (xto && !(env->msgtype == MMS_MSGTYPE_SEND_REQ ||
|
|
|
|
|
env->msgtype == MMS_MSGTYPE_RETRIEVE_CONF))
|
|
|
|
|
if (xto && !(e->msgtype == MMS_MSGTYPE_SEND_REQ ||
|
|
|
|
|
e->msgtype == MMS_MSGTYPE_RETRIEVE_CONF))
|
|
|
|
|
xto->process = 0; /* No more processing. */
|
|
|
|
|
else {
|
|
|
|
|
env->lasttry = tnow;
|
|
|
|
|
env->attempts++;
|
|
|
|
|
e->lasttry = tnow;
|
|
|
|
|
e->attempts++;
|
|
|
|
|
|
|
|
|
|
/* If max send attempts has been reached, set next try to expiry time, otherwise
|
|
|
|
|
* use normal back-off procedure
|
|
|
|
|
*/
|
|
|
|
|
if (env->attempts >= settings->maxsendattempts)
|
|
|
|
|
env->sendt = env->expiryt;
|
|
|
|
|
if (e->attempts >= settings->maxsendattempts)
|
|
|
|
|
e->sendt = e->expiryt;
|
|
|
|
|
else
|
|
|
|
|
env->sendt = env->lasttry + settings->send_back_off * env->attempts;
|
|
|
|
|
e->sendt = e->lasttry + settings->send_back_off * e->attempts;
|
|
|
|
|
|
|
|
|
|
if (settings->qfs->mms_queue_update(e) == 1)
|
|
|
|
|
e = NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (settings->qfs->mms_queue_update(env) == 1)
|
|
|
|
|
env = NULL;
|
|
|
|
|
return env;
|
|
|
|
|
return e;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static MmsEnvelope *update_env_failed(MmsEnvelope *env)
|
|
|
|
|
static MmsEnvelope *update_env_failed(MmsEnvelope *e)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
time_t tnow = time(NULL);
|
|
|
|
|
if (env && env != &edummy) {
|
|
|
|
|
env->sendt = tnow + settings->send_back_off;
|
|
|
|
|
env->lasttry = tnow;
|
|
|
|
|
|
|
|
|
|
if (settings->qfs->mms_queue_update(env) == 1)
|
|
|
|
|
env = NULL;
|
|
|
|
|
}
|
|
|
|
|
return env;
|
|
|
|
|
e->sendt = tnow + settings->send_back_off;
|
|
|
|
|
e->lasttry = tnow;
|
|
|
|
|
|
|
|
|
|
if (settings->qfs->mms_queue_update(e) == 1)
|
|
|
|
|
e = NULL;
|
|
|
|
|
return e;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void start_push(Octstr *rcpt_to, int isphonenum, MmsEnvelope *e, MmsMsg *msg)
|
|
|
|
|
static void do_mm1_push(Octstr *rcpt_to, int isphonenum, MmsEnvelope *e, MmsMsg *msg)
|
|
|
|
|
{
|
|
|
|
|
List *pheaders;
|
|
|
|
|
static unsigned char ct; /* Transaction counter -- do we need it? */
|
|
|
|
|
Octstr *to = NULL;
|
|
|
|
|
|
|
|
|
|
Octstr *pduhdr = octstr_create("");
|
|
|
|
|
|
|
|
|
|
Octstr *s = NULL;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
mms_info(0, "MM1", NULL, "mms2mobile.startpush: notification to %s\n", octstr_get_cstr(rcpt_to));
|
|
|
|
|
|
|
|
|
|
if (!rcpt_to) {
|
|
|
|
|
mms_error(0, "MM1", NULL, "mobilesender: Queue entry %s has no recipient address!", e->xqfname);
|
|
|
|
|
goto done;
|
|
|
|
@ -99,29 +91,35 @@ static void start_push(Octstr *rcpt_to, int isphonenum, MmsEnvelope *e, MmsMsg *
|
|
|
|
|
octstr_append_char(pduhdr, 0x84); /* ... */
|
|
|
|
|
|
|
|
|
|
s = mms_tobinary(msg);
|
|
|
|
|
|
|
|
|
|
if (isphonenum) {
|
|
|
|
|
Octstr *url;
|
|
|
|
|
|
|
|
|
|
octstr_url_encode(to);
|
|
|
|
|
octstr_url_encode(s);
|
|
|
|
|
#if 0
|
|
|
|
|
octstr_dump(pduhdr, 0);
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
octstr_url_encode(pduhdr);
|
|
|
|
|
|
|
|
|
|
url = octstr_format("%S&text=%S%S&to=%S&udh=%%06%%05%%04%%0B%%84%%23%%F0",
|
|
|
|
|
Octstr *url = octstr_format("%S&text=%E%E&to=%E&udh=%%06%%05%%04%%0B%%84%%23%%F0",
|
|
|
|
|
settings->sendsms_url, pduhdr, s, to);
|
|
|
|
|
int status;
|
|
|
|
|
List *rph = NULL;
|
|
|
|
|
Octstr *rbody = NULL;
|
|
|
|
|
MmsEnvelopeTo *xto = gwlist_get(e->to, 0);
|
|
|
|
|
|
|
|
|
|
pheaders = http_create_empty_headers();
|
|
|
|
|
http_header_add(pheaders, "Connection", "close");
|
|
|
|
|
http_header_add(pheaders, "User-Agent", MM_NAME "/" MMSC_VERSION);
|
|
|
|
|
|
|
|
|
|
http_start_request(httpcaller, HTTP_METHOD_GET, url,
|
|
|
|
|
pheaders, NULL, 0, e, NULL);
|
|
|
|
|
if ((status = mms_url_fetch_content(HTTP_METHOD_GET, url, pheaders, NULL, &rph, &rbody)) < 0 ||
|
|
|
|
|
http_status_class(status) != HTTP_STATUS_SUCCESSFUL) {
|
|
|
|
|
|
|
|
|
|
mms_error(0, "MM1", NULL, " Push[%s] from %s, to %s, failed, HTTP code => %d", e->xqfname,
|
|
|
|
|
octstr_get_cstr(e->from), octstr_get_cstr(to), status);
|
|
|
|
|
|
|
|
|
|
e = update_env_failed(e);
|
|
|
|
|
} else { /* Successful push. */
|
|
|
|
|
|
|
|
|
|
mms_log2("Notify", octstr_imm("system"), to,
|
|
|
|
|
-1, e ? e->msgId : NULL, NULL, NULL, "MM1", NULL,NULL);
|
|
|
|
|
e = update_env_success(e, xto);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
http_destroy_headers(pheaders);
|
|
|
|
|
http_destroy_headers(rph);
|
|
|
|
|
octstr_destroy(rbody);
|
|
|
|
|
octstr_destroy(url);
|
|
|
|
|
} else { /* An IP Address: Send packet, forget. */
|
|
|
|
|
Octstr *addr = udp_create_address(to, WAPPUSH_PORT);
|
|
|
|
@ -144,87 +142,14 @@ static void start_push(Octstr *rcpt_to, int isphonenum, MmsEnvelope *e, MmsMsg *
|
|
|
|
|
mms_error(0, "MM1", NULL, "push to %s:%d failed: %s", octstr_get_cstr(to), WAPPUSH_PORT, strerror(errno));
|
|
|
|
|
}
|
|
|
|
|
octstr_destroy(addr);
|
|
|
|
|
if (e)
|
|
|
|
|
settings->qfs->mms_queue_free_env(e);
|
|
|
|
|
}
|
|
|
|
|
done:
|
|
|
|
|
octstr_destroy(to);
|
|
|
|
|
octstr_destroy(pduhdr);
|
|
|
|
|
octstr_destroy(s);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static int receive_push_reply(HTTPCaller *caller)
|
|
|
|
|
{
|
|
|
|
|
int http_status;
|
|
|
|
|
List *reply_headers = NULL;
|
|
|
|
|
Octstr *final_url = NULL, *reply_body = NULL;
|
|
|
|
|
|
|
|
|
|
MmsEnvelope *env;
|
|
|
|
|
|
|
|
|
|
http_status = HTTP_UNAUTHORIZED;
|
|
|
|
|
|
|
|
|
|
while ((env = http_receive_result_real(caller, &http_status, &final_url, &reply_headers,
|
|
|
|
|
&reply_body,1)) != NULL) {
|
|
|
|
|
MmsEnvelopeTo *xto = NULL;
|
|
|
|
|
Octstr *to = NULL;
|
|
|
|
|
|
|
|
|
|
if (http_status == -1 || final_url == NULL) {
|
|
|
|
|
mms_error(0, "MM1", NULL, "push failed, no reason found");
|
|
|
|
|
goto push_failed;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (env == &edummy) /* Skip this one it is a dummy. */
|
|
|
|
|
goto push_free_env;
|
|
|
|
|
xto = gwlist_get(env->to, 0);
|
|
|
|
|
if (xto)
|
|
|
|
|
to = xto->rcpt;
|
|
|
|
|
else {
|
|
|
|
|
mms_error(0, "MM1", NULL, "mobilesender: Queue entry %s has no recipient address!", env->xqfname);
|
|
|
|
|
goto push_failed;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
mms_info(0, "MM1", NULL, "send2mobile.push_reply[%s]: From %s, to %s => %d",
|
|
|
|
|
env->xqfname,
|
|
|
|
|
octstr_get_cstr(env->from), octstr_get_cstr(to), http_status);
|
|
|
|
|
|
|
|
|
|
if (http_status == HTTP_UNAUTHORIZED ||
|
|
|
|
|
http_status == HTTP_NOT_FOUND ||
|
|
|
|
|
http_status == HTTP_FORBIDDEN) { /* This is a temporary system error
|
|
|
|
|
* do not increase attempts, count,
|
|
|
|
|
* merely reschedule
|
|
|
|
|
* for a minute or so later.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
mms_error(0, "MM1", NULL, "Deffered notification, WAP Push failed for "
|
|
|
|
|
"msgid %s to %s, http error: %d!", octstr_get_cstr(env->msgId),
|
|
|
|
|
octstr_get_cstr(to), http_status);
|
|
|
|
|
goto push_failed;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
debug("mobilesender.push", 0, "Push reply headers were");
|
|
|
|
|
http_header_dump(reply_headers);
|
|
|
|
|
|
|
|
|
|
mms_log2("Notify", octstr_imm("system"), to,
|
|
|
|
|
-1, env ? env->msgId : NULL, NULL, NULL, "MM1", NULL,NULL);
|
|
|
|
|
|
|
|
|
|
if ((env = update_env_success(env, xto)) != NULL)
|
|
|
|
|
goto push_free_env;
|
|
|
|
|
|
|
|
|
|
/* Fall through. */
|
|
|
|
|
push_failed:
|
|
|
|
|
env = update_env_failed(env);
|
|
|
|
|
push_free_env:
|
|
|
|
|
if (env && env != &edummy)
|
|
|
|
|
settings->qfs->mms_queue_free_env(env);
|
|
|
|
|
|
|
|
|
|
octstr_destroy(final_url);
|
|
|
|
|
octstr_destroy(reply_body);
|
|
|
|
|
http_destroy_headers(reply_headers);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
if (e)
|
|
|
|
|
settings->qfs->mms_queue_free_env(e);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int sendNotify(MmsEnvelope *e)
|
|
|
|
@ -344,23 +269,27 @@ static int sendNotify(MmsEnvelope *e)
|
|
|
|
|
Octstr *s = octstr_format(octstr_get_cstr(settings->mms_notify_txt),
|
|
|
|
|
from);
|
|
|
|
|
if (settings->notify_unprovisioned && s && octstr_len(s) > 0) { /* Only send if the string was set. */
|
|
|
|
|
List *pheaders;
|
|
|
|
|
Octstr *sto = octstr_duplicate(phonenum);
|
|
|
|
|
List *pheaders = http_create_empty_headers(), *rph = NULL;
|
|
|
|
|
Octstr *rbody = NULL;
|
|
|
|
|
int status;
|
|
|
|
|
|
|
|
|
|
octstr_url_encode(s);
|
|
|
|
|
octstr_url_encode(sto);
|
|
|
|
|
url = octstr_format("%S&text=%E&to=%E",settings->sendsms_url,s, phonenum);
|
|
|
|
|
|
|
|
|
|
url = octstr_format("%S&text=%S&to=%S",settings->sendsms_url,s, sto);
|
|
|
|
|
pheaders = http_create_empty_headers();
|
|
|
|
|
http_header_add(pheaders, "Connection", "close");
|
|
|
|
|
http_header_add(pheaders, "User-Agent", MM_NAME "/" VERSION);
|
|
|
|
|
|
|
|
|
|
http_start_request(httpcaller, HTTP_METHOD_GET, url,
|
|
|
|
|
pheaders, NULL, 0, &edummy, NULL);
|
|
|
|
|
if ((status = mms_url_fetch_content(HTTP_METHOD_GET, url,
|
|
|
|
|
pheaders, NULL, &rph, &rbody)) <0 ||
|
|
|
|
|
http_status_class(status) != HTTP_STATUS_SUCCESSFUL)
|
|
|
|
|
mms_error(0, "MM1", NULL, "Notify unprovisioned url fetch failed => %d", status);
|
|
|
|
|
|
|
|
|
|
http_destroy_headers(pheaders);
|
|
|
|
|
http_destroy_headers(rph);
|
|
|
|
|
octstr_destroy(url);
|
|
|
|
|
octstr_destroy(sto);
|
|
|
|
|
} else if (s)
|
|
|
|
|
octstr_destroy(rbody);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
octstr_destroy(s);
|
|
|
|
|
res = MMS_SEND_OK;
|
|
|
|
|
err = octstr_imm("No MMS Ind support, sent SMS instead");
|
|
|
|
@ -399,24 +328,22 @@ static int sendNotify(MmsEnvelope *e)
|
|
|
|
|
goto done;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (smsg)
|
|
|
|
|
start_push(phonenum ? phonenum : rcpt_ip,
|
|
|
|
|
if (smsg) {
|
|
|
|
|
do_mm1_push(phonenum ? phonenum : rcpt_ip,
|
|
|
|
|
phonenum ? 1 : 0,
|
|
|
|
|
e, smsg); /* Send the message.
|
|
|
|
|
* Don't touch 'e' after this point!
|
|
|
|
|
* It may be freed by receive thread.
|
|
|
|
|
*/
|
|
|
|
|
e, smsg); /* Don't touch 'e' after this point. It is gone */
|
|
|
|
|
e = NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (smsg != msg && smsg)
|
|
|
|
|
mms_destroy(smsg);
|
|
|
|
|
|
|
|
|
|
done:
|
|
|
|
|
if (err != NULL &&
|
|
|
|
|
res != MMS_SEND_ERROR_TRANSIENT) { /* If there was a report request and this is a legit error
|
|
|
|
|
if (e != NULL &&
|
|
|
|
|
err != NULL &&
|
|
|
|
|
res != MMS_SEND_ERROR_TRANSIENT && dlr) { /* If there was a report request and this is a legit error
|
|
|
|
|
* queue it.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
if (dlr) {
|
|
|
|
|
MmsMsg *m = mms_deliveryreport(msgId, to, e->from, tnow,
|
|
|
|
|
rtype ? octstr_imm(rtype) :
|
|
|
|
|
octstr_imm("Indeterminate"));
|
|
|
|
@ -441,16 +368,15 @@ static int sendNotify(MmsEnvelope *e)
|
|
|
|
|
octstr_destroy(res);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Write to log */
|
|
|
|
|
mms_info(0, "MM1", NULL, "%s Mobile Queue MMS Send Notify: From=%s, to=%s, msgsize=%d, reason=%s",
|
|
|
|
|
mms_info(2, "MM1", NULL, "%s Mobile Queue MMS Send Notify: From=%s, to=%s, msgsize=%d, reason=%s. Processed in %d secs",
|
|
|
|
|
SEND_ERROR_STR(res),
|
|
|
|
|
octstr_get_cstr(from), octstr_get_cstr(to), msize,
|
|
|
|
|
err ? octstr_get_cstr(err) : "");
|
|
|
|
|
err ? octstr_get_cstr(err) : "",
|
|
|
|
|
(int)(time(NULL) - tnow));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (res == MMS_SEND_ERROR_FATAL) {
|
|
|
|
|
if (res == MMS_SEND_ERROR_FATAL && xto && e) {
|
|
|
|
|
xto->process = 0; /* No more attempts to deliver, delete this. */
|
|
|
|
|
if (settings->qfs->mms_queue_update(e) == 1)
|
|
|
|
|
e = NULL; /* Queue entry gone. */
|
|
|
|
@ -477,24 +403,14 @@ static int sendNotify(MmsEnvelope *e)
|
|
|
|
|
octstr_destroy(from);
|
|
|
|
|
octstr_destroy(err);
|
|
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
|
return 1; /* Tell caller we dealt with envelope */
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void mbuni_mm1_queue_runner(int *rstop)
|
|
|
|
|
{
|
|
|
|
|
httpcaller = http_caller_create();
|
|
|
|
|
if (gwthread_create((gwthread_func_t *)receive_push_reply, httpcaller) < 0) { /* Listener thread. */
|
|
|
|
|
mms_error(0, "MM1", NULL, "Mobile sender: Failed to create push reply thread: %d: %s!",
|
|
|
|
|
errno, strerror(errno));
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
settings->qfs->mms_queue_run(octstr_get_cstr(settings->mm1_queuedir),
|
|
|
|
|
sendNotify, settings->queue_interval, settings->maxthreads, rstop);
|
|
|
|
|
gwthread_sleep(2); /* Wait for it to die. */
|
|
|
|
|
http_caller_signal_shutdown(httpcaller);
|
|
|
|
|
gwthread_sleep(2);
|
|
|
|
|
http_caller_destroy(httpcaller);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|