📄 soapimplement.cpp
字号:
#include "stdafx.h"
#include "soapH.h"
#include "SoapImplement.h"
#include "..\mmsparser.h"
#include "..\mmscontent.h"
#include "..\log.h"
#include "..\mailcoder.h"
#include "..\resource.h"
#include "..\mmsdidodlg.h"
#define DO_NOSENSE_TRIMING
extern Logger *mplog;
extern CMmsdidoDlg *mainDlg;
#include <process.h>
SOAP_NMAC struct Namespace namespaces[] =
{
{"SOAP-ENV", "http://schemas.xmlsoap.org/soap/envelope/", "http://www.w3.org/*/soap-envelope"},
{"SOAP-ENC", "http://schemas.xmlsoap.org/soap/encoding/", "http://www.w3.org/*/soap-encoding"},
{"xsi", "http://www.w3.org/2001/XMLSchema-instance", "http://www.w3.org/*/XMLSchema-instance"},
{"xsd", "http://www.w3.org/2001/XMLSchema", "http://www.w3.org/*/XMLSchema"},
{"mm7", "http://www.3gpp.org/ftp/specs/archive/23_series/23.140/schema/REL-5-MM7-1-0"},
{NULL, NULL}
};
extern CPtrList *rspList;
void soap_thread(void *arg);
int add_msg_node(char *s, MmsListNode *msg_node);
CSoapImp::CSoapImp (CDialog *dlg)
{
parentDlg = dlg;
rsp_thread_stop = false;
rspList = new CPtrList();
}
CSoapImp::~CSoapImp ()
{
}
void CSoapImp::stop()
{
rsp_thread_stop = true;
soap_end_flag = 0;
//CSingleLock SingleLock(&Mutex);
//SingleLock.Lock();
if (mysoap) soap_end(mysoap);
if (mysoap) soap_destroy(mysoap);
if (mysoap) soap_done(mysoap);
// wait till the soap thread ended.
while (soap_end_flag == 0)
{
Sleep(10);
}
delete mysoap;
mysoap = NULL;
}
void CSoapImp::start()
{
int m;
rsp_thread_stop = false;
mysoap = soap_new();
soap_init(mysoap);
mysoap->bind_flags |= SO_REUSEADDR;
m = soap_bind(mysoap, NULL, ((CMmsdidoDlg *)parentDlg)->get_mm7_port(), 100);
if (m < 0)
{
mplog->write(LOG_LEVEL_ERROR, __FILE__, __LINE__,
"Soap binding, Failed, Try another Port.");
parentDlg->MessageBox("Soap binding, Failed, Try another Port.");
return;
}
_beginthread(soap_thread, 0, this);
}
void soap_thread(void *arg)
{
int s;
CMmsdidoDlg *pDlg;
CSoapImp *pSoapImp;
pSoapImp = (CSoapImp *)arg;
pDlg = (CMmsdidoDlg *)pSoapImp->parentDlg;
while(!pSoapImp->rsp_thread_stop)
{
s = soap_accept(pSoapImp->mysoap);
if (s < 0)
{
soap_print_fault(pSoapImp->mysoap, stderr);
break;
}
soap_serve(pSoapImp->mysoap);
soap_destroy(pSoapImp->mysoap);
soap_end(pSoapImp->mysoap);
}
soap_done(pSoapImp->mysoap);
// mark of soap thread ended
pSoapImp->soap_end_flag = 1;
}
////////////////////////////////////////////////////////////////////////////////
//
// Remote MM7 method interfaces
//
////////////////////////////////////////////////////////////////////////////////
int mm7__SubmitReq(struct soap *soap, char *MM7Version,
struct SenderIdentification *SenderIdentification,
struct Recipients *Recipients,
char *ServiceCode,
char *LinkedID,
char *MessageClass,
char *TimeStamp,
struct ReplyCharging *ReplyCharging,
char *EarliestDeliveryTime,
char *ExpiryDate,
bool DeliverReport,
bool ReadReply,
char *Priority,
char *Subject,
bool Adaption,
char *ChargedParty,
bool DistributionIndicator,
char *FeeType,
float FeeCode,
struct AttachmentList *Content,
struct SubmitRsp &SubmitRsp)
{
add_msg_node("mm7__SubmitReq arrived.", NULL);
return SOAP_OK;
};
int mm7__CancelReq(struct soap *soap, char *MM7Version,
struct SenderIdentification *SenderIdentification,
char *MessageID,
struct CancelRsp &CancelRsp)
{
return SOAP_OK;
};
int mm7__ReplaceReq(struct soap *soap, char *MM7Version,
struct SenderIdentification *SenderIdentification,
char *MessageID,
char *ServiceCode,
char *TimeStamp,
char *EarliestDeliveryTime,
bool ReadReply,
bool Adaption,
bool DistributionIndicator,
struct AttachmentList *Content,
struct ReplaceRsp &ReplaceRsp)
{
return SOAP_OK;
};
int mm7__DeliverReq(struct soap *soap, char *MM7Version,
char *MMSRelayServerID,
char *LinkedID,
struct groupAddress *Sender,
struct Recipients *Recipients,
char *TimeStamp,
char *ReplyChargingID,
char *Priority,
char *Subject,
struct AttachmentList *Content,
struct DeliverRsp &DeliverRsp)
{
MmsListNode *pNode;
CPtrList *attachement_list, *body_item_list;
MmsItemListNode *pItemNode;
char *sub_final, *bin_buf, *file_buf;
int dst_len, file_size;
pNode = new MmsListNode;
attachement_list = new CPtrList;
body_item_list = new CPtrList;
pNode->item_list = NULL;
pNode->internal_id = pNode->internal_id = time(NULL) * 1000 + rand()%1000;
pNode->body_item_list = body_item_list;
// Add relay server id
if (MMSRelayServerID)
{
pItemNode = MmsParser::create_new_itemnode(MMS_MSGTYPE_MM7_MSG,
"MMSRelayServerID", MMSRelayServerID);
body_item_list->AddTail(pItemNode);
}
// Add Linked ID
if (LinkedID)
{
pItemNode = MmsParser::create_new_itemnode(MMS_MSGTYPE_MM7_MSG,
"LinkedID", LinkedID);
body_item_list->AddTail(pItemNode);
}
// Add time stamp
if (TimeStamp)
{
pItemNode = MmsParser::create_new_itemnode(MMS_MSGTYPE_MM7_MSG,
"TimeStamp", TimeStamp);
body_item_list->AddTail(pItemNode);
}
// Add ReplyChargingID
if (ReplyChargingID)
{
pItemNode = MmsParser::create_new_itemnode(MMS_MSGTYPE_MM7_MSG,
"ReplyChargingID", ReplyChargingID);
body_item_list->AddTail(pItemNode);
}
// Add Priority
if (Priority)
{
pItemNode = MmsParser::create_new_itemnode(MMS_MSGTYPE_MM7_MSG,
"Priority", Priority);
body_item_list->AddTail(pItemNode);
}
// Add Subject
if (Subject)
{
MmsParser::string_decode(Subject, strlen(Subject), sub_final, UTF_8);
pItemNode = MmsParser::create_new_itemnode(MMS_HEAD_SUBJECT, "Subject",
sub_final);
body_item_list->AddTail(pItemNode);
}
// Deal with Attachements list
pNode->attachments_list = attachement_list;
xsd__base64Binary *dime_file;
int i;
MmsAttachedFileNode *pNewFileNode;
char default_name[MAX_SIZE_FILENAME];
for (i = 0; i < Content->__size; i++)
{
sprintf(default_name, "default%d.dat", i);
dime_file = &(Content->__ptr[i]);
pNewFileNode = new MmsAttachedFileNode;
file_buf = (char *)dime_file->__ptr;
file_size = dime_file->__size;
strcpy(pNewFileNode->content_id,
dime_file->id?dime_file->id:"NO");
strcpy(pNewFileNode->content_type_str,
dime_file->type?dime_file->type:"null");
strcpy(pNewFileNode->file_name,
dime_file->options?dime_file->options:default_name);
pNewFileNode->header_size = 0;
bin_buf = file_buf;
dst_len = file_size;
/******
* Temporary operation
***************/
#ifdef DO_NOSENSE_TRIMING
bool base64_flag = false;
if (strstr(file_buf, "base64"))
base64_flag = true;
MmsContent::trime_content_head(file_buf,
(unsigned int &)dst_len);
if (base64_flag)
{
// Base64 decode
dst_len = CMmsCoder::Base64DecodeSize(file_size);
bin_buf = (char *)malloc(dst_len);
if (bin_buf == NULL)
{
mplog->write(LOG_LEVEL_DEBUG, __FILE__, __LINE__,
"Out of memory.");
}
dst_len = CMmsCoder::base64_decode(file_buf,
file_size, bin_buf);
}
#endif
// Make a new copy of the file buf
file_buf = (char *)malloc(file_size);
if (file_buf == NULL)
return -1;
memcpy(file_buf, bin_buf, file_size);
pNewFileNode->file_buf = file_buf;
pNewFileNode->file_size = dst_len;
#ifdef DO_NOSENSE_TRIMING
if (base64_flag)
free(bin_buf);
#endif
attachement_list->AddTail(pNewFileNode);
}
sprintf(pNode->from_msisdn, "UN");
strcpy(pNode->subject, sub_final);
sprintf(pNode->msg_id, "UN");
pNode->msg_type = MMS_MSGTYPE_MM7_MSG;
pNode->read_reply_flag = 0;
pNode->retrieved_flag = MMS_STATUS_RETRIEVED;
sprintf(pNode->to_msisdn, "UN");
add_msg_node("mm7_DelieverReq arrived.", pNode);
return SOAP_OK;
};
int mm7__DeliveryReportReq(struct soap *soap, char *MM7Version,
char *MMSRelayServerID,
char *MessageID,
struct groupAddress *Recipients,
struct groupAddress *Sender,
char *Date,
char *MMStatus,
char *StatusText,
struct DeliveryReportRsp &DeliveryReportRsp)
{
add_msg_node("mm7__DeliveryReportReq arrived.", NULL);
return SOAP_OK;
};
int mm7__ReadReplyReq(struct soap *soap, char *MM7Version,
char *MMSRelayServerID,
char *MessageID,
struct groupAddress *Recipients,
struct groupAddress *Sender,
char *TimeStamp,
char *MMStatus,
char *StatusText,
struct ReadReplyRsp &ReadReplyRsp)
{
return SOAP_OK;
};
int mm7__RsErrorRsp(struct soap *soap, char *MM7Version, struct Status status,struct ReturnNothing *out)
{
add_msg_node("mm7__RsErrorRsp arrived.", NULL);
return SOAP_OK;
}
int mm7__VASPErrorRsp(struct soap *soap, char *MM7Version, struct Status status,struct ReturnNothing *out)
{
add_msg_node("mm7__VASPErrorRsp arrived.", NULL);
return SOAP_OK;
}
int add_msg_node(char *display_buf, MmsListNode *msg_node)
{
COPYDATASTRUCT pcds;
mplog->write(LOG_LEVEL_DEBUG, __FILE__, __LINE__,
"Add MM7 Msgnode: %s", display_buf);
/****
* Display message. A thread function can not invoke UI controls
* directly.
************/
pcds.dwData = 0;
pcds.lpData = display_buf;
pcds.cbData = strlen(display_buf) + 1;
SendMessage(mainDlg->m_hWnd, WM_COPYDATA,
(WPARAM)mainDlg->m_hWnd, (LPARAM)&pcds);
mainDlg->add_msg_node(msg_node);
mainDlg->fire_display_msg();
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -