blob: 5d9dafd5086d0c4438bed7d174c69c1dd9f6ca71 [file] [log] [blame]
Harald Welte4b233b42012-11-07 08:32:31 +01001
2/*
3 * Copyright (C) 2006 Raul Tremsal
4 * File : esme.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>
Vadim Yanitskiye9ffa492024-01-08 20:46:03 +070026#include <stdlib.h>
Harald Welte4b233b42012-11-07 08:32:31 +010027#include <unistd.h>
28#include <string.h>
29#include <libxml/xmlmemory.h>
30#include <libxml/parser.h>
31
32#include "esme.h"
33
34extern char *optarg;
35char file_config[256];
36xmlDocPtr d; /* document */
37xmlNodePtr c; /* config */
38xmlNodePtr conn_tcp; /* conn_tcp */
39xmlNodePtr conn_smpp; /* conn_smpp */
40xmlNodePtr smpp_msg; /* smpp_msg */
41
42int sock_tcp = 0;
43
44
45#define HELP_FORMAT " -c file.xml [-h]\n" \
46" -c /path/to/file.xml: config file path.\n" \
47" -h : Help, show this message.\n"
48
49int main( int argc, char **argv )
50{
51 int co;
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");
Neels Hofmeyrcf9e5f82018-10-29 18:32:49 +010060 /* fall thru */
Harald Welte4b233b42012-11-07 08:32:31 +010061 case 'h':
62 printf("usage: %s %s\n", argv[0], HELP_FORMAT);
63 return( -1 );
64 };
65 };
66
67 if( strcmp(file_config, "") == 0 ){ printf("Error in parameters\n");
68 printf("usage: %s %s\n", argv[0], HELP_FORMAT); return( -1 ); };
69 d = xmlParseFile( file_config );
70 if( d == NULL ){ printf("Error in xmlParseFile()\n");
71 printf("usage: %s %s\n", argv[0], HELP_FORMAT); return( -1 ); };
72 c = xmlDocGetRootElement( d );
73 if( c == NULL ){ printf("Error in xmlDocGetRootElement()\n");
74 printf("usage: %s %s\n", argv[0], HELP_FORMAT); return( -1 ); };
75
76 XML_IN_NODE(c, "config", c=c->xmlChildrenNode;break;, return(-1); );
77 XML_IN_NODE(c, "conn_tcp", conn_tcp=c;break;, return(-1); );
78 XML_IN_NODE(c, "conn_smpp", conn_smpp=c;break;, return(-1); );
79 XML_IN_NODE(c, "smpp_msg", smpp_msg=c;break;, return(-1); );
80
81 /* do tcp connect */
82 if( do_tcp_connect( conn_tcp, &sock_tcp ) ){
83 printf("Error in tcp connect.\n"); goto lb_free_document; };
84
85 /* do smpp connect */
86 if( do_smpp_connect( conn_smpp, sock_tcp ) ){
87 printf("Error in smpp connect.\n"); goto lb_tcp_close; };
88
89 /* do smpp send message */
90 if( do_smpp_send_message( smpp_msg, sock_tcp ) ){
91 printf("Error in smpp send message.\n"); goto lb_smpp_close; };
92
93 /* That's all folks */
94 /* taaa taratatata tatatatatata */
95 /* taaa taratatata tatatatatata */
96 /* ta aaa ta aaa tatatata */
97 /* ta aaa ta aaa tatatata */
98 /* taaa taratatata tatatatatata */
99 /* :) */
100
101lb_smpp_close: /* do smpp close */
102 if( do_smpp_close( sock_tcp ) ) printf("Error in smpp close.\n");
103
104lb_tcp_close: /* do tcp close */
105 if( do_tcp_close( sock_tcp ) ) printf("Error in tcp close.\n");
106
107lb_free_document: /* free xml document */
108 xmlFreeDoc( d );
109
110 return( 0 );
111};