41 #define _CRT_SECURE_NO_DEPRECATE //do not use windows secure crt 50 #define __FILE_ID__ "messagebox" 168 isosize = (((int)(
_udata).size()) >> (1));
169 isolatin = string(isosize, (
char)0);
171 while (i < isosize) {
172 isolatin[i] = (char)(((u8)
_udata[2*i+1]));
193 unisize = (((int)(
_udata).size()) >> (1));
196 while (i < unisize) {
198 res.push_back(unival);
203 unisize = (int)(
_udata).size();
206 while (i < unisize) {
207 res.push_back(((u8)
_udata[i])+0);
329 _alphab = (((((val) >> (2)))) & (3));
369 udatalen = (int)(
_udata).size();
372 while (i < udatalen) {
379 _udata = string(0, (
char)0);
391 if ((
int)(val).length() == 0) {
397 newdatalen = (int)(newdata).size();
398 if (newdatalen == 0) {
402 newdatalen = (int)(newdata).size();
406 newdatalen = (int)(newdata).size();
408 udatalen = (int)(
_udata).size();
411 udata = string(udatalen + 2*newdatalen, (
char)0);
413 while (i < udatalen) {
414 udata[i] = (char)(((u8)
_udata[i]));
418 while (i < newdatalen) {
419 udata[udatalen+1] = (char)(((u8)newdata[i]));
420 udatalen = udatalen + 2;
425 udata = string(udatalen+newdatalen, (
char)0);
427 while (i < udatalen) {
428 udata[i] = (char)(((u8)
_udata[i]));
432 while (i < newdatalen) {
433 udata[udatalen] = (char)(((u8)newdata[i]));
434 udatalen = udatalen + 1;
454 arrlen = (int)val.size();
460 newdatalen = newdatalen + 1;
465 udatalen = (int)(
_udata).size();
466 udata = string(udatalen+2*newdatalen, (
char)0);
468 while (i < udatalen) {
469 udata[i] = (char)(((u8)
_udata[i]));
476 surrogate = uni - 65536;
477 uni = (((((surrogate) >> (10))) & (1023))) + 55296;
478 udata[udatalen] = (char)(((uni) >> (8)));
479 udata[udatalen+1] = (char)(((uni) & (255)));
480 udatalen = udatalen + 2;
481 uni = (((surrogate) & (1023))) + 56320;
483 udata[udatalen] = (char)(((uni) >> (8)));
484 udata[udatalen+1] = (char)(((uni) & (255)));
485 udatalen = udatalen + 2;
509 _npdu = (int)parts.size();
515 while (partno <
_npdu) {
521 sorted.push_back(subsms);
526 if (initpartno == partno) {
531 _npdu = (int)sorted.size();
541 while (partno < (
int)
_parts.size()) {
544 totsize = totsize + (int)(subdata).size();
547 res = string(totsize, (
char)0);
550 while (partno < (
int)
_parts.size()) {
554 while (i < (
int)(subdata).size()) {
555 res[totsize] = (char)(((u8)subdata[i]));
556 totsize = totsize + 1;
575 srclen = (int)(bytes).size();
579 val = ((u8)bytes[i]);
580 if ((val >= 48) && (val < 58)) {
586 res = string(1, (
char)0);
590 res = string(2+((numlen+1) >> (1)), (
char)0);
591 res[0] = (char)(numlen);
592 if (((u8)bytes[0]) == 43) {
593 res[1] = (char)(145);
595 res[1] = (char)(129);
601 val = ((u8)bytes[i]);
602 if ((val >= 48) && (val < 58)) {
603 if (((numlen) & (1)) == 0) {
606 res[((numlen) >> (1))] = (
char)(digit + 16*(val-48));
613 if (((numlen) & (1)) != 0) {
614 res[((numlen) >> (1))] = (
char)(digit + 240);
633 addrType = ((((u8)addr[ofs])) & (112));
634 if (addrType == 80) {
636 siz = ((4*siz) / (7));
637 gsm7 = string(siz, (
char)0);
644 gsm7[i] = (char)(carry);
648 byt = ((u8)addr[ofs+rpos]);
650 gsm7[i] = (char)(((carry) | ((((((byt) << (nbits)))) & (127)))));
651 carry = ((byt) >> ((7 - nbits)));
659 if (addrType == 16) {
662 siz = (((siz+1)) >> (1));
665 byt = ((u8)addr[ofs+i+1]);
670 if (((((u8)addr[ofs+siz])) >> (4)) == 15) {
671 res = (res).substr( 0, (
int)(res).length()-1);
686 explen = (int)(exp).length();
688 res = string(0, (
char)0);
691 if ((exp).substr(0, 1) ==
"+") {
692 n = atoi(((exp).substr(1, explen-1)).c_str());
693 res = string(1, (
char)0);
695 n = 192+(((n+6*86400)) / ((7*86400)));
698 n = 166+(((n+86399)) / (86400));
701 n = 143+(((n-43200+1799)) / (1800));
703 n = -1+(((n+299)) / (300));
713 if ((exp).substr(4, 1) ==
"-" || (exp).substr(4, 1) ==
"/") {
715 exp = (exp).substr( 2, explen-2);
716 explen = (int)(exp).length();
719 res = string(7, (
char)0);
722 while ((i+1 < explen) && (n < 7)) {
723 v1 = ((u8)expasc[i]);
724 if ((v1 >= 48) && (v1 < 58)) {
725 v2 = ((u8)expasc[i+1]);
726 if ((v2 >= 48) && (v2 < 58)) {
729 res[n] = (char)((((v2) << (4))) + v1);
742 v1 = ((u8)expasc[i-3]);
743 v2 = ((u8)expasc[i]);
744 if (((v1 == 43) || (v1 == 45)) && (v2 == 58)) {
745 v1 = ((u8)expasc[i+1]);
746 v2 = ((u8)expasc[i+2]);
747 if ((v1 >= 48) && (v1 < 58) && (v1 >= 48) && (v1 < 58)) {
748 v1 = (((10*(v1 - 48)+(v2 - 48))) / (15));
750 v2 = 4 * ((u8)res[n]) + v1;
751 if (((u8)expasc[i-3]) == 45) {
784 n = (n-192) * 7 * 86400;
792 while ((i < siz) && (i < 6)) {
793 byt = ((u8)exp[ofs+i]);
809 byt = ((u8)exp[ofs+i]);
811 if (((byt) & (8)) != 0) {
815 byt = (10*(((byt) & (15)))) + (((byt) >> (4)));
818 if ((
int)(hh).length()<2) {
821 if ((
int)(ss).length()<2) {
833 udhsize = (int)(
_udh).size();
834 res = (int)(
_udata).size();
837 res = res + (((8 + 8*udhsize + 6)) / (7));
839 res = (((res * 7 + 7)) / (8));
842 res = res + 1 + udhsize;
862 udhsize = (int)(
_udh).size();
863 udlen = (int)(
_udata).size();
864 res = string(1+udsize, (
char)0);
872 udhlen = (((8 + 8*udhsize + 6)) / (7));
873 nbits = 7*udhlen - 8 - 8*udhsize;
875 res[0] = (char)(udhlen+udlen);
878 res[0] = (char)(udsize);
883 res[wpos] = (char)(udhsize);
886 while (i < udhsize) {
887 res[wpos] = (char)(((u8)
_udh[i]));
902 res[wpos] = (char)(((carry) | ((((((thi_b) << (nbits)))) & (255)))));
905 carry = ((thi_b) >> ((7 - nbits)));
910 res[wpos] = (char)(carry);
916 res[wpos] = (char)(((u8)
_udata[i]));
936 udhsize = (int)(
_udh).size();
937 udlen = (int)(
_udata).size();
938 mss = 140 - 1 - 5 - udhsize;
940 mss = (((mss * 8 - 6)) / (7));
942 _npdu = (((udlen+mss-1)) / (mss));
946 while (wpos < udlen) {
948 newudh = string(5+udhsize, (
char)0);
949 newudh[0] = (char)(0);
950 newudh[1] = (char)(3);
951 newudh[2] = (char)(
_mref);
952 newudh[3] = (char)(
_npdu);
953 newudh[4] = (char)(partno);
955 while (i < udhsize) {
956 newudh[5+i] = (char)(((u8)
_udh[i]));
959 if (wpos+mss < udlen) {
962 partlen = udlen-wpos;
964 newud = string(partlen, (
char)0);
966 while (i < partlen) {
967 newud[i] = (char)(((u8)
_udata[wpos]));
1001 _pdu = string(0, (
char)0);
1005 if ((
int)(sca).size() > 0) {
1006 sca[0] = (char)((
int)(sca).size()-1);
1012 hdr = string(1, (
char)0);
1017 hdr = string(2, (
char)0);
1018 hdr[1] = (char)(
_mref);
1020 if ((
int)(stamp).size() > 0) {
1021 pdutyp = pdutyp + 16;
1023 if ((
int)(stamp).size() == 7) {
1024 pdutyp = pdutyp + 8;
1027 if ((
int)(
_udh).size() > 0) {
1028 pdutyp = pdutyp + 64;
1030 hdr[0] = (char)(pdutyp);
1031 pdulen = (int)(sca).size()+(int)(hdr).size()+(int)(addr).size()+2+(int)(stamp).size()+(int)(udata).size();
1032 _pdu = string(pdulen, (
char)0);
1035 while (i < (
int)(sca).size()) {
1036 _pdu[pdulen] = (char)(((u8)sca[i]));
1037 pdulen = pdulen + 1;
1041 while (i < (
int)(hdr).size()) {
1042 _pdu[pdulen] = (char)(((u8)hdr[i]));
1043 pdulen = pdulen + 1;
1047 while (i < (
int)(addr).size()) {
1048 _pdu[pdulen] = (char)(((u8)addr[i]));
1049 pdulen = pdulen + 1;
1053 pdulen = pdulen + 1;
1055 pdulen = pdulen + 1;
1057 while (i < (
int)(stamp).size()) {
1058 _pdu[pdulen] = (char)(((u8)stamp[i]));
1059 pdulen = pdulen + 1;
1063 while (i < (
int)(udata).size()) {
1064 _pdu[pdulen] = (char)(((u8)udata[i]));
1065 pdulen = pdulen + 1;
1082 udhlen = (int)(
_udh).size();
1084 while (i+1 < udhlen) {
1085 iei = ((u8)
_udh[i]);
1086 ielen = ((u8)
_udh[i+1]);
1088 if (i + ielen <= udhlen) {
1089 if ((iei == 0) && (ielen == 3)) {
1097 if ((iei == 8) && (ielen == 4)) {
1129 rpos = 1+((u8)pdu[0]);
1130 pdutyp = ((u8)pdu[rpos]);
1132 _deliv = (((pdutyp) & (3)) == 0);
1134 addrlen = ((u8)pdu[rpos]);
1140 _mref = ((u8)pdu[rpos]);
1142 addrlen = ((u8)pdu[rpos]);
1146 if ((((pdutyp) & (16))) != 0) {
1147 if ((((pdutyp) & (8))) != 0) {
1156 rpos = rpos + ((((addrlen+3)) >> (1)));
1157 _pid = ((u8)pdu[rpos]);
1159 dcs = ((u8)pdu[rpos]);
1161 _alphab = (((((dcs) >> (2)))) & (3));
1164 rpos = rpos + tslen;
1168 udlen = ((u8)pdu[rpos]);
1170 if (((pdutyp) & (64)) != 0) {
1171 udhsize = ((u8)pdu[rpos]);
1173 _udh = string(udhsize, (
char)0);
1175 while (i < udhsize) {
1176 _udh[i] = (char)(((u8)pdu[rpos]));
1182 udhlen = (((8 + 8*udhsize + 6)) / (7));
1183 nbits = 7*udhlen - 8 - 8*udhsize;
1185 thi_b = ((u8)pdu[rpos]);
1187 carry = ((thi_b) >> (nbits));
1194 udlen = udlen - udhlen;
1197 _udh = string(0, (
char)0);
1199 _udata = string(udlen, (
char)0);
1205 _udata[i] = (char)(carry);
1209 thi_b = ((u8)pdu[rpos]);
1211 _udata[i] = (char)(((carry) | ((((((thi_b) << (nbits)))) & (127)))));
1212 carry = ((thi_b) >> ((7 - nbits)));
1221 _udata[i] = (char)(((u8)pdu[rpos]));
1246 retcode= pdu.
send();
1275 ,_slotsInUse(SLOTSINUSE_INVALID)
1276 ,_slotsCount(SLOTSCOUNT_INVALID)
1277 ,_slotsBitmap(SLOTSBITMAP_INVALID)
1278 ,_pduSent(PDUSENT_INVALID)
1279 ,_pduReceived(PDURECEIVED_INVALID)
1280 ,_command(COMMAND_INVALID)
1281 ,_valueCallbackMessageBox(NULL)
1283 ,_gsm2unicodeReady(0)
1301 if(json_val->
has(
"slotsInUse")) {
1304 if(json_val->
has(
"slotsCount")) {
1307 if(json_val->
has(
"slotsBitmap")) {
1310 if(json_val->
has(
"pduSent")) {
1313 if(json_val->
has(
"pduReceived")) {
1316 if(json_val->
has(
"command")) {
1344 }
catch (std::exception) {
1373 }
catch (std::exception) {
1395 }
catch (std::exception) {
1424 }
catch (std::exception) {
1447 char buf[32]; sprintf(buf,
"%d", newval); rest_val = string(buf);
1448 res =
_setAttr(
"pduSent", rest_val);
1449 }
catch (std::exception) {
1478 }
catch (std::exception) {
1501 char buf[32]; sprintf(buf,
"%d", newval); rest_val = string(buf);
1502 res =
_setAttr(
"pduReceived", rest_val);
1503 }
catch (std::exception) {
1525 }
catch (std::exception) {
1540 res =
_setAttr(
"command", rest_val);
1541 }
catch (std::exception) {
1589 }
catch (std::exception) {
1611 if (callback != NULL) {
1618 if (callback != NULL && this->
isOnline()) {
1652 vector<string> arrPdu;
1759 gsmlen = (int)(gsm).size();
1762 while (i < gsmlen) {
1763 if (((u8)gsm[i]) == 27) {
1764 reslen = reslen - 1;
1770 while (i < gsmlen) {
1772 if ((uni == 27) && (i+1 < gsmlen)) {
1844 gsmlen = (int)(gsm).size();
1847 while (i < gsmlen) {
1848 if (((u8)gsm[i]) == 27) {
1849 reslen = reslen - 1;
1853 resbin = string(reslen, (
char)0);
1856 while (i < gsmlen) {
1858 if ((uni == 27) && (i+1 < gsmlen)) {
1911 if ((uni > 0) && (uni < 256)) {
1912 resbin[reslen] = (char)(uni);
1913 reslen = reslen + 1;
1918 if ((
int)(resstr).length() > reslen) {
1919 resstr = (resstr).substr(0, reslen);
1938 asclen = (int)(asc).size();
1941 while (i < asclen) {
1949 res = string(0, (
char)0);
1954 res = string(asclen+extra, (
char)0);
1957 while (i < asclen) {
1960 res[wpos] = (char)(gsm7);
1992 res[wpos] = (char)(gsm7);
2015 vector<YSms> newArr;
2016 vector<YSms> newMsg;
2017 vector<YSms> newAgg;
2018 vector<string> signatures;
2028 nslots = 8*(int)(newBitmap).size();
2035 while (pduIdx < (
int)
_pdus.size()) {
2036 sms =
_pdus[pduIdx];
2038 idx = ((slot) >> (3));
2039 if (idx < (
int)(newBitmap).size()) {
2040 bitVal = ((1) << ((((slot) & (7)))));
2041 if ((((((u8)newBitmap[idx])) & (bitVal))) != 0) {
2042 newArr.push_back(sms);
2044 newMsg.push_back(sms);
2048 while ((i < nsig) && ((
int)(sig).length() > 0)) {
2049 if (signatures[i] == sig) {
2054 if ((
int)(sig).length() > 0) {
2055 signatures.push_back(sig);
2061 pduIdx = pduIdx + 1;
2065 while (slot < nslots) {
2066 idx = ((slot) >> (3));
2067 bitVal = ((1) << ((((slot) & (7)))));
2069 if (idx < (
int)(prevBitmap).size()) {
2070 prevBit = ((((u8)prevBitmap[idx])) & (bitVal));
2072 if ((((((u8)newBitmap[idx])) & (bitVal))) != 0) {
2075 newArr.push_back(sms);
2077 newMsg.push_back(sms);
2081 while ((i < nsig) && ((
int)(sig).length() > 0)) {
2082 if (signatures[i] == sig) {
2087 if ((
int)(sig).length() > 0) {
2088 signatures.push_back(sig);
2100 sig = signatures[i];
2103 while (pduIdx < (
int)
_pdus.size()) {
2104 sms =
_pdus[pduIdx];
2111 newAgg.push_back(sms);
2114 pduIdx = pduIdx + 1;
2116 if ((cnt > 0) && ((
int)newAgg.size() == cnt)) {
2119 newMsg.push_back(sms);
2248 vector<YFUN_DESCR> v_fundescr;
2250 string serial, funcId, funcName, funcVal, errmsg;
2253 v_fundescr.size() == 0 ||
virtual int get_dcs(void)
yCRITICAL_SECTION _this_cs
virtual int set_alphabet(int val)
YMessageBoxValueCallback _valueCallbackMessageBox
virtual int get_msgRef(void)
YRETCODE _load_unsafe(int msValidity)
static const string SLOTSBITMAP_INVALID
virtual vector< int > gsm2unicode(string gsm)
virtual int set_userDataHeader(string val)
static YMessageBox * FirstMessageBox(void)
virtual int set_msgClass(int val)
virtual string decodeTimeStamp(string exp, int ofs, int siz)
virtual YSms fetchPdu(int slot)
void(* YMessageBoxValueCallback)(YMessageBox *func, const string &functionValue)
int set_pduSent(int newval)
virtual int get_protocolId(void)
YRETCODE _upload(const string &path, const string &content)
static int DefaultCacheValidity
string getString(const string &key)
virtual int get_concatIndex(void)
virtual string encodeAddress(string addr)
virtual string get_userDataHeader(void)
virtual string get_sender(void)
string get_slotsBitmap(void)
virtual int nextMsgRef(void)
void yLeaveCriticalSection(yCRITICAL_SECTION *cs)
virtual int set_timestamp(string val)
virtual int sendTextMessage(string recipient, string message)
virtual string get_userData(void)
string _download(const string &url)
virtual vector< YSms > get_parts(void)
static YRETCODE getFunctionInfo(YFUN_DESCR fundesc, YDEV_DESCR &devdescr, string &serial, string &funcId, string &funcName, string &funcVal, string &errmsg)
virtual int set_slot(int val)
vector< int > _gsm2unicode
virtual int set_sender(string val)
#define YAPI_INVALID_STRING
virtual int set_smsc(string val)
YMessageBox * nextMessageBox(void)
virtual int _parseAttr(YJSONObject *json_val)
virtual int udataSize(void)
virtual int generateParts(void)
virtual int _invokeValueCallback(string value)
virtual int get_alphabet(void)
virtual string gsm2str(string gsm)
static YMessageBox * FindMessageBox(string func)
virtual int set_received(bool val)
virtual int set_pdu(string pdu)
int getInt(const string &key)
static u64 GetTickCount(void)
static void _AddToCache(const string &classname, const string &func, YFunction *obj)
virtual bool isReceived(void)
virtual vector< YSms > get_pdus(void)
virtual int get_slot(void)
virtual int convertToUnicode(void)
virtual int checkNewMessages(void)
virtual int addUnicodeData(vector< int > val)
static YFunction * _FindFromCache(const string &classname, const string &func)
virtual int parsePdu(string pdu)
vector< string > _json_get_array(const string &json)
static const int PDUSENT_INVALID
virtual int initGsm2Unicode(void)
static string ysprintf(const char *fmt,...)
virtual int clearSIMSlot(int slot)
virtual int parseUserDataHeader(void)
void yEnterCriticalSection(yCRITICAL_SECTION *cs)
static yCRITICAL_SECTION _global_cs
static const string COMMAND_INVALID
virtual string get_timestamp(void)
string _decode_json_string(const string &json)
virtual string encodeUserData(void)
virtual int get_concatCount(void)
static string _hexStr2Bin(const string &str)
virtual int generatePdu(void)
static const int SLOTSINUSE_INVALID
virtual int set_userData(string val)
static int getFunctionsByClass(const string &class_str, YFUN_DESCR prevfundesc, vector< YFUN_DESCR > &buffer, int maxsize, string &errmsg)
virtual vector< YSms > get_messages(void)
virtual vector< int > get_unicodeData(void)
virtual string get_recipient(void)
virtual string encodeTimeStamp(string exp)
virtual string get_textData(void)
virtual int _parseAttr(YJSONObject *json_val)
int set_command(const string &newval)
virtual YSms newMessage(string recipient)
virtual int set_protocolId(int val)
int set_pduReceived(int newval)
virtual string str2gsm(string msg)
virtual int clearPduCounters(void)
int get_pduReceived(void)
virtual string get_smsc(void)
static const int PDURECEIVED_INVALID
YMessageBox(const string &func)
virtual int addText(string val)
virtual int set_parts(vector< YSms > parts)
static bool _apiInitialized
YRETCODE _nextFunction(string &hwId)
virtual string get_pdu(void)
static void _UpdateValueCallbackList(YFunction *func, bool add)
virtual int deleteFromSIM(void)
virtual int get_partCount(void)
bool has(const string &key)
virtual int set_msgRef(int val)
YRETCODE _setAttr(string attrname, string newvalue)
virtual string get_concatSignature(void)
virtual int sendFlashMessage(string recipient, string message)
virtual string decodeAddress(string addr, int ofs, int siz)
virtual int get_msgClass(void)
virtual int set_recipient(string val)
virtual int _invokeValueCallback(string value)
static const int SLOTSCOUNT_INVALID
virtual int set_dcs(int val)
virtual int registerValueCallback(YMessageBoxValueCallback callback)