diff --git a/client.c b/client.c index a2f1aea7..afcb8088 100755 --- a/client.c +++ b/client.c @@ -77,7 +77,7 @@ int packetSendRequest(int method,unsigned char *packet,int packet_len,int batchP return 0; } - getPeerList(); + if (!peer_count) getPeerList(); gettimeofday(&time_in,NULL); diff --git a/mphlr.h b/mphlr.h index 66183832..c2ed7866 100755 --- a/mphlr.h +++ b/mphlr.h @@ -227,6 +227,7 @@ extern struct mphlr_variable vars[]; #define ACTION_SET 0x01 #define ACTION_DEL 0x02 #define ACTION_INSERT 0x03 +#define ACTION_SENDSMS 0x04 #define ACTION_CREATEHLR 0x0f #define ACTION_DONE 0x7e @@ -236,6 +237,7 @@ extern struct mphlr_variable vars[]; #define ACTION_OKAY 0x81 #define ACTION_DATA 0x82 #define ACTION_WROTE 0x83 +#define ACTION_SMSRECEIVED 0x84 #define ACTION_XFER 0xf0 #define ACTION_PAD 0xfe diff --git a/server.c b/server.c index 56587511..e76520ec 100755 --- a/server.c +++ b/server.c @@ -129,7 +129,7 @@ int processRequest(unsigned char *packet,int len, unsigned char *transaction_id,char *did,char *sid) { /* Find HLR entry by DID or SID, unless creating */ - int ofs,rofs; + int ofs,rofs=0; int records_searched=0; int prev_pofs=0; @@ -173,6 +173,42 @@ int processRequest(unsigned char *packet,int len, case ACTION_EOT: /* EOT */ pofs=len; break; + case ACTION_SENDSMS: /* Send an SMS to the specified SID. */ + /* You cannot use a DID */ + if (did[0]) return respondSimple(NULL,ACTION_DECLINED,NULL,0,transaction_id); + + /* XXX Thomas to complete and make sure it works: + 1. Unpack SMS message. + 2. Make sure it hasn't already been delivered. + 3. Make sure there is space to deliver it . + 4. Deliver it to the next free message slot + */ + + // extractSMS(...); -- don't forget to check maximum message length + int instance=-1; /* use first free slot */ + unsigned char oldvalue[65536]; + { int oldl=65536; int oldr=hlrGetVariable(hlr,ofs,VAR_SMESSAGES,instance,oldvalue,&oldl); + if (oldr) { + /* Already exists, so no need to deliver it again */ + respondSimple(sid,ACTION_SMSRECEIVED,NULL,0,transaction_id); + } + else + { + /* Write new value back */ + if (hlrSetVariable(hlr,ofs,VAR_SMESSAGES,instance,oldvalue,oldl)) + { + setReason("Failed to write variable"); + return + respondSimple(NULL,ACTION_ERROR,(unsigned char *)"No space for message",0,transaction_id); + } + if (debug>2) { fprintf(stderr,"HLR after writing:\n"); hlrDump(hlr,ofs); } + + /* Reply that we wrote the fragment */ + respondSimple(sid,ACTION_WROTE,&packet[rofs],6, + transaction_id); + } + } + break; case ACTION_SET: ofs=0; if (debug>1) fprintf(stderr,"Looking for hlr entries with sid='%s' / did='%s'\n",sid,did);