📄 mms_mm7soap.c
字号:
*subject = http_header_value(m->envelope, octstr_imm("Subject"));
*vasid = http_header_value(m->envelope, octstr_imm("VASID"));
if ((s = http_header_value(m->envelope, octstr_imm("SenderAddress"))) == NULL)
s = http_header_value(m->envelope, octstr_imm("Sender"));
if (s && octstr_get_char(s, 0) == '+')
octstr_delete(s, 0, 2);
else if (s) {
octstr_destroy(s);
s = NULL;
}
*sender = s;
if (expiry_t) {
Octstr *s = http_header_value(m->envelope, octstr_imm("ExpiryDate"));
*expiry_t = -1;
if (s) {
*expiry_t = date_parse_http(s);
octstr_destroy(s);
}
}
if (delivery_t) {
Octstr *s = http_header_value(m->envelope, octstr_imm("EarliestDeliveryTime"));
*delivery_t = -1;
if (s) {
*delivery_t = date_parse_http(s);
octstr_destroy(s);
}
}
return 0;
}
MmsMsg *mm7_soap_to_mmsmsg(MSoapMsg_t *m, Octstr *from)
{
int msgtype = mm7_msgtype(m);
MmsMsg *msg = NULL;
Octstr *s, *f, *p, *q, *r;
List *l;
time_t t;
switch(msgtype) {
case MM7_TAG_DeliverReq:
case MM7_TAG_SubmitReq:
case MM7_TAG_ReplaceReq:
msg = mms_frommime(m->msg);
if (!msg)
break;
mms_remove_headers(msg, "Content-ID"); /* not necessary, but... */
/* Put in some headers... */
if (from)
mms_replace_header_value(msg, "From", octstr_get_cstr(from));
if ((s = http_header_value(m->envelope, octstr_imm("MessageClass"))) != NULL) {
if (mms_string_to_message_class(s) >= 0)
mms_replace_header_value(msg, "X-Mms-Message-Class", octstr_get_cstr(s));
octstr_destroy(s);
}
if ((s = http_header_value(m->envelope, octstr_imm("Priority"))) != NULL) {
if (mms_string_to_priority(s) >= 0)
mms_replace_header_value(msg, "X-Mms-Priority", octstr_get_cstr(s));
octstr_destroy(s);
}
if ((s = http_header_value(m->envelope, octstr_imm("DeliveryReport"))) != NULL) {
long x = mms_string_to_boolean_flag(s);
if (x >= 0)
mms_replace_header_value(msg, "X-Mms-Delivery-Report",
(char *)mms_reports_to_cstr(x));
octstr_destroy(s);
}
if ((s = http_header_value(m->envelope, octstr_imm("ReadReply"))) != NULL) {
long x = mms_string_to_boolean_flag(s);
if (x >= 0)
mms_replace_header_value(msg, "X-Mms-Read-Report",
(char *)mms_reports_to_cstr(x));
octstr_destroy(s);
}
if ((s = http_header_value(m->envelope, octstr_imm("TimeStamp"))) != NULL) {
mms_replace_header_value(msg, "Date", octstr_get_cstr(s));
octstr_destroy(s);
}
if ((s = http_header_value(m->envelope, octstr_imm("ExpiryDate"))) != NULL) {
mms_replace_header_value(msg, "X-Mms-Expiry", octstr_get_cstr(s));
octstr_destroy(s);
}
if ((s = http_header_value(m->envelope, octstr_imm("Subject"))) != NULL) {
mms_replace_header_value(msg, "Subject", octstr_get_cstr(s));
octstr_destroy(s);
}
if ((s = http_header_value(m->envelope, octstr_imm("MessageID"))) != NULL) {
mms_replace_header_value(msg, "Message-ID", octstr_get_cstr(s));
octstr_destroy(s);
}
/* Put in recipient list. XXX - really?? */
l = gwlist_create();
get_rcptvalues(l, m->envelope, "To");
mms_replace_header_values(msg, "To", l);
gwlist_destroy(l, (gwlist_item_destructor_t *)octstr_destroy);
l = gwlist_create();
get_rcptvalues(l, m->envelope, "Cc");
mms_replace_header_values(msg, "Cc", l);
gwlist_destroy(l, (gwlist_item_destructor_t *)octstr_destroy);
/* XXX - we ignore reply charging, etc. */
break;
case MM7_TAG_DeliveryReportReq: /* should we bother?? Can these ever be handled here?? */
case MM7_TAG_ReadReplyReq:
s = http_header_value(m->envelope, octstr_imm("MessageID"));
if ((p = http_header_value(m->envelope, octstr_imm("To"))) != NULL &&
octstr_get_char(p, 0) == '+')
octstr_delete(p, 0, 2);
else if (p) {
octstr_destroy(p);
p = NULL;
}
if ((f = http_header_value(m->envelope, octstr_imm("From"))) != NULL &&
octstr_get_char(f, 0) == '+')
octstr_delete(f, 0, 2);
else if (f) {
octstr_destroy(f);
f = NULL;
}
if ((q = http_header_value(m->envelope, octstr_imm("Date"))) != NULL)
t = date_parse_http(q);
else
t = time(NULL);
r = http_header_value(m->envelope, octstr_imm("MMStatus"));
if (msgtype == MM7_TAG_DeliveryReportReq &&
p && r && mms_string_to_status(r) >= 0)
msg = mms_deliveryreport(s ? s : octstr_imm("0000"), p, t, r);
else if (msgtype == MM7_TAG_ReadReplyReq &&
f && p && r && mms_string_to_read_status(r) >= 0)
msg = mms_readreport(s ? s : octstr_imm("0000"),
f, p, t, r);
if (s)
octstr_destroy(s);
if (p)
octstr_destroy(p);
if (r)
octstr_destroy(r);
if (f)
octstr_destroy(f);
break;
default:
break;
}
return msg;
}
void mm7_soap_destroy(MSoapMsg_t *m)
{
if (m == NULL) return;
http_destroy_headers(m->envelope);
if (m->msg)
mime_entity_destroy(m->msg);
gw_free(m);
}
static MSoapMsg_t *mm7_soap_create(int msgtype, Octstr *otransid)
{
MSoapMsg_t *m = gw_malloc(sizeof *m);
m->envelope = http_create_empty_headers();
m->msg = NULL;
http_header_add(m->envelope, "MessageType", (char *)mms_mm7tag_to_cstr(msgtype));
/* http_header_add(m->envelope, "MM7Version", MM7_DEFAULT_VERSION); */
http_header_add(m->envelope, "TransactionID",
otransid ? octstr_get_cstr(otransid) : "0000");
return m;
}
MSoapMsg_t *mm7_mmsmsg_to_soap(MmsMsg *msg, Octstr *from, List *xto,
Octstr *transid, Octstr *srvcode,
Octstr *linkedid, int isclientside,
char *vaspid, char *vasid)
{
int i, n, mtype = mms_messagetype(msg);
MSoapMsg_t *m = NULL;
List *headers;
Octstr *xfrom = (from != NULL) ? octstr_format("+ %S", from) : NULL, *s;
switch(mtype) {
case MMS_MSGTYPE_SEND_REQ:
case MMS_MSGTYPE_RETRIEVE_CONF:
m = mm7_soap_create(isclientside ? MM7_TAG_SubmitReq : MM7_TAG_DeliverReq,
transid);
m->msg = mms_tomime(msg,1);
for (i = 0, n = xto ? gwlist_len(xto) : 0; i < n; i++) { /* Add recipients. */
Octstr *xx = octstr_format("+ %S", gwlist_get(xto, i));
http_header_add(m->envelope, "To",
octstr_get_cstr(xx));
octstr_destroy(xx);
}
if (srvcode)
http_header_add(m->envelope,
isclientside ? "ServiceCode" : "MMSRelayServerID",
octstr_get_cstr(srvcode));
if (linkedid)
http_header_add(m->envelope, "LinkedID", octstr_get_cstr(linkedid));
if (xfrom)
http_header_add(m->envelope,
isclientside ? "SenderAddress" : "Sender",
octstr_get_cstr(xfrom));
if ((s = mms_get_header_value(msg, octstr_imm("Date"))) != NULL) {
http_header_add(m->envelope, "TimeStamp", octstr_get_cstr(s));
octstr_destroy(s);
}
if (isclientside) {
if (vaspid)
http_header_add(m->envelope, "VASPID", vaspid);
if (vasid)
http_header_add(m->envelope, "VASID", vasid);
if ((s = mms_get_header_value(msg, octstr_imm("X-Mms-Message-Class"))) != NULL) {
http_header_add(m->envelope, "MessageClass", octstr_get_cstr(s));
octstr_destroy(s);
}
if ((s = mms_get_header_value(msg, octstr_imm("X-Mms-Expiry"))) != NULL) {
http_header_add(m->envelope, "ExpiryDate", octstr_get_cstr(s));
octstr_destroy(s);
}
if ((s = mms_get_header_value(msg, octstr_imm("X-Mms-Delivery-Report"))) != NULL) {
char *val = (octstr_case_compare(s, octstr_imm("Yes")) == 0) ?
"true" : "false";
http_header_add(m->envelope, "DeliveryReport", val);
octstr_destroy(s);
}
if ((s = mms_get_header_value(msg, octstr_imm("X-Mms-Read-Report"))) != NULL) {
char *val = (octstr_case_compare(s, octstr_imm("Yes")) == 0) ?
"true" : "false";
http_header_add(m->envelope, "ReadReply", val);
octstr_destroy(s);
}
/* Track adaptations stuff -- Vincent */
if ((s = mms_get_header_value(msg, octstr_imm("X-Mms-Allow-Adaptations"))) != NULL) {
char *val = (octstr_case_compare(s, octstr_imm("true")) == 0) ?
"true" : "false";
http_header_add(m->envelope, "allowAdaptations", val);
octstr_destroy(s);
}
}
if ((s = mms_get_header_value(msg, octstr_imm("X-Mms-Priority"))) != NULL) {
http_header_add(m->envelope, "Priority", octstr_get_cstr(s));
octstr_destroy(s);
}
if ((s = mms_get_header_value(msg, octstr_imm("Subject"))) != NULL) {
http_header_add(m->envelope, "Subject", octstr_get_cstr(s));
octstr_destroy(s);
}
/* Should we bother to strip message part of headers??? */
headers = mime_entity_headers(m->msg);
http_header_remove_all(headers, "Subject");
http_header_remove_all(headers, "X-Mms-Message-Type");
http_header_remove_all(headers, "X-Mms-Message-Version");
http_header_remove_all(headers, "X-Mms-Allow-Adaptations");
http_header_remove_all(headers, "From");
http_header_remove_all(headers, "To");
http_header_remove_all(headers, "Cc");
http_header_remove_all(headers, "Bcc");
mime_replace_headers(m->msg, headers);
http_destroy_headers(headers);
break;
case MMS_MSGTYPE_READ_ORIG_IND:
case MMS_MSGTYPE_DELIVERY_IND:
m = mm7_soap_create((mtype == MMS_MSGTYPE_READ_ORIG_IND) ?
MM7_TAG_ReadReplyReq : MM7_TAG_DeliveryReportReq,
transid);
if (xfrom)
http_header_add(m->envelope, "Sender", octstr_get_cstr(xfrom));
if (xto && gwlist_len(xto) > 0) {
Octstr *xx = octstr_format("+ %S", gwlist_get(xto, 0));
http_header_add(m->envelope, "To",
octstr_get_cstr(xx));
octstr_destroy(xx);
}
s = mms_get_header_value(msg, octstr_imm("Message-ID"));
if (!s)
s = octstr_duplicate(transid);
http_header_add(m->envelope, "MessageID", octstr_get_cstr(s));
octstr_destroy(s);
if ((s = mms_get_header_value(msg, octstr_imm("Date"))) != NULL) {
http_header_add(m->envelope,
(mtype == MMS_MSGTYPE_READ_ORIG_IND) ? "TimeStamp" : "Date",
octstr_get_cstr(s));
octstr_destroy(s);
}
if ((s = mms_get_header_value(msg,
(mtype == MMS_MSGTYPE_READ_ORIG_IND) ?
octstr_imm("X-Mms-Read-Status") :
octstr_imm("X-Mms-Status") )) != NULL) {
http_header_add(m->envelope, "MMStatus", octstr_get_cstr(s));
octstr_destroy(s);
}
break;
default:
break;
}
if (xfrom)
octstr_destroy(xfrom);
return m;
}
MSoapMsg_t *mm7_make_resp(MSoapMsg_t *mreq, int status, Octstr *msgid, int isclientside)
{
int mtype = mreq ? mm7_msgtype(mreq) : -1;
Octstr *transid;
MSoapMsg_t *mresp;
char scode[64];
unsigned char *statustxt = mms_soap_status_to_cstr(status);
transid = mreq ? http_header_value(mreq->envelope, octstr_imm("TransactionID")) : NULL;
if (!MM7_SOAP_STATUS_OK(status) || mtype < 0)
mresp = mm7_soap_create(isclientside ? MM7_TAG_VASPErrorRsp : MM7_TAG_RSErrorRsp, transid);
else
mresp = mm7_soap_create(mtype + 1, transid);
sprintf(scode, "%d", status);
http_header_add(mresp->envelope, "Status", ""); /* So that we get output. */
http_header_add(mresp->envelope, "StatusCode", scode);
http_header_add(mresp->envelope, "StatusText", statustxt ? (char *)statustxt : "Error");
if (msgid && mtype == MM7_TAG_SubmitReq) /* only allow MessageID in submitRsp */
http_header_add(mresp->envelope, "MessageID", octstr_get_cstr(msgid));
if (!MM7_SOAP_STATUS_OK(status)) {
http_header_add(mresp->envelope, "Fault", ""); /* do we really need these? XXX */
http_header_add(mresp->envelope, "faultcode", "" SOAP_ENV ":Server");
http_header_add(mresp->envelope, "faultstring", "Server error");
}
octstr_destroy(transid);
return mresp;
}
Octstr *mm7_soap_header_value(MSoapMsg_t *m, Octstr *header)
{
return http_header_value(m->envelope, header);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -