/** Submit an SMS for delivery to an IMSI. */ int sendsimple(int argc, char** argv, ostream& os) { if (argc<4) return BAD_NUM_ARGS; char *IMSI = argv[1]; char *srcAddr = argv[2]; string rest = ""; for (int i=3; i<argc; i++) rest = rest + argv[i] + " "; const char *txtBuf = rest.c_str(); if (!isIMSI(IMSI)) { os << "Invalid IMSI. Enter 15 digits only."; return BAD_VALUE; } static UDPSocket sock(0,"127.0.0.1",gConfig.getNum("SIP.Local.Port")); static const char form[] = "MESSAGE sip:IMSI%[email protected] SIP/2.0\n" "Via: SIP/2.0/TCP 127.0.0.1;branch=%x\n" "Max-Forwards: 2\n" "From: %s <sip:%[email protected]:%d>;tag=%d\n" "To: sip:IMSI%[email protected]\n" "Call-ID: %[email protected]:%d\n" "CSeq: 1 MESSAGE\n" "Content-Type: text/plain\nContent-Length: %u\n" "\n%s\n"; static char buffer[1500]; snprintf(buffer,1499,form, IMSI, (unsigned)random(), srcAddr,srcAddr,sock.port(),(unsigned)random(), IMSI, (unsigned)random(),sock.port(), strlen(txtBuf), txtBuf); sock.write(buffer); os << "message submitted for delivery" << endl; #if 0 int numRead = sock.read(buffer,10000); if (numRead>=0) { buffer[numRead]='\0'; os << "response: " << buffer << endl; } else { os << "timed out waiting for response"; } #endif return SUCCESS; }
// Test Existing server. Note: Must be started on port 1234 int testExistingServer () { TestHelper helper; UDPSocket socket; socket.bind(); UDPEchoClient client(socket); client.result() = memFun (&helper, &TestHelper::callback); client.start ("127.0.0.1", 1234, 1000); bool hasResult = helper.waitForResult (2000); tassert (hasResult, "Must callback"); if (helper.result() != NoError){ fprintf (stderr, "Warning: Localhost echo server seems not to run!"); return 0; // do not interpret as an error } tcheck1 (client.port() == socket.port()); tcheck1 (client.address() == "127.0.0.1"); return 0; }