Changeset 3728

Show
Ignore:
Timestamp:
06/05/2012 06:53:38 PM (12 months ago)
Author:
kurtis.heimerl
Message:

Fixed sendsms bug, needed to move to non-interactive version

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • openbts/trunk/CLI/CLI.cpp

    r3691 r3728  
    283283} 
    284284 
     285int isIMSI(const char *imsi) 
     286{ 
     287        int i = 0; 
     288 
     289        if (!imsi) 
     290                return 0; 
     291        if (strlen(imsi) != 15) 
     292                return 0; 
     293         
     294        for (i = 0; i < strlen(imsi); i++) { 
     295                if (!isdigit(imsi[i])) 
     296                        return 0; 
     297        } 
     298 
     299        return 1; 
     300} 
    285301 
    286302/** Submit an SMS for delivery to an IMSI. */ 
    287303int sendsimple(int argc, char** argv, ostream& os) 
    288304{ 
    289         if (argc!=3) return BAD_NUM_ARGS; 
    290  
    291         os << "enter text to send: "; 
    292         char txtBuf[161]; 
    293         cin.getline(txtBuf,160,'\n'); 
     305        if (argc<4) return BAD_NUM_ARGS; 
     306 
    294307        char *IMSI = argv[1]; 
    295308        char *srcAddr = argv[2]; 
     309        string rest = ""; 
     310        for (int i=3; i<argc; i++) rest = rest + argv[i] + " "; 
     311        const char *txtBuf = rest.c_str(); 
     312 
     313        if (!isIMSI(IMSI)) { 
     314                os << "Invalid IMSI. Enter 15 digits only."; 
     315                return BAD_VALUE; 
     316        } 
    296317 
    297318        static UDPSocket sock(0,"127.0.0.1",gConfig.getNum("SIP.Local.Port")); 
     
    312333        sock.write(buffer); 
    313334 
     335        os << "message submitted for delivery" << endl; 
    314336 
    315337#if 0 
     
    326348} 
    327349 
    328  
    329350/** Submit an SMS for delivery to an IMSI. */ 
    330351int sendsms(int argc, char** argv, ostream& os) 
    331352{ 
    332         if (argc!=3) return BAD_NUM_ARGS; 
    333  
    334         os << "enter text to send: "; 
    335         char txtBuf[161]; 
    336         cin.getline(txtBuf,160,'\n'); 
     353        if (argc<4) return BAD_NUM_ARGS; 
     354 
    337355        char *IMSI = argv[1]; 
    338356        char *srcAddr = argv[2]; 
     357        string rest = ""; 
     358        for (int i=3; i<argc; i++) rest = rest + argv[i] + " "; 
     359        const char *txtBuf = rest.c_str(); 
     360 
     361        if (!isIMSI(IMSI)) { 
     362                os << "Invalid IMSI. Enter 15 digits only."; 
     363                return BAD_VALUE; 
     364        } 
    339365 
    340366        Control::TransactionEntry *transaction = new Control::TransactionEntry( 
     
    741767        addCommand("exit", exit_function, "[wait] -- exit the application, either immediately, or waiting for existing calls to clear with a timeout in seconds"); 
    742768        addCommand("tmsis", tmsis, "[\"clear\"] or [\"dump\" filename] -- print/clear the TMSI table or dump it to a file."); 
    743         addCommand("sendsms", sendsms, "<IMSI> <src> -- send direct SMS to <IMSI>, addressed from <src>, after prompting."); 
    744         addCommand("sendsimple", sendsimple, "<IMSI> <src> -- send SMS to <IMSI> via SIP interface, addressed from <src>, after prompting."); 
     769        addCommand("sendsms", sendsms, "IMSI src# message... -- send direct SMS to IMSI, addressed from source number src#."); 
     770        addCommand("sendsimple", sendsimple, "IMSI src# message... -- send SMS to IMSI via SIP interface, addressed from source number src#."); 
    745771        //apparently non-function now -kurtis 
    746772        //addCommand("sendrrlp", sendrrlp, "<IMSI> <hexstring> -- send RRLP message <hexstring> to <IMSI>.");