1
0
Fork 0

Fixes for crashing mmsproxy when sender address not found.

This commit is contained in:
bagyenda 2005-03-30 13:48:38 +00:00
parent 08234f3191
commit 6c5d99c0e2
2 changed files with 86 additions and 22 deletions

View File

@ -432,7 +432,7 @@ static int mms_load_ua_profile_cache(char *dir)
static void mms_profile_fetcher(char *cache_dir)
{
Octstr *profile_url, *body;
Octstr *profile_url, *final_url, *body;
List *h;
int status;
@ -440,7 +440,7 @@ static void mms_profile_fetcher(char *cache_dir)
client = http_caller_create();
debug("mms.uaprof", 0, "Entered fetcher");
while (http_receive_result(client, &status, &profile_url, &h, &body) != NULL) {
while ((profile_url = http_receive_result(client, &status, &final_url, &h, &body)) != NULL) {
if (status == HTTP_OK) {
MmsUaProfile *prof = parse_uaprofile(body);
Octstr *fname;
@ -474,6 +474,7 @@ static void mms_profile_fetcher(char *cache_dir)
if (body) octstr_destroy(body);
if (profile_url) octstr_destroy(profile_url);
if (h) http_destroy_headers(h);
if (final_url) octstr_destroy(final_url);
}
debug("mms.uaprof", 0, "Fetcher shutdown...");
@ -516,19 +517,22 @@ MmsUaProfile *mms_get_ua_profile(char *url)
goto done;
}
if ((prof = dict_get(profile_dict, s)) != NULL) {
octstr_destroy(s);
if ((prof = dict_get(profile_dict, s)) != NULL)
goto done;
}
/* Not found, queue get and return NULL. */
if (client) {
h = http_create_empty_headers();
http_header_add(h, "User-Agent", MM_NAME "/" GW_VERSION);
http_start_request(client,HTTP_METHOD_GET, s, h, NULL, 1, NULL, NULL);
http_start_request(client,HTTP_METHOD_GET, s, h, NULL, 1, octstr_duplicate(s), NULL);
http_destroy_headers(h);
} else
error(0, "mms_uaprof: get_profile, Fetch thread not started!\n");
done:
octstr_destroy(s);
return prof;
}

View File

@ -138,7 +138,6 @@ int main(int argc, char *argv[])
h.prof = mms_get_ua_profile(octstr_get_cstr(profile_url));
octstr_destroy(profile_url);
} else
h.prof = mms_make_ua_profile(h.headers);
/* Get the sender address. */
@ -526,7 +525,7 @@ static void sendmms_proxy(MmsHTTPClientInfo *h)
{
Octstr *qf;
List *mh = mms_message_headers(m);
Octstr *from = octstr_duplicate(h->client_addr);
Octstr *from = h->client_addr ? octstr_duplicate(h->client_addr) : NULL;
List *to = list_create();
Octstr *subject;
time_t expiryt, deliveryt;
@ -543,6 +542,9 @@ static void sendmms_proxy(MmsHTTPClientInfo *h)
if (!h->client_addr) {
mresp = mms_sendconf("Error-sending-address-unresolved", "None", octstr_get_cstr(otransid),0,
menc);
error(0, "MMS Send interface: failed to find sender address in request from %s!",
octstr_get_cstr(h->ip));
} else {
Octstr *x = mms_get_header_value(m, octstr_imm("X-Mms-Store"));
@ -629,9 +631,12 @@ static void sendmms_proxy(MmsHTTPClientInfo *h)
if (sdf)
octstr_destroy(sdf);
octstr_destroy(from);
octstr_destroy(subject);
http_destroy_headers(mh);
if (from)
octstr_destroy(from);
if (subject)
octstr_destroy(subject);
if (mh)
http_destroy_headers(mh);
list_destroy(to, (list_item_destructor_t *)octstr_destroy);
notify_cmd = "sent";
@ -642,7 +647,7 @@ static void sendmms_proxy(MmsHTTPClientInfo *h)
{
Octstr *qf = NULL, *token = NULL;
List *mh = mms_message_headers(m);
Octstr *from = octstr_duplicate(h->client_addr);
Octstr *from = h->client_addr ? octstr_duplicate(h->client_addr) : NULL;
List *to = list_create();
Octstr *subject;
time_t expiryt, deliveryt;
@ -663,8 +668,17 @@ static void sendmms_proxy(MmsHTTPClientInfo *h)
Octstr *mmbox_loc = NULL;
Octstr *sdf = NULL;
collect_senddata(mh, &to, &subject, &otransid, &expiryt, &deliveryt);
if (!h->client_addr) {
mresp = mms_sendconf("Error-sending-address-unresolved", "None", octstr_get_cstr(otransid),1,
menc);
error(0, "MMS Send interface (fwd): failed to find sender address in request from %s!",
octstr_get_cstr(h->ip));
goto forward_done;
}
if (mms_decodefetchurl(url, &qf, &token,&mloc) != 0) {
error(0, "MMS Send interface: failed to decode forward url (%s) from %s!",
octstr_get_cstr(url),
@ -981,10 +995,14 @@ static void sendmms_proxy(MmsHTTPClientInfo *h)
mms_queue_update(e) != 1) /* Should be freed. */
mms_queue_free_env(e);
octstr_destroy(qf);
octstr_destroy(transid);
octstr_destroy(allow_report);
octstr_destroy(status);
if (qf)
octstr_destroy(qf);
if (transid)
octstr_destroy(transid);
if (allow_report)
octstr_destroy(allow_report);
if (status)
octstr_destroy(status);
http_header_add(rh, "Content-Type", "text/plain");
ctype_set = 1;
reply_body = octstr_imm("Received");
@ -996,10 +1014,11 @@ static void sendmms_proxy(MmsHTTPClientInfo *h)
case MMS_MSGTYPE_READ_REC_IND:
{
List *mh = mms_message_headers(m);
Octstr *from = octstr_duplicate(h->client_addr);
Octstr *from = h->client_addr ? octstr_duplicate(h->client_addr) : octstr_create("anon@anon");
List *to = list_create();
Octstr *x;
if (mms_convert_readrec2readorig(m) < 0)
goto mdone2;
@ -1013,9 +1032,13 @@ static void sendmms_proxy(MmsHTTPClientInfo *h)
mms_log("ReadReport", h->client_addr, NULL, msize, NULL, NULL, NULL, "MM1", h->ua,NULL);
octstr_destroy(x);
octstr_destroy(from);
http_destroy_headers(mh);
mdone2:
if (from)
octstr_destroy(from);
if (mh)
http_destroy_headers(mh);
list_destroy(to, (list_item_destructor_t *)octstr_destroy);
http_header_add(rh, "Content-Type", "text/plain");
@ -1045,6 +1068,13 @@ static void sendmms_proxy(MmsHTTPClientInfo *h)
Octstr *mmbox_loc = NULL;
Octstr *sdf = NULL;
if (!h->client_addr) {
mresp = mms_storeconf("Error-service-denied", octstr_get_cstr(otransid), NULL, 0, menc);
error(0, "MMS Send interface (store): failed to find sender address in request from %s!",
octstr_get_cstr(h->ip));
goto store_done;
}
if (mms_decodefetchurl(url, &qf, &token,&mloc) != 0) {
error(0, "MMS Send interface: failed to decode store url (%s) from %s!",
@ -1166,6 +1196,14 @@ static void sendmms_proxy(MmsHTTPClientInfo *h)
if (charset)
octstr_destroy(charset);
if (!h->client_addr) {
mresp = mms_storeconf("Error-service-denied", octstr_get_cstr(otransid), NULL, 1, menc);
error(0, "MMS Send interface (upload): failed to find sender address in request from %s!",
octstr_get_cstr(h->ip));
goto upload_done;
}
/* If:
* - body type is not mms type, or
* - we are unable to parse it
@ -1201,6 +1239,7 @@ static void sendmms_proxy(MmsHTTPClientInfo *h)
octstr_get_cstr(otransid),NULL, 1,menc);
}
upload_done:
if (mstore)
mms_destroy(mstore);
@ -1232,7 +1271,17 @@ static void sendmms_proxy(MmsHTTPClientInfo *h)
List *cls = list_create();
List *rss = list_create();
mresp = mms_deleteconf(menc, octstr_get_cstr(otransid));
if (!h->client_addr) {
error(0, "MMS Send interface (delete): failed to find sender address in request from %s!",
octstr_get_cstr(h->ip));
mms_replace_header_value(mresp, "X-Mms-Response-Status",
"0Error-permanent-sending-address-unresolved");
goto delete_done;
}
for (i = 0; i < list_len(lh); i++) {
Octstr *url = list_get(lh,i);
@ -1287,7 +1336,7 @@ static void sendmms_proxy(MmsHTTPClientInfo *h)
mms_replace_header_values(mresp, "X-Mms-Content-Location", cls);
mms_replace_header_values(mresp, "X-Mms-Response-Status", rss);
delete_done:
list_destroy(cls, (list_item_destructor_t *)octstr_destroy);
list_destroy(rss, (list_item_destructor_t *)octstr_destroy);
list_destroy(lh, (list_item_destructor_t *)octstr_destroy);
@ -1315,6 +1364,15 @@ static void sendmms_proxy(MmsHTTPClientInfo *h)
Octstr *x;
int start, limit;
if (!h->client_addr) {
error(0, "MMS Send interface (view): failed to find sender address in request from %s!",
octstr_get_cstr(h->ip));
err = "Error-permanent-sending-address-unresolved";
goto view_done;
}
if ((x = mms_get_header_value(m, octstr_imm("X-Mms-Start"))) != NULL) {
sscanf(octstr_get_cstr(x), "%d", &start);
octstr_destroy(x);
@ -1392,7 +1450,8 @@ static void sendmms_proxy(MmsHTTPClientInfo *h)
}
} else /* Profile not loaded... */
err = "Error-transient-network-problem";
view_done:
mresp = mms_viewconf(octstr_get_cstr(otransid),
msgrefs,
msglocs,
@ -1459,7 +1518,8 @@ static void sendmms_proxy(MmsHTTPClientInfo *h)
http_send_reply(h->client, hstatus, rh, reply_body);
http_destroy_headers(rh);
octstr_destroy(reply_body);
if (reply_body)
octstr_destroy(reply_body);
octstr_destroy(h->ip);
octstr_destroy(h->url);