-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsmsstorage.cpp
executable file
·80 lines (75 loc) · 1.93 KB
/
smsstorage.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#include "sms.h"
#include "mgrep.h"
using namespace SMS;
using namespace std;
int CSMSStorage::writeSMStoStorage(const char* sourceNo, const char* TargetNo, char* buf, unsigned int buf_size){
initFilter();
if (mgrep_str(buf, buf_size,m_filterBuf)==0) {
return SUCCESS;
}
syslog(LOG_ERR," msg have bad word!");
return ERROR;
}
int CSMSStorage::OnNotify(){
syslog(LOG_ERR, "there is new msg!");
try{
if (getFirstSMSFromStorage()!=0) {
throw runtime_error("Storage is empty");
}
char* buf=NULL;
unsigned int bufLen=0;
unsigned int dataLen=0;
int retCode;
do{
dataLen=bufLen;
syslog(LOG_ERR, "shit1!");
readGettedSMS(buf,&dataLen);
syslog(LOG_ERR, "shit2!");
syslog(LOG_ERR,"buf point: %p dataLen: %d", buf, dataLen);
if (dataLen>bufLen)
{
buf=(char*)realloc(buf, dataLen);
syslog(LOG_ERR,"buf point: %p dataLen: %d", buf, dataLen);
if (buf==NULL){
syslog(LOG_ERR, "alloc memory for sms send error!");
return -1;
}
bufLen=dataLen;
syslog(LOG_ERR, "shit3!");
readGettedSMS(buf,&dataLen);
syslog(LOG_ERR, "shit4!");
if (dataLen>bufLen)
{
syslog(LOG_ERR,"read SMS length error!");
throw runtime_error("read SMS length error!");
}
}
syslog(LOG_ERR, "shit5!");
syslog(LOG_ERR,"buf point: %p", buf);
if ((buf!=NULL) && (dataLen!=0)) {
retCode=m_pSMSPProtocol->Send((SMSMessage *)buf);
} else {
retCode=FAILED;
syslog(LOG_ERR,"buf point is null!");
}
if (retCode!=SUCCESS) {
if (retCode==ERROR) {
backupError();
syslog(LOG_ERR,"send error:(");
} else {
syslog(LOG_ERR,"send failed");
}
} else {
recordSended();
}
syslog(LOG_ERR, "shit6!");
}
while (getNextSMSFromStorage()==0);
free(buf);
} catch(exception e ) {
syslog(LOG_ERR, "Send SMS error: %s", e.what());
}
clearStorage();
set_notifier();
return 0;
}