From 4b233b4f3b22f79c2bdd60703d309c9929f74ab6 Mon Sep 17 00:00:00 2001 From: Harald Welte Date: Wed, 7 Nov 2012 08:32:31 +0100 Subject: initial import of libsmpp34-1.10 --- test_apps/Makefile.am | 35 +++++ test_apps/analizer.c | 245 +++++++++++++++++++++++++++++++++++ test_apps/esme.c | 109 ++++++++++++++++ test_apps/esme.h | 67 ++++++++++ test_apps/esme.xml | 6 + test_apps/pack_and_send.inc | 25 ++++ test_apps/recv_and_unpack.inc | 29 +++++ test_apps/sendwp.c | 109 ++++++++++++++++ test_apps/sendwp.h | 68 ++++++++++ test_apps/sendwp.xml | 12 ++ test_apps/smpp.c | 289 ++++++++++++++++++++++++++++++++++++++++++ test_apps/tcp.c | 94 ++++++++++++++ 12 files changed, 1088 insertions(+) create mode 100644 test_apps/Makefile.am create mode 100644 test_apps/analizer.c create mode 100644 test_apps/esme.c create mode 100644 test_apps/esme.h create mode 100644 test_apps/esme.xml create mode 100644 test_apps/pack_and_send.inc create mode 100644 test_apps/recv_and_unpack.inc create mode 100644 test_apps/sendwp.c create mode 100644 test_apps/sendwp.h create mode 100644 test_apps/sendwp.xml create mode 100644 test_apps/smpp.c create mode 100644 test_apps/tcp.c (limited to 'test_apps') diff --git a/test_apps/Makefile.am b/test_apps/Makefile.am new file mode 100644 index 0000000..e1e565c --- /dev/null +++ b/test_apps/Makefile.am @@ -0,0 +1,35 @@ +# test_pdu/Makefile.am # + +TESTAPPS_SOURCE_DIR = $(top_srcdir)/test_apps +sendwp_SOURCES = \ + $(TESTAPPS_SOURCE_DIR)/tcp.c\ + $(TESTAPPS_SOURCE_DIR)/smpp.c\ + $(TESTAPPS_SOURCE_DIR)/sendwp.h\ + $(TESTAPPS_SOURCE_DIR)/sendwp.c + +sendwp_CPPFLAGS = `xml2-config --cflags` +sendwp_LDFLAGS = `xml2-config --libs` +sendwp_pkgdatadir = $(prefix)/bin +sendwp_pkgdata_DATA = \ + $(TESTAPPS_SOURCE_DIR)/sendwp.xml + +esme_SOURCES = \ + $(TESTAPPS_SOURCE_DIR)/tcp.c\ + $(TESTAPPS_SOURCE_DIR)/smpp.c\ + $(TESTAPPS_SOURCE_DIR)/esme.h\ + $(TESTAPPS_SOURCE_DIR)/esme.c + +esme_CPPFLAGS = `xml2-config --cflags` +esme_LDFLAGS = `xml2-config --libs` +esme_pkgdatadir = $(prefix)/bin +esme_pkgdata_DATA = \ + $(TESTAPPS_SOURCE_DIR)/esme.xml + +analizer_SOURCES = \ + $(TESTAPPS_SOURCE_DIR)/analizer.c + +analizer_CPPFLAGS = +analizer_LDFLAGS = +analizer_pkgdatadir = +analizer_pkgdata_DATA = + diff --git a/test_apps/analizer.c b/test_apps/analizer.c new file mode 100644 index 0000000..9128a05 --- /dev/null +++ b/test_apps/analizer.c @@ -0,0 +1,245 @@ + +/* + * Copyright (C) 2006 Raul Tremsal + * File : esme.c + * Author: Raul Tremsal + * + * This file is part of libsmpp34 (c-open-smpp3.4 library). + * + * The libsmpp34 library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of the + * License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this library; if not, write to the Free Software Foundation, + * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ + +#include +#include +#include +#include + + +#ifdef __linux__ +#include +#endif + +#include "smpp34.h" +#include "smpp34_structs.h" +#include "smpp34_params.h" + +extern char *optarg; +char file_pdu[256]; + +int ret = 0; +uint8_t bufPDU[2048]; +int bufPDULen = 0; +uint8_t bPrint[2048]; + +#define HELP_FORMAT " -f file [-h]\n" \ +" -f /path/to/file: binary file path.\n" \ +" -h : Help, show this message.\n" + + +int work( uint32_t id, void* dst ) +{ + + /* Print Buffer *******************************************************/ + memset(bPrint, 0, sizeof(bPrint)); + ret = smpp34_dumpBuf(bPrint, sizeof(bPrint), bufPDU, bufPDULen); + if( ret != 0 ){ + printf("Error in smpp34_dumpBuf():%d:\n%s\n", + smpp34_errno, smpp34_strerror ); + return( -1 ); + }; + printf("parse smpp34_dumpBuf()\n%s\n", smpp34_strerror); + printf("-----------------------------------------------------------\n"); + printf("%s", bPrint); + printf("-----------------------------------------------------------\n"); + + /* Copy PDU from Buffer ***********************************************/ + ret = smpp34_unpack(id, (void*)dst, bufPDU, bufPDULen); + if( ret != 0 ){ + printf("Error in smpp34_unpack():%d:\n%s\n", + smpp34_errno, smpp34_strerror); + return( -1 ); + }; + printf("parse smpp34_unpack()\n%s\n", smpp34_strerror); + + /* Print PDU **********************************************************/ + memset(bPrint, 0, sizeof(bPrint)); + ret = smpp34_dumpPdu(id, bPrint, sizeof(bPrint), (void*)dst ); + if( ret != 0){ + printf("Error in smpp34_dumpPdu():%d:\n%s\n", + smpp34_errno, smpp34_strerror); + return( -1 ); + }; + printf("parse smpp34_dumpPdu()\n%s\n", smpp34_strerror); + printf("-----------------------------------------------------------\n"); + printf("%s\n", bPrint); + printf("-----------------------------------------------------------\n"); + + return( 0 ); +}; + +int main( int argc, char **argv ) +{ + int co; + FILE *fd = NULL; + uint32_t tt, id; + tt = id = 0; + + while( (co = getopt(argc, argv, "f:h")) != EOF ){ + switch( co ){ + case 'f': + snprintf(file_pdu, sizeof(file_pdu), "%s", optarg); + break; + default: + printf("Error: unrecognized option\n"); + case 'h': + printf("usage: %s %s\n", argv[0], HELP_FORMAT); + return( -1 ); + }; + }; + + if( strcmp(file_pdu, "") == 0 ){ printf("Error in parameters\n"); + printf("usage: %s %s\n", argv[0], HELP_FORMAT); return( -1 ); }; + + /* Open File **********************************************************/ + + if( (fd = fopen(file_pdu, "r")) == NULL ){ + printf("Can't open file %s\n", file_pdu); + return( -1 ); + }; + + memset(bufPDU, 0, sizeof(bufPDU)); bufPDULen = 0; + /* char *fgets(char *s, int size, FILE *stream); */ + while( !feof( fd ) ){ + *(bufPDU + (bufPDULen++)) = (uint8_t)getc( fd ); + }; + fclose( fd ); bufPDULen--; + + memcpy(&tt, (bufPDU+4), 4); id = ntohl( tt ); + + if( id == BIND_TRANSMITTER ){ + bind_transmitter_t t1; + memset(&t1, 0, sizeof(bind_transmitter_t)); + return( work( id, (void*)&t1 ) ); + } else if( id == BIND_TRANSMITTER_RESP ){ + bind_transmitter_resp_t t1; + memset(&t1, 0, sizeof(bind_transmitter_resp_t)); + return( work( id, (void*)&t1 ) ); + } else if( id == BIND_RECEIVER ){ + bind_receiver_t t1; + memset(&t1, 0, sizeof(bind_receiver_t)); + return( work( id, (void*)&t1 ) ); + } else if( id == BIND_RECEIVER_RESP ){ + bind_receiver_resp_t t1; + memset(&t1, 0, sizeof(bind_receiver_resp_t)); + return( work( id, (void*)&t1 ) ); + } else if( id == BIND_TRANSCEIVER ){ + bind_transceiver_t t1; + memset(&t1, 0, sizeof(bind_transceiver_t)); + return( work( id, (void*)&t1 ) ); + } else if( id == BIND_TRANSCEIVER_RESP ){ + bind_transceiver_resp_t t1; + memset(&t1, 0, sizeof(bind_transceiver_resp_t)); + return( work( id, (void*)&t1 ) ); + } else if( id == OUTBIND ){ + outbind_t t1; + memset(&t1, 0, sizeof(outbind_t)); + return( work( id, (void*)&t1 ) ); + } else if( id == UNBIND ){ + unbind_t t1; + memset(&t1, 0, sizeof(unbind_t)); + return( work( id, (void*)&t1 ) ); + } else if( id == UNBIND_RESP ){ + unbind_resp_t t1; + memset(&t1, 0, sizeof(unbind_resp_t)); + return( work( id, (void*)&t1 ) ); + } else if( id == GENERIC_NACK ){ + generic_nack_t t1; + memset(&t1, 0, sizeof(generic_nack_t)); + return( work( id, (void*)&t1 ) ); + } else if( id == SUBMIT_SM ){ + submit_sm_t t1; + memset(&t1, 0, sizeof(submit_sm_t)); + return( work( id, (void*)&t1 ) ); + } else if( id == SUBMIT_SM_RESP ){ + submit_sm_resp_t t1; + memset(&t1, 0, sizeof(submit_sm_resp_t)); + return( work( id, (void*)&t1 ) ); + } else if( id == SUBMIT_MULTI ){ + submit_multi_t t1; + memset(&t1, 0, sizeof(submit_multi_t)); + return( work( id, (void*)&t1 ) ); + } else if( id == SUBMIT_MULTI_RESP ){ + submit_multi_resp_t t1; + memset(&t1, 0, sizeof(submit_multi_resp_t)); + return( work( id, (void*)&t1 ) ); + } else if( id == DELIVER_SM ){ + deliver_sm_t t1; + memset(&t1, 0, sizeof(deliver_sm_t)); + return( work( id, (void*)&t1 ) ); + } else if( id == DELIVER_SM_RESP ){ + deliver_sm_resp_t t1; + memset(&t1, 0, sizeof(deliver_sm_resp_t)); + return( work( id, (void*)&t1 ) ); + } else if( id == DATA_SM ){ + data_sm_t t1; + memset(&t1, 0, sizeof(data_sm_t)); + return( work( id, (void*)&t1 ) ); + } else if( id == DATA_SM_RESP ){ + data_sm_resp_t t1; + memset(&t1, 0, sizeof(data_sm_resp_t)); + return( work( id, (void*)&t1 ) ); + } else if( id == QUERY_SM ){ + query_sm_t t1; + memset(&t1, 0, sizeof(query_sm_t)); + return( work( id, (void*)&t1 ) ); + } else if( id == QUERY_SM_RESP ){ + query_sm_resp_t t1; + memset(&t1, 0, sizeof(query_sm_resp_t)); + return( work( id, (void*)&t1 ) ); + } else if( id == CANCEL_SM ){ + cancel_sm_t t1; + memset(&t1, 0, sizeof(cancel_sm_t)); + return( work( id, (void*)&t1 ) ); + } else if( id == CANCEL_SM_RESP ){ + cancel_sm_resp_t t1; + memset(&t1, 0, sizeof(cancel_sm_resp_t)); + return( work( id, (void*)&t1 ) ); + } else if( id == REPLACE_SM ){ + replace_sm_t t1; + memset(&t1, 0, sizeof(replace_sm_t)); + return( work( id, (void*)&t1 ) ); + } else if( id == REPLACE_SM_RESP ){ + replace_sm_resp_t t1; + memset(&t1, 0, sizeof(replace_sm_resp_t)); + return( work( id, (void*)&t1 ) ); + } else if( id == ENQUIRE_LINK ){ + enquire_link_t t1; + memset(&t1, 0, sizeof(enquire_link_t)); + return( work( id, (void*)&t1 ) ); + } else if( id == ENQUIRE_LINK_RESP ){ + enquire_link_resp_t t1; + memset(&t1, 0, sizeof(enquire_link_resp_t)); + return( work( id, (void*)&t1 ) ); + } else if( id == ALERT_NOTIFICATION ){ + alert_notification_t t1; + memset(&t1, 0, sizeof(alert_notification_t)); + return( work( id, (void*)&t1 ) ); + } else { + printf("Invalid SMPP PDU [%08X].\n", id); + }; + return( -1 ); + +}; diff --git a/test_apps/esme.c b/test_apps/esme.c new file mode 100644 index 0000000..31ea222 --- /dev/null +++ b/test_apps/esme.c @@ -0,0 +1,109 @@ + +/* + * Copyright (C) 2006 Raul Tremsal + * File : esme.c + * Author: Raul Tremsal + * + * This file is part of libsmpp34 (c-open-smpp3.4 library). + * + * The libsmpp34 library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of the + * License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this library; if not, write to the Free Software Foundation, + * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ + +#include +#include +#include +#include +#include + +#include "esme.h" + +extern char *optarg; +char file_config[256]; +xmlDocPtr d; /* document */ +xmlNodePtr c; /* config */ +xmlNodePtr conn_tcp; /* conn_tcp */ +xmlNodePtr conn_smpp; /* conn_smpp */ +xmlNodePtr smpp_msg; /* smpp_msg */ + +int sock_tcp = 0; + + +#define HELP_FORMAT " -c file.xml [-h]\n" \ +" -c /path/to/file.xml: config file path.\n" \ +" -h : Help, show this message.\n" + +int main( int argc, char **argv ) +{ + int co; + + while( (co = getopt(argc, argv, "c:h")) != EOF ){ + switch( co ){ + case 'c': + snprintf(file_config, sizeof(file_config), "%s", optarg); + break; + default: + printf("Error: unrecognized option\n"); + case 'h': + printf("usage: %s %s\n", argv[0], HELP_FORMAT); + return( -1 ); + }; + }; + + if( strcmp(file_config, "") == 0 ){ printf("Error in parameters\n"); + printf("usage: %s %s\n", argv[0], HELP_FORMAT); return( -1 ); }; + d = xmlParseFile( file_config ); + if( d == NULL ){ printf("Error in xmlParseFile()\n"); + printf("usage: %s %s\n", argv[0], HELP_FORMAT); return( -1 ); }; + c = xmlDocGetRootElement( d ); + if( c == NULL ){ printf("Error in xmlDocGetRootElement()\n"); + printf("usage: %s %s\n", argv[0], HELP_FORMAT); return( -1 ); }; + + XML_IN_NODE(c, "config", c=c->xmlChildrenNode;break;, return(-1); ); + XML_IN_NODE(c, "conn_tcp", conn_tcp=c;break;, return(-1); ); + XML_IN_NODE(c, "conn_smpp", conn_smpp=c;break;, return(-1); ); + XML_IN_NODE(c, "smpp_msg", smpp_msg=c;break;, return(-1); ); + + /* do tcp connect */ + if( do_tcp_connect( conn_tcp, &sock_tcp ) ){ + printf("Error in tcp connect.\n"); goto lb_free_document; }; + + /* do smpp connect */ + if( do_smpp_connect( conn_smpp, sock_tcp ) ){ + printf("Error in smpp connect.\n"); goto lb_tcp_close; }; + + /* do smpp send message */ + if( do_smpp_send_message( smpp_msg, sock_tcp ) ){ + printf("Error in smpp send message.\n"); goto lb_smpp_close; }; + + /* That's all folks */ + /* taaa taratatata tatatatatata */ + /* taaa taratatata tatatatatata */ + /* ta aaa ta aaa tatatata */ + /* ta aaa ta aaa tatatata */ + /* taaa taratatata tatatatatata */ + /* :) */ + +lb_smpp_close: /* do smpp close */ + if( do_smpp_close( sock_tcp ) ) printf("Error in smpp close.\n"); + +lb_tcp_close: /* do tcp close */ + if( do_tcp_close( sock_tcp ) ) printf("Error in tcp close.\n"); + +lb_free_document: /* free xml document */ + xmlFreeDoc( d ); + + return( 0 ); +}; diff --git a/test_apps/esme.h b/test_apps/esme.h new file mode 100644 index 0000000..98ccd08 --- /dev/null +++ b/test_apps/esme.h @@ -0,0 +1,67 @@ + +/* + * Copyright (C) 2006 Raul Tremsal + * File : esme.h + * Author: Raul Tremsal + * + * This file is part of libsmpp34 (c-open-smpp3.4 library). + * + * The libsmpp34 library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of the + * License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this library; if not, write to the Free Software Foundation, + * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ + +#ifndef _esme_h_ +#define _esme_h_ + +#define GET_PROP_INT( dst, c, src )\ +{\ + xmlChar *clave = NULL; dst = 0;\ + if( (clave = xmlGetProp(c, (xmlChar*)src)) != NULL ){\ + dst = strtol((char*)clave, NULL, 10);\ + xmlFree( clave );\ + }\ +}; + +#define GET_PROP_STR( dst, c, src )\ +{\ + xmlChar *clave = NULL;\ + memset(dst, 0, sizeof(dst));\ + if( (clave = xmlGetProp(c, (xmlChar*)src)) != NULL ){\ + snprintf((char*)dst, sizeof(dst), "%s", (char*)clave);\ + xmlFree( clave );\ + }\ +}; + + + +#define _xmlChar( str ) (const xmlChar*) str +#define XML_IN_NODE( c, str, exito, fracaso )\ +while( c != NULL ){\ + if( xmlStrcmp(c->name, _xmlChar(str)) == 0 ){\ + exito;\ + };\ + c = c->next;\ +};\ +if( c == NULL ){\ + printf("Can't find tag <%s>.", str);\ + fracaso;\ +}; + +int do_tcp_connect( xmlNodePtr p, int *sock_tcp ); +int do_tcp_close( int sock_tcp ); +int do_smpp_connect( xmlNodePtr p, int sock_tcp ); +int do_smpp_send_message( xmlNodePtr p, int sock_tcp ); +int do_smpp_close( int sock_tcp ); +#endif /* _esme_h_ */ diff --git a/test_apps/esme.xml b/test_apps/esme.xml new file mode 100644 index 0000000..7669880 --- /dev/null +++ b/test_apps/esme.xml @@ -0,0 +1,6 @@ + + + + + + diff --git a/test_apps/pack_and_send.inc b/test_apps/pack_and_send.inc new file mode 100644 index 0000000..f683981 --- /dev/null +++ b/test_apps/pack_and_send.inc @@ -0,0 +1,25 @@ + + /* Linealize PDU to buffer ********************************************/ + memset(local_buffer, 0, sizeof(local_buffer)); + ret = smpp34_pack2( local_buffer, sizeof(local_buffer), + &local_buffer_len, (void*)&req); + if( ret != 0 ){ printf("Error in smpp34_pack():%d:\n%s\n", + smpp34_errno, smpp34_strerror); return( -1 ); }; + /* Print PDU **********************************************************/ + memset(print_buffer, 0, sizeof(print_buffer)); + ret = smpp34_dumpPdu2( print_buffer, sizeof(print_buffer), (void*)&req); + if( ret != 0){ printf("Error in smpp34_dumpPdu():%d:\n%s\n", + smpp34_errno, smpp34_strerror); return( -1 ); }; + printf("-----------------------------------------------------------\n"); + printf("SENDING PDU \n%s\n", print_buffer); + /* Print Buffer *******************************************************/ + memset(print_buffer, 0, sizeof(print_buffer)); + ret = smpp34_dumpBuf(print_buffer, sizeof(print_buffer), + local_buffer, local_buffer_len); + if( ret != 0 ){ printf("Error in smpp34_dumpBuf():%d:\n%s\n", + smpp34_errno, smpp34_strerror ); return( -1 ); }; + printf("SENDING BUFFER \n%s\n", print_buffer); + /* Write to socket ****************************************************/ + ret = send(sock_tcp, local_buffer, local_buffer_len, 0); + if( ret != local_buffer_len ){ printf("Error in send()\n");return( -1 );}; + diff --git a/test_apps/recv_and_unpack.inc b/test_apps/recv_and_unpack.inc new file mode 100644 index 0000000..090ea11 --- /dev/null +++ b/test_apps/recv_and_unpack.inc @@ -0,0 +1,29 @@ + + memset(local_buffer, 0, sizeof(local_buffer)); + /* Read from socket (This is a sample, must be more complex) **********/ + ret = recv(sock_tcp, local_buffer, 4, MSG_PEEK); + if( ret != 4 ){ printf("Error in recv(PEEK)\n");return( -1 );}; + memcpy(&tempo, local_buffer, sizeof(uint32_t)); /* get lenght PDU */ + local_buffer_len = ntohl( tempo ); + ret = recv(sock_tcp, local_buffer, local_buffer_len, 0); + if( ret != local_buffer_len ){ + printf("Error in recv(%d bytes)\n", local_buffer_len);return( -1 );}; + /* Print Buffer *******************************************************/ + memset(print_buffer, 0, sizeof(print_buffer)); + ret = smpp34_dumpBuf(print_buffer, sizeof(print_buffer), + local_buffer, local_buffer_len); + if( ret != 0 ){ printf("Error in smpp34_dumpBuf():%d:\n%s\n", + smpp34_errno, smpp34_strerror ); return( -1 ); }; + printf("-----------------------------------------------------------\n"); + printf("RECEIVE BUFFER \n%s\n", print_buffer); + /* unpack PDU *********************************************************/ + ret = smpp34_unpack2((void*)&res, local_buffer, local_buffer_len); + if( ret != 0){ printf( "Error in smpp34_unpack():%d:%s\n", + smpp34_errno, smpp34_strerror); return( -1 ); }; + /* Print PDU **********************************************************/ + memset(print_buffer, 0, sizeof(print_buffer)); + ret = smpp34_dumpPdu2(print_buffer, sizeof(print_buffer), (void*)&res); + if( ret != 0){ printf("Error in smpp34_dumpPdu():%d:\n%s\n", + smpp34_errno, smpp34_strerror); return( -1 ); }; + printf("RECEIVE PDU \n%s\n", print_buffer); + diff --git a/test_apps/sendwp.c b/test_apps/sendwp.c new file mode 100644 index 0000000..b719c45 --- /dev/null +++ b/test_apps/sendwp.c @@ -0,0 +1,109 @@ + +/* + * Copyright (C) 2006 Raul Tremsal + * File : sendwp.c + * Author: Raul Tremsal + * + * This file is part of libsmpp34 (c-open-smpp3.4 library). + * + * The libsmpp34 library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of the + * License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this library; if not, write to the Free Software Foundation, + * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ + +#include +#include +#include +#include +#include + +#include "sendwp.h" + +extern char *optarg; +char file_config[256]; +xmlDocPtr d; /* document */ +xmlNodePtr c; /* config */ +xmlNodePtr conn_tcp; /* conn_tcp */ +xmlNodePtr conn_smpp; /* conn_smpp */ +xmlNodePtr smpp_msg; /* smpp_msg */ + +int sock_tcp = 0; + + +#define HELP_FORMAT " -c file.xml [-h]\n" \ +" -c /path/to/file.xml: config file path.\n" \ +" -h : Help, show this message.\n" + +int main( int argc, char **argv ) +{ + int co; + int secuencia = 3; + + while( (co = getopt(argc, argv, "c:h")) != EOF ){ + switch( co ){ + case 'c': + snprintf(file_config, sizeof(file_config), "%s", optarg); + break; + default: + printf("Error: unrecognized option\n"); + case 'h': + printf("usage: %s %s\n", argv[0], HELP_FORMAT); + return( -1 ); + }; + }; + + if( strcmp(file_config, "") == 0 ){ printf("Error in parameters\n"); + printf("usage: %s %s\n", argv[0], HELP_FORMAT); return( -1 ); }; + d = xmlParseFile( file_config ); + if( d == NULL ){ printf("Error in xmlParseFile()\n"); + printf("usage: %s %s\n", argv[0], HELP_FORMAT); return( -1 ); }; + c = xmlDocGetRootElement( d ); + if( c == NULL ){ printf("Error in xmlDocGetRootElement()\n"); + printf("usage: %s %s\n", argv[0], HELP_FORMAT); return( -1 ); }; + + XML_IN_NODE(c, "config", c=c->xmlChildrenNode;break;, return(-1); ); + XML_IN_NODE(c, "conn_tcp", conn_tcp=c;break;, return(-1); ); + XML_IN_NODE(c, "conn_smpp", conn_smpp=c;break;, return(-1); ); + XML_IN_NODE(c, "smpp_msg", smpp_msg=c;break;, return(-1); ); + + /* do tcp connect */ + if( do_tcp_connect( conn_tcp, &sock_tcp ) ){ + printf("Error in tcp connect.\n"); goto lb_free_document; }; + + /* do smpp connect */ + if( do_smpp_connect( conn_smpp, sock_tcp ) ){ + printf("Error in smpp connect.\n"); goto lb_tcp_close; }; + + /* do smpp send message */ + while( smpp_msg != NULL ){ + if( do_smpp_send_message2( smpp_msg, sock_tcp, secuencia++ ) ){ + printf("Error in smpp send message.\n"); + goto lb_smpp_close; + }; + smpp_msg = smpp_msg->next; + smpp_msg = smpp_msg->next; + }; + + +lb_smpp_close: /* do smpp close */ + if( do_smpp_close( sock_tcp ) ) printf("Error in smpp close.\n"); + +lb_tcp_close: /* do tcp close */ + if( do_tcp_close( sock_tcp ) ) printf("Error in tcp close.\n"); + +lb_free_document: /* free xml document */ + xmlFreeDoc( d ); + + return( 0 ); +}; diff --git a/test_apps/sendwp.h b/test_apps/sendwp.h new file mode 100644 index 0000000..09ed4e4 --- /dev/null +++ b/test_apps/sendwp.h @@ -0,0 +1,68 @@ + +/* + * Copyright (C) 2006 Raul Tremsal + * File : sendwp.h + * Author: Raul Tremsal + * + * This file is part of libsmpp34 (c-open-smpp3.4 library). + * + * The libsmpp34 library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of the + * License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this library; if not, write to the Free Software Foundation, + * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ + +#ifndef _sendwp_h_ +#define _sendwp_h_ + +#define GET_PROP_INT( dst, c, src )\ +{\ + xmlChar *clave = NULL; dst = 0;\ + if( (clave = xmlGetProp(c, (xmlChar*)src)) != NULL ){\ + dst = strtol((char*)clave, NULL, 10);\ + xmlFree( clave );\ + }\ +}; + +#define GET_PROP_STR( dst, c, src )\ +{\ + xmlChar *clave = NULL;\ + memset(dst, 0, sizeof(dst));\ + if( (clave = xmlGetProp(c, (xmlChar*)src)) != NULL ){\ + snprintf((char*)dst, sizeof(dst), "%s", (char*)clave);\ + xmlFree( clave );\ + }\ +}; + + + +#define _xmlChar( str ) (const xmlChar*) str +#define XML_IN_NODE( c, str, exito, fracaso )\ +while( c != NULL ){\ + if( xmlStrcmp(c->name, _xmlChar(str)) == 0 ){\ + exito;\ + };\ + c = c->next;\ +};\ +if( c == NULL ){\ + printf("Can't find tag <%s>.", str);\ + fracaso;\ +}; + +int do_tcp_connect( xmlNodePtr p, int *sock_tcp ); +int do_tcp_close( int sock_tcp ); +int do_smpp_connect( xmlNodePtr p, int sock_tcp ); +int do_smpp_send_message( xmlNodePtr p, int sock_tcp ); +int do_smpp_send_message2( xmlNodePtr p, int sock_tcp, int sequence ); +int do_smpp_close( int sock_tcp ); +#endif /* _sendwp_h_ */ diff --git a/test_apps/sendwp.xml b/test_apps/sendwp.xml new file mode 100644 index 0000000..6d9dab1 --- /dev/null +++ b/test_apps/sendwp.xml @@ -0,0 +1,12 @@ + + + + + + + + + + diff --git a/test_apps/smpp.c b/test_apps/smpp.c new file mode 100644 index 0000000..ea45d26 --- /dev/null +++ b/test_apps/smpp.c @@ -0,0 +1,289 @@ + +/* + * Copyright (C) 2006 Raul Tremsal + * File : smpp.c + * Author: Raul Tremsal + * + * This file is part of libsmpp34 (c-open-smpp3.4 library). + * + * The libsmpp34 library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of the + * License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this library; if not, write to the Free Software Foundation, + * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +#ifdef __linux__ +#include +#endif + +#include "smpp34.h" +#include "smpp34_structs.h" +#include "smpp34_params.h" + +#include "esme.h" + +extern int smpp34_errno; +extern char smpp34_strerror[2048]; + +uint8_t print_buffer[2048]; +uint8_t local_buffer[1024]; +int local_buffer_len = 0; +int ret = 0; +uint32_t tempo = 0; +uint32_t cmd_id = 0; + +int unhex(char c) { + if (c >= '0' && c <= '9') + return (c - '0'); + if (c >= 'a' && c <= 'f') + return (c - 'a' + 10); + if (c >= 'A' && c <= 'F') + return (c - 'A' + 10); + return (-1); +} + +int hex2bin(char *hex, unsigned char *bin) { + int i = 0; + int j = 0; + + /* Trim string if comments present */ + if (strchr(hex, '#') != NULL) + *strchr(hex, '#') = 0; + if (strchr(hex, '*') != NULL) + *strchr(hex, '*') = 0; + if (strchr(hex, '\'') != NULL) + *strchr(hex, '\'') = 0; + + for (i = 0; i < strlen(hex); i++) { + if (hex[i] >= '0' && unhex(hex[i]) < 0){ + printf("Bad hex digit encountered.\n"); + return( -1 ); + } + } + + for (i = 0; i < strlen(hex); i++) { + if (hex[i] < '0') + continue; + if (hex[i] >= '0' && hex[i+1] >= '0') { + bin[j++] = unhex(hex[i])*16+unhex(hex[i+1]); + i++; // skip one + continue; + } + if (hex[i] >= '0') { + bin[j++] = unhex(hex[i]); + } + } + return (j); +} + +int do_smpp_connect( xmlNodePtr p, int sock_tcp ) +{ + bind_transmitter_t req; + bind_transmitter_resp_t res; + memset(&req, 0, sizeof(bind_transmitter_t)); + memset(&res, 0, sizeof(bind_transmitter_resp_t)); + + /* Init PDU ***********************************************************/ + req.command_length = 0; + req.command_id = BIND_TRANSMITTER; + req.command_status = ESME_ROK; + req.sequence_number = 1; + GET_PROP_STR( req.system_id, p, "system_id" ); + GET_PROP_STR( req.password, p, "password" ); + GET_PROP_STR( req.system_type, p, "system_type" ); + req.interface_version = SMPP_VERSION; +#if 0 /* if you need add */ + req.addr_ton = 2; + req.addr_npi = 1; + snprintf( b.address_range, sizeof(b.address_range), "%s", ""); +#endif + + /* FIRST STEP: PACK AND SEND */ +#include "pack_and_send.inc" + /* Set a timer (PENDIENTE) ********************************************/ + /* SECOND STEP: READ AND UNPACK Response */ +#include "recv_and_unpack.inc" + destroy_tlv( res.tlv ); /* Por las dudas */ + + if( res.command_id != BIND_TRANSMITTER_RESP || + res.command_status != ESME_ROK ){ + printf("Error in BIND(BIND_TRANSMITTER)[%d:%d]\n", + res.command_id, res.command_status); + return( -1 ); + }; + return( 0 ); +}; + + +int do_smpp_send_message( xmlNodePtr p, int sock_tcp ) +{ + + char message[256]; + tlv_t tlv; + submit_sm_t req; + submit_sm_resp_t res; + memset(&req, 0, sizeof(submit_sm_t)); + memset(&res, 0, sizeof(submit_sm_resp_t)); + + /* Init PDU ***********************************************************/ + req.command_length = 0; + req.command_id = SUBMIT_SM; + req.command_status = ESME_ROK; + req.sequence_number = 2; +#if 0 /* if you need this */ + snprintf(b.service_type, sizeof(b.service_type), "%s", "SMS"); + b.source_addr_ton = 2; + b.source_addr_npi = 1; +#endif + GET_PROP_STR( req.source_addr, p, "src" ); +#if 0 /* if you need this */ + b.dest_addr_ton = 2; + b.dest_addr_npi = 0; +#endif + GET_PROP_STR( req.destination_addr, p, "dst" ); +#if 0 /* if you need this */ + b.esm_class = 0; + b.protocol_id = 0; + b.priority_flag = 0; + snprintf( b.schedule_delivery_time, TIME_LENGTH, "%s", ""); + snprintf( b.validity_period, TIME_LENGTH, "%s", ""); + b.registered_delivery = 0; + b.replace_if_present_flag =0; + b.data_coding = 0; + b.sm_default_msg_id = 0; +#endif + GET_PROP_STR( message, p, "msg" ); + +#if 0 /* Message in short_message scope */ + b.sm_length = strlen(TEXTO); + memcpy(b.short_message, TEXTO, b.sm_length); +#else /* Message in Payload */ + tlv.tag = TLVID_message_payload; + tlv.length = strlen(message); + memcpy(tlv.value.octet, message, tlv.length); + build_tlv( &(req.tlv), &tlv ); +#endif + + /* Add other optional param */ + tlv.tag = TLVID_user_message_reference; + tlv.length = sizeof(uint16_t); + tlv.value.val16 = 0x0024; + build_tlv( &(req.tlv), &tlv ); + + /* FIRST STEP: PACK AND SEND */ +#include "pack_and_send.inc" + destroy_tlv( req.tlv ); /* Por las dudas */ + /* Set a timer (PENDIENTE) ********************************************/ + /* SECOND STEP: READ AND UNPACK Response */ +#include "recv_and_unpack.inc" + + if( res.command_id != SUBMIT_SM_RESP || + res.command_status != ESME_ROK ){ + printf("Error in send(SUBMIT_SM)[%08X:%08X]\n", + res.command_id, res.command_status); + return( -1 ); + }; + return( 0 ); +}; + + +int do_smpp_send_message2( xmlNodePtr p, int sock_tcp, int sequence ) +{ + + char message[512]; + submit_sm_t req; + submit_sm_resp_t res; + memset(&req, 0, sizeof(submit_sm_t)); + memset(&res, 0, sizeof(submit_sm_resp_t)); + + /* Init PDU ***********************************************************/ + req.command_length = 0; + req.command_id = SUBMIT_SM; + req.command_status = ESME_ROK; + req.sequence_number = sequence; + GET_PROP_STR( req.service_type, p, "service_type" ); + + GET_PROP_INT( req.source_addr_ton, p, "source_addr_ton" ); + GET_PROP_INT( req.source_addr_npi, p, "source_addr_npi" ); + GET_PROP_STR( req.source_addr, p, "src" ); + + GET_PROP_INT( req.dest_addr_ton, p, "dest_addr_ton" ); + GET_PROP_INT( req.dest_addr_npi, p, "dest_addr_npi" ); + GET_PROP_STR( req.destination_addr, p, "dst" ); + + GET_PROP_INT( req.esm_class, p, "esm_class" ); + GET_PROP_INT( req.protocol_id, p, "protocol_id" ); + GET_PROP_INT( req.priority_flag, p, "priority_flag" ); + GET_PROP_STR( req.schedule_delivery_time, p, "schedule_delivery_time" ); + GET_PROP_STR( req.validity_period, p, "validity_period" ); + GET_PROP_INT( req.registered_delivery, p, "registered_delivery" ); + GET_PROP_INT( req.replace_if_present_flag, p, "replace_if_present_flag" ); + GET_PROP_INT( req.data_coding, p, "data_coding" ); + GET_PROP_INT( req.sm_default_msg_id, p, "sm_default_msg_id" ); + GET_PROP_STR( message, p, "hex" ); + req.sm_length = hex2bin(message, req.short_message); + + /* FIRST STEP: PACK AND SEND */ +#include "pack_and_send.inc" + destroy_tlv( req.tlv ); /* Por las dudas */ + /* Set a timer (PENDIENTE) ********************************************/ + /* SECOND STEP: READ AND UNPACK Response */ +#include "recv_and_unpack.inc" + + if( res.command_id != SUBMIT_SM_RESP || + res.command_status != ESME_ROK ){ + printf("Error in send(SUBMIT_SM)[%d:%d]\n", + res.command_id, res.command_status); + return( -1 ); + }; + return( 0 ); +}; + + +int do_smpp_close( int sock_tcp ) +{ + unbind_t req; + unbind_resp_t res; + memset(&req, 0, sizeof(unbind_t)); + memset(&res, 0, sizeof(unbind_resp_t)); + + /* Init PDU ***********************************************************/ + req.command_length = 0; + req.command_id = UNBIND; + req.command_status = ESME_ROK; + req.sequence_number = 3; + + /* FIRST STEP: PACK AND SEND */ +#include "pack_and_send.inc" + /* Set a timer (PENDIENTE) ********************************************/ + /* SECOND STEP: READ AND UNPACK Response */ +#include "recv_and_unpack.inc" + + if( res.command_id != UNBIND_RESP || + res.command_status != ESME_ROK ){ + printf("Error in send(UNBIND)[%d:%d]\n", + res.command_id, res.command_status); + return( -1 ); + }; + + return( 0 ); +}; diff --git a/test_apps/tcp.c b/test_apps/tcp.c new file mode 100644 index 0000000..ef572df --- /dev/null +++ b/test_apps/tcp.c @@ -0,0 +1,94 @@ + +/* + * Copyright (C) 2006 Raul Tremsal + * File : tcp.c + * Author: Raul Tremsal + * + * This file is part of libsmpp34 (c-open-smpp3.4 library). + * + * The libsmpp34 library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of the + * License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this library; if not, write to the Free Software Foundation, + * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +#include "esme.h" + +int do_tcp_connect( xmlNodePtr p, int *s ) +{ + int ret = 0; + int n = 1; + struct hostent _host; +#ifdef __linux__ + struct hostent *__host_result; +#endif + struct in_addr addr; + struct sockaddr_in name; + + char h[256]; + char ahost[1024]; + int port = 0; + + + GET_PROP_STR(h, p, "host"); + GET_PROP_INT(port, p, "port"); + + if((*s = socket(AF_INET, SOCK_STREAM, 0)) == -1){ + printf("Error in socket()\n"); + ret = -1; goto lb_tcp_connect_end; + }; + if( setsockopt(*s, SOL_SOCKET, SO_REUSEADDR, (char*)&n, sizeof(n)) == -1){ + printf("Error in setsockopt().\n"); + ret = -1; goto lb_tcp_connect_end; + }; + +#ifdef __linux__ + if( gethostbyname_r(h,&_host,ahost,sizeof(ahost),&__host_result,&n) != 0) +#else /* solaris */ + if( gethostbyname_r(h,&_host,ahost,sizeof(ahost),&n) == NULL) +#endif + { + printf("Error in gethostbyname_r().\n"); + ret = -1; goto lb_tcp_connect_end; + }; + + memcpy(&addr.s_addr, _host.h_addr_list[0], sizeof(struct in_addr)); + name.sin_family = AF_INET; + name.sin_port = htons( port ); + name.sin_addr = addr; + + if(connect(*s,(struct sockaddr *)&name,sizeof(name)) != 0){ + printf("Error in connect(%s:%d)\n", h, port); + ret = -1; goto lb_tcp_connect_end; + }; + +lb_tcp_connect_end: + return( ret ); +}; + + +int do_tcp_close( int sock_tcp ) +{ + + close( sock_tcp ); + return( 0 ); +}; -- cgit v1.2.3