Пример #1
0
static Octstr  *mm7http_send(MmscGrp *mmc, Octstr *from, Octstr *to,
			     MmsMsg *m, Octstr **error,
			     int *retry)
{
     Octstr *ret = NULL;
     int mtype = mms_messagetype(m);
     int hstatus = HTTP_OK;
     List *rh, *ph = NULL;
     Octstr *body = NULL, *rbody = NULL; 
     Octstr *mms;
     MIMEEntity *form_data = make_multipart_formdata();
     
     mms_info(0, "MM7", mmc->id,  "MMSBox: Send [http] to MMC[%s], msg type [%s], from %s, to %s", 
	  mmc ? octstr_get_cstr(mmc->id) : "", 
	  mms_message_type_to_cstr(mtype), 
	  octstr_get_cstr(from), octstr_get_cstr(to));

     mms = mms_tobinary(m);
     
     add_multipart_form_field(form_data, "to", "text/plain", NULL, to);
     add_multipart_form_field(form_data, "from", "text/plain", NULL, from);
     add_multipart_form_field(form_data, "mms", "application/vnd.wap.mms-message", NULL, mms);

     
     rh = mime_entity_headers(form_data);
     body = mime_entity_body(form_data);

     hstatus = mmsbox_url_fetch_content(HTTP_METHOD_POST, mmc->mmsc_url, rh, body, &ph, &rbody);

     if (http_status_class(hstatus) != HTTP_STATUS_SUCCESSFUL) {
	  *error = octstr_format("Failed to contact MMC[url=%S] => HTTP returned status = %d !",
				 mmc->mmsc_url, hstatus);
     } else {
	  ret = rbody ? octstr_duplicate(rbody) : NULL;
	  if (ret)
	       octstr_strip_blanks(ret);
     }
     
     *retry = (ret == NULL && (http_status_class(hstatus) == HTTP_STATUS_SERVER_ERROR || hstatus < 0));

     if (ret)
	  mms_log2("Sent", from, to, -1, ret, NULL, mmc->id, "MMSBox", NULL, NULL);

     http_destroy_headers(rh);
     octstr_destroy(body);
     http_destroy_headers(ph);
     octstr_destroy(rbody);
     octstr_destroy(mms);
     mime_entity_destroy(form_data);
     
     return ret;
}
Пример #2
0
static void start_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;
     

     info(0, "mms2mobile.startpush: notification to %s\n", octstr_get_cstr(rcpt_to));
     
     if (!rcpt_to) {
	  error(0, "mobilesender: Queue entry %s has no recipient address!", e->xqfname);
	  goto done;
     } else
	  to = octstr_duplicate(rcpt_to);
     

     ct++;    
     octstr_append_char(pduhdr, ct);  /* Pushd id */
     octstr_append_char(pduhdr, 0x06); /* PUSH */

     
#if 1
     octstr_append_char(pduhdr, 1 + 1 + 1);
     octstr_append_char(pduhdr, 0xbe); /* content type. */     
#else
     octstr_append_char(pduhdr, 
			1 + 1 + sizeof "application/vnd.wap.mms-message"); /*header length. */     
     octstr_append_cstr(pduhdr, "application/vnd.wap.mms-message");
     octstr_append_char(pduhdr, 0x0); /* string terminator. */
#endif
     octstr_append_char(pduhdr, 0xaf); /* push application ID header and value follows. */
     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",	
			      settings->sendsms_url, pduhdr, s, to);     
	  
	  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);
	  	  
	  http_destroy_headers(pheaders);
	  octstr_destroy(url);
     } else { /* An IP Address: Send packet, forget. */
	  Octstr *addr = udp_create_address(to, WAPPUSH_PORT);
	  int sock = udp_client_socket();
	  
	  if (sock > 0) {
	       MmsEnvelopeTo *xto = gwlist_get(e->to,0);
	       octstr_append(pduhdr, s);
#if 0
	       octstr_dump(pduhdr, 0);
#endif
	       udp_sendto(sock, pduhdr, addr);
	       close(sock); /* ?? */      
	       mms_log2("Notify", octstr_imm("system"), to, 
			-1, e ? e->msgId : NULL, 
			NULL, NULL, "MM1", NULL,NULL);
	       e = update_env_success(e, xto);
	  } else {
	       e = update_env_failed(e);
	       error(0, "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);
}
Пример #3
0
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) {
	       error(0, "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 {
	       error(0, "mobilesender: Queue entry %s has no recipient address!", env->xqfname);
	       goto push_failed;
	  }
	  
	  info(0, "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. 
						*/ 
	       
	       error(0, "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;        
}
Пример #4
0
static Octstr  *mm7eaif_send(MmscGrp *mmc, Octstr *from, Octstr *to, 
			     Octstr *transid,
			     char *vasid,
			     List *hdrs,
			     MmsMsg *m, Octstr **error,
			     int *retry)
{
     Octstr *ret = NULL, *resp = NULL;
     int mtype = mms_messagetype(m);
     int hstatus = HTTP_OK;
     List *rh = http_create_empty_headers(), *ph = NULL;
     Octstr *body = NULL, *rbody = NULL, *xver = NULL; 
     char *msgtype;

     
     mms_info(0, "MM7", mmc->id,  "MMSBox: Send [eaif] to MMC[%s], msg type [%s], from %s, to %s", 
	  mmc ? octstr_get_cstr(mmc->id) : "", 
	  mms_message_type_to_cstr(mtype), 
	  octstr_get_cstr(from), octstr_get_cstr(to));

     http_header_remove_all(rh, "X-Mms-Allow-Adaptations");	
     http_header_add(rh, "X-NOKIA-MMSC-To", octstr_get_cstr(to));
     http_header_add(rh, "X-NOKIA-MMSC-From", octstr_get_cstr(from));

     xver = octstr_format(EAIF_VERSION, mmc->ver.major, mmc->ver.minor1);
     http_header_add(rh, "X-NOKIA-MMSC-Version", octstr_get_cstr(xver));
     octstr_destroy(xver);

     if (mtype == MMS_MSGTYPE_SEND_REQ || 
	 mtype == MMS_MSGTYPE_RETRIEVE_CONF) {
	  msgtype = "MultiMediaMessage";
	  mms_make_sendreq(m); /* ensure it is a sendreq. */
     } else if (mtype == MMS_MSGTYPE_DELIVERY_IND)
	  msgtype = "DeliveryReport";
     else
	  msgtype = "ReadReply";
     http_header_add(rh, "X-NOKIA-MMSC-Message-Type", msgtype);

     if (hdrs)
	  http_header_combine(rh, hdrs);  /* If specified, then update and pass on. */

     http_header_add(rh, "Content-Type", "application/vnd.wap.mms-message");

     /* Patch the message FROM and TO fields. */
     mms_replace_header_value(m, "From", octstr_get_cstr(from));
     mms_replace_header_value(m, "To", octstr_get_cstr(to));
     mms_replace_header_value(m,"X-Mms-Transaction-ID",
			      transid ? octstr_get_cstr(transid) : "000");
     body = mms_tobinary(m);	       

     hstatus = mmsbox_url_fetch_content(HTTP_METHOD_POST, mmc->mmsc_url, rh, body, &ph, &rbody);

     if (http_status_class(hstatus) != HTTP_STATUS_SUCCESSFUL) {
	  *error = octstr_format("Failed to contact MMC[url=%S] => HTTP returned status = %d !",
				 mmc->mmsc_url, hstatus);
     } else {
	  MmsMsg *mresp = rbody ? mms_frombinary(rbody, octstr_imm("anon@anon")) : NULL;
	  
	  resp = octstr_imm("Ok");
	  if (mresp && mms_messagetype(mresp) == MMS_MSGTYPE_SEND_CONF)
	       resp = mms_get_header_value(mresp, octstr_imm("X-Mms-Response-Status"));	  
	  if (octstr_case_compare(resp, octstr_imm("ok")) != 0)
	       hstatus = HTTP_STATUS_SERVER_ERROR; /* error. */
	  else if (mresp)
	       ret = mms_get_header_value(mresp, octstr_imm("Message-ID"));

	  mms_destroy(mresp);
     }

     if (hstatus < 0)
	  ret = NULL; 
     else {
	  hstatus = http_status_class(hstatus);	  
	  if (hstatus == HTTP_STATUS_SERVER_ERROR ||
	      hstatus == HTTP_STATUS_CLIENT_ERROR) 
	       ret = NULL;
	  else if (!ret) 
	       ret = http_header_value(ph, octstr_imm("X-Nokia-MMSC-Message-Id"));
     }
     *retry = (ret == NULL && (hstatus == HTTP_STATUS_SERVER_ERROR || hstatus < 0));

     if (ret)
	  mms_log2("Sent", from, to, -1, ret, NULL, mmc->id, "MMSBox", NULL, NULL);

#if 0
     mms_info(0, "MM7", mmc->id,"Sent to MMC[%s], code=[%d], resp=[%s] msgid [%s]", 
	  octstr_get_cstr(mmc->id), 
	  hstatus, resp ? octstr_get_cstr(resp) : "(none)", ret ? octstr_get_cstr(ret) : "(none)");
#endif 

     http_destroy_headers(rh);
     octstr_destroy(body);
     http_destroy_headers(ph);
     octstr_destroy(rbody);

     octstr_destroy(resp);
     return ret;
}
Пример #5
0
/* XXX Returns msgid in mmsc or NULL if error. Caller uses this for DLR issues. 
 * Caller must make sure throughput issues
 * are observed!
 * Don't remove from queue on fail, just leave it to expire. 
 */
static Octstr *mm7soap_send(MmscGrp *mmc, Octstr *from, Octstr *to, 
			    Octstr *transid,
			    Octstr *linkedid, 
			    char *vasid,
			    Octstr *service_code,
			    List *hdrs,
			    MmsMsg *m, Octstr **error,
			    List **errl,
			    int *retry)
{
     Octstr *ret = NULL;
     int mtype = mms_messagetype(m);
     int hstatus = HTTP_OK, tstatus  = -1;
     List *xto = gwlist_create();
     MSoapMsg_t *mreq = NULL, *mresp = NULL;
     List *rh = NULL, *ph = NULL;
     Octstr *body = NULL, *rbody = NULL, *url = NULL; 
     Octstr *s;
     char *xvasid = vasid ? vasid : (mmc->default_vasid ? octstr_get_cstr(mmc->default_vasid) : NULL);

     mms_info(0, "MM7", mmc->id,  "MMSBox: Send[soap] to MMSC[%s], msg type [%s], from %s, to %s", 
	  mmc->id ? octstr_get_cstr(mmc->id) : "", 
	  mms_message_type_to_cstr(mtype), 
	  octstr_get_cstr(from), octstr_get_cstr(to));    
     
     gwlist_append(xto, to);
     
     if ((mreq = mm7_mmsmsg_to_soap(m, (mmc == NULL || mmc->no_senderaddress == 0) ? from : NULL, 
				    xto, transid,
				    service_code, 
				    linkedid, 
				    1, octstr_get_cstr(mmc->vasp_id), xvasid, NULL, 0,/* UA N/A on this side. */
				    hdrs)) == NULL) {
	  *error = octstr_format("Failed to convert Msg[%S] 2 SOAP message!",
				 mms_message_type_to_string(mtype));
	  goto done1;
     }
     
     if (mm7_soapmsg_to_httpmsg(mreq, &mmc->ver, &rh, &body) < 0) {
	  *error = octstr_format("Failed to convert SOAP message to HTTP Msg!");
	  goto done1;
     } 

     if (hdrs)
	  http_header_combine(rh, hdrs);  /* If specified, then update and pass on. */
     
     hstatus = mmsbox_url_fetch_content(HTTP_METHOD_POST, mmc->mmsc_url, rh, body, &ph,&rbody);     
     if (http_status_class(hstatus) != HTTP_STATUS_SUCCESSFUL) {
	  *error = octstr_format("Failed to contact MMC[url=%S] => HTTP returned status=[%d]!",
				 mmc->mmsc_url, hstatus);
	  goto done1;
     }
     
     if ((mresp = mm7_parse_soap(ph, rbody)) == NULL) {
	  *error = octstr_format("Failed to parse MMSC[url=%S, id=%S]  response!",
				 mmc->mmsc_url,  mmc->id);
	  goto done1;
     } 

     if (errl) { /* Pick up status stuff -- for DLR */
	  if (*errl == NULL)
	       *errl = http_create_empty_headers();
	  if ((s = mm7_soap_header_value(mresp, octstr_imm("StatusText"))) != NULL) {	  
	       http_header_add(*errl, "X-Mbuni-StatusText", octstr_get_cstr(s));
	       octstr_destroy(s);
	  }

	  if ((s = mm7_soap_header_value(mresp, octstr_imm("Details"))) != NULL) {	  
	       http_header_add(*errl, "X-Mbuni-StatusDetails", octstr_get_cstr(s));
	       octstr_destroy(s);
	  }
     }

     /* Now look at response code and use it to tell you what you want. */
     if ((s = mm7_soap_header_value(mresp, octstr_imm("StatusCode"))) != NULL) {
	  tstatus = atoi(octstr_get_cstr(s));
	  octstr_destroy(s);
     } else if ((s = mm7_soap_header_value(mresp, octstr_imm("faultstring"))) != NULL) {
	  tstatus = atoi(octstr_get_cstr(s));
	  octstr_destroy(s);
     } else
	  tstatus = MM7_SOAP_FORMAT_CORRUPT; 
     

     if (!MM7_SOAP_STATUS_OK(tstatus) && tstatus != MM7_SOAP_COMMAND_REJECTED) {
	  Octstr *detail =  mm7_soap_header_value(mresp, octstr_imm("Details"));
	  char *tmp = (char *)mms_soap_status_to_cstr(tstatus);
	  if (detail == NULL)
	       detail = mm7_soap_header_value(mresp, octstr_imm("faultcode"));
	  ret = NULL;
	  mms_info(0, "MM7", mmc->id, "Send to MMSC[%s], failed, code=[%d=>%s], detail=[%s]", 
	       mmc ? octstr_get_cstr(mmc->id) : "", 
	       tstatus, tmp ? tmp : "", 
	       detail ? octstr_get_cstr(detail) : "");

	  *error = octstr_format("Failed to deliver to MMC[url=%S, id=%S], status=[%d=>%s]!",
				 mmc->mmsc_url, 
				 mmc->id,
				 tstatus, 
				 tmp ? tmp : "");	  
	  octstr_destroy(detail);	  
     } else {	  
	  ret = mm7_soap_header_value(mresp, octstr_imm("MessageID"));	  
	  mms_info(0, "MM7", NULL, "Sent to MMC[%s], code=[%d=>%s], msgid=[%s]", octstr_get_cstr(mmc->id), 
	       tstatus, mms_soap_status_to_cstr(tstatus), ret ? octstr_get_cstr(ret) : "(none)");
     }


     if (ret)
	  mms_log2("Sent", from, to, -1, ret, NULL, mmc->id, "MMSBox", NULL, NULL);
done1:
     *retry = (ret == NULL && (!MM7_SOAP_CLIENT_ERROR(tstatus) || tstatus < 0));
     
     mm7_soap_destroy(mreq);
     mm7_soap_destroy(mresp);	  
     http_destroy_headers(rh);
     octstr_destroy(body);
     http_destroy_headers(ph);
     octstr_destroy(rbody);
     octstr_destroy(url);

     gwlist_destroy(xto, NULL);

     return ret;
}
Пример #6
0
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;     
     
     if (!rcpt_to) {
	  mms_error(0, "MM1", NULL, "mobilesender: Queue entry %s has no recipient address!", e->xqfname);
	  goto done;
     } else
	  to = octstr_duplicate(rcpt_to);
     

     ct++;    
     octstr_append_char(pduhdr, ct);  /* Pushd id */
     octstr_append_char(pduhdr, 0x06); /* PUSH */

     
#if 1
     octstr_append_char(pduhdr, 1 + 1 + 1);
     octstr_append_char(pduhdr, 0xbe); /* content type. */     
#else
     octstr_append_char(pduhdr, 
			1 + 1 + strlen("application/vnd.wap.mms-message") + 1); /*header length. */     
     octstr_append_cstr(pduhdr, "application/vnd.wap.mms-message");
     octstr_append_char(pduhdr, 0x0); /* string terminator. */
#endif
     octstr_append_char(pduhdr, 0xaf); /* push application ID header and value follows. */
     octstr_append_char(pduhdr, 0x84); /* ... */

     s = mms_tobinary(msg);
     if (isphonenum) {
	  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);	       
	  
	  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(e,xto,0);
	  } else {	 /* Successful push. */      

	       mms_log2("Notify", octstr_imm("system"), to, 
			-1, e ? e->msgId : NULL, NULL, NULL, "MM1", NULL,NULL);
	       e = update_env(e, xto, 1);	       
	  }     
	  
	  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);
	  int sock = udp_client_socket();
	  MmsEnvelopeTo *xto = gwlist_get(e->to,0);
	  
	  if (sock > 0) {
	       octstr_append(pduhdr, s);
#if 0
	       octstr_dump(pduhdr, 0);
#endif
	       udp_sendto(sock, pduhdr, addr);
	       close(sock); /* ?? */      
	       mms_log2("Notify", octstr_imm("system"), to, 
			-1, e ? e->msgId : NULL, 
			NULL, NULL, "MM1", NULL,NULL);
	       e = update_env(e, xto, 1);
	  } else {
	       e = update_env(e, xto, 0);
	       mms_error(0,  "MM1", NULL, "push to %s:%d failed: %s", 
			 octstr_get_cstr(to), WAPPUSH_PORT, strerror(errno));
	  }
	  octstr_destroy(addr);
     }
 done:
     octstr_destroy(to);
     octstr_destroy(pduhdr);
     octstr_destroy(s);
     
     if (e)
	  settings->qfs->mms_queue_free_env(e);     
}