1
2 /*
3 * Copyright (C) 2006 Raul Tremsal
4 * File : sendwp.c
5 * Author: Raul Tremsal <ultraismo@yahoo.com>
6 *
7 * This file is part of libsmpp34 (c-open-smpp3.4 library).
8 *
9 * The libsmpp34 library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public License as
11 * published by the Free Software Foundation; either version 2.1 of the
12 * License, or (at your option) any later version.
13 *
14 * This library is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
16 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
17 * License for more details.
18 *
19 * You should have received a copy of the GNU Lesser General Public License
20 * along with this library; if not, write to the Free Software Foundation,
21 * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 *
23 */
24
25 #include <stdio.h>
26 #include <unistd.h>
27 #include <string.h>
28 #include <libxml/xmlmemory.h>
29 #include <libxml/parser.h>
30
31 #include "sendwp.h"
32
33 extern char *optarg;
34 char file_config[256];
35 xmlDocPtr d; /* document */
36 xmlNodePtr c; /* config */
37 xmlNodePtr conn_tcp; /* conn_tcp */
38 xmlNodePtr conn_smpp; /* conn_smpp */
39 xmlNodePtr smpp_msg; /* smpp_msg */
40
41 int sock_tcp = 0;
42
43
44 #define HELP_FORMAT " -c file.xml [-h]\n" \
45 " -c /path/to/file.xml: config file path.\n" \
46 " -h : Help, show this message.\n"
47
main(int argc,char ** argv)48 int main( int argc, char **argv )
49 {
50 int co;
51 int secuencia = 3;
52
53 while( (co = getopt(argc, argv, "c:h")) != EOF ){
54 switch( co ){
55 case 'c':
56 snprintf(file_config, sizeof(file_config), "%s", optarg);
57 break;
58 default:
59 printf("Error: unrecognized option\n");
60 case 'h':
61 printf("usage: %s %s\n", argv[0], HELP_FORMAT);
62 return( -1 );
63 };
64 };
65
66 if( strcmp(file_config, "") == 0 ){ printf("Error in parameters\n");
67 printf("usage: %s %s\n", argv[0], HELP_FORMAT); return( -1 ); };
68 d = xmlParseFile( file_config );
69 if( d == NULL ){ printf("Error in xmlParseFile()\n");
70 printf("usage: %s %s\n", argv[0], HELP_FORMAT); return( -1 ); };
71 c = xmlDocGetRootElement( d );
72 if( c == NULL ){ printf("Error in xmlDocGetRootElement()\n");
73 printf("usage: %s %s\n", argv[0], HELP_FORMAT); return( -1 ); };
74
75 XML_IN_NODE(c, "config", c=c->xmlChildrenNode;break;, return(-1); );
76 XML_IN_NODE(c, "conn_tcp", conn_tcp=c;break;, return(-1); );
77 XML_IN_NODE(c, "conn_smpp", conn_smpp=c;break;, return(-1); );
78 XML_IN_NODE(c, "smpp_msg", smpp_msg=c;break;, return(-1); );
79
80 /* do tcp connect */
81 if( do_tcp_connect( conn_tcp, &sock_tcp ) ){
82 printf("Error in tcp connect.\n"); goto lb_free_document; };
83
84 /* do smpp connect */
85 if( do_smpp_connect( conn_smpp, sock_tcp ) ){
86 printf("Error in smpp connect.\n"); goto lb_tcp_close; };
87
88 /* do smpp send message */
89 while( smpp_msg != NULL ){
90 if( do_smpp_send_message2( smpp_msg, sock_tcp, secuencia++ ) ){
91 printf("Error in smpp send message.\n");
92 goto lb_smpp_close;
93 };
94 smpp_msg = smpp_msg->next;
95 smpp_msg = smpp_msg->next;
96 };
97
98
99 lb_smpp_close: /* do smpp close */
100 if( do_smpp_close( sock_tcp ) ) printf("Error in smpp close.\n");
101
102 lb_tcp_close: /* do tcp close */
103 if( do_tcp_close( sock_tcp ) ) printf("Error in tcp close.\n");
104
105 lb_free_document: /* free xml document */
106 xmlFreeDoc( d );
107
108 return( 0 );
109 };
110