Parse an incoming SMS message into RPData, save everything else we need. We do this immediately upon reception of a SIP message to error check it before queueing it for delivery to an MS. Return result or NULL on failure. SIP should return error 400 "Bad Request" in this case.
| 627 | // We do this immediately upon reception of a SIP message to error check it before queueing it for delivery to an MS. |
| 628 | // Return result or NULL on failure. SIP should return error 400 "Bad Request" in this case. |
| 629 | RPData *parseSMS(const char *callingPartyDigits, const char* message, const char* contentType) |
| 630 | { |
| 631 | // TODO: Read MIME Type from smqueue!! |
| 632 | unsigned reference = random() % 255; |
| 633 | RPData *rp_data = NULL; |
| 634 | |
| 635 | if (strncmp(contentType,"text/plain",10)==0) { |
| 636 | rp_data = new RPData(reference, |
| 637 | RPAddress(gConfig.getStr("SMS.FakeSrcSMSC").c_str()), |
| 638 | TLDeliver(callingPartyDigits,message,0)); |
| 639 | } else if (strncmp(contentType,"application/vnd.3gpp.sms",24)==0) { |
| 640 | BitVector2 RPDUbits(strlen(message)*4); |
| 641 | if (!RPDUbits.unhex(message)) { |
| 642 | LOG(WARNING) << "Hex string parsing failed (in incoming SIP MESSAGE)"; |
| 643 | return NULL; |
| 644 | } |
| 645 | |
| 646 | try { |
| 647 | RLFrame RPDU(RPDUbits); |
| 648 | LOG(DEBUG) << "SMS RPDU: " << RPDU; |
| 649 | |
| 650 | rp->data = new RPData(); |
| 651 | rp_data->parse(RPDU); |
| 652 | LOG(DEBUG) << "SMS RP-DATA " << rp_data; |
| 653 | } |
| 654 | catch (SMSReadError) { |
| 655 | LOG(WARNING) << "SMS parsing failed (above L3)"; |
| 656 | delete rp_data; rp_data = NULL; |
| 657 | } |
| 658 | catch (GSM::L3ReadError) { |
| 659 | LOG(WARNING) << "SMS parsing failed (in L3)"; |
| 660 | delete rp_data; rp_data = NULL; |
| 661 | } |
| 662 | catch (...) { // Should not happen, but be safe. |
| 663 | LOG(WARNING) << "SMS parsing failed (unexpected error)"; |
| 664 | delete rp_data; rp_data = NULL; |
| 665 | } |
| 666 | return rp_data; |
| 667 | } else { |
| 668 | LOG(WARNING) << "Unsupported content type (in incoming SIP MESSAGE) -- type: " << contentType; |
| 669 | return NULL; |
| 670 | } |
| 671 | } |
| 672 | #endif |
| 673 | |
| 674 | }; |