Debian Codegraph @

lib/freeDiameter-1.2.1/extensions/app_sip/tools/app_sip_ppr.c

raw symbols SCIP
1 /*********************************************************************************************************
2 * Software License Agreement (BSD License) *
3 * Author: Alexandre Westfahl <[email protected]> *
4 * *
5 * Copyright (c) 2010, Alexandre Westfahl, Teraoka Laboratory (Keio University), and the WIDE Project. *
6 * *
7 * All rights reserved. *
8 * *
9 * Redistribution and use of this software in source and binary forms, with or without modification, are *
10 * permitted provided that the following conditions are met: *
11 * *
12 * * Redistributions of source code must retain the above *
13 * copyright notice, this list of conditions and the *
14 * following disclaimer. *
15 * *
16 * * Redistributions in binary form must reproduce the above *
17 * copyright notice, this list of conditions and the *
18 * following disclaimer in the documentation and/or other *
19 * materials provided with the distribution. *
20 * *
21 * * Neither the name of the Teraoka Laboratory nor the *
22 * names of its contributors may be used to endorse or *
23 * promote products derived from this software without *
24 * specific prior written permission of Teraoka Laboratory *
25 * *
26 * *
27 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED *
28 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A *
29 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR *
30 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT *
31 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS *
32 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR *
33 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF *
34 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
35 *********************************************************************************************************/
36
37
38 // This file is separated from the source code because it is a separate command which will call push profile function in Diameter-SIP
39 #include <sys/types.h>
40 #include <sys/socket.h>
41 #include <netinet/in.h>
42 #include <arpa/inet.h>
43 #include <unistd.h>
44 typedef int SOCKET;
45 typedef struct sockaddr_in SOCKADDR_IN;
46 typedef struct sockaddr SOCKADDR;
47 #include <stdio.h>
48 #include <stdlib.h>
49 #include <string.h>
50
51 #include <errno.h>
52
53 struct pprsipaor
54 {
55 char username[200];
56 char datatype1[255];
57 char datatype2[255];
58 char datatype3[255];
59 int accounting;
60 };
61
62 int main (int argc, char **argv)
63 {
64 SOCKET sock;
65 SOCKADDR_IN sin;
66 struct pprsipaor pprsip;
67 int numdatatype=0,i=0;
68 int port=667;
69
70 sock = socket(AF_INET, SOCK_STREAM, 0);
71 sin.sin_addr.s_addr = inet_addr("127.0.0.1");
72 sin.sin_family = AF_INET;
73
74
75 //We initialize the structure
76 pprsip.username[0]='\0';
77 pprsip.datatype1[0]='\0';
78 pprsip.datatype2[0]='\0';
79 pprsip.datatype3[0]='\0';
80 pprsip.accounting=0;
81
82 //Start of arguments check
83 if(argc<3)
84 {
85 fprintf(stderr,"Missing arguments! You must at least provide a username.\n");
86 return 1;
87 }
88
89
90 for (i=1;i<argc;i++)
91 {
92 //We must check if it is a value or the name
93 if(strncmp(argv[i],"-",1)==0)
94 {
95 if(strcmp(argv[i],"-u")==0)
96 {
97 //Username
98 if(strlen(argv[i+1])<199)
99 {
100 strcpy(pprsip.username,argv[i+1]);
101 //We must not check the value
102 i++;
103 }
104 else
105 {
106 fprintf(stderr,"Username is too long!\n");
107 }
108 }
109 else if(strcmp(argv[i],"-t")==0)
110 {//User-data types
111 i++;
112 int j=i;
113
114 for(j=i;j<argc;j++)
115 {
116
117 if(strncmp(argv[i],"-",1)!=0)
118 {
119 if(strlen(argv[i])>254)
120 {
121 fprintf(stderr,"User-data type is too long!\n");
122 }
123 else
124 {
125 if(numdatatype<3)
126 {
127 switch(numdatatype)
128 {
129 case 0:
130 strcpy(pprsip.datatype1,argv[i]);
131 break;
132 case 1:
133 strcpy(pprsip.datatype2,argv[i]);
134 break;
135 case 2:
136 strcpy(pprsip.datatype3,argv[i]);
137 break;
138 }
139 numdatatype++;
140 }
141 else
142 {
143 fprintf(stderr,"You can not provide more than 3 User-data type at the same time!\n");
144 break;
145 }
146 }
147 i=j+1;
148 }
149 else
150 {
151 //We have a new argument
152 i--;
153 break;
154 }
155 }
156 }
157 else if(strcmp(argv[i],"-a")==0)
158 {
159 pprsip.accounting=1;
160
161
162 }
163 else if(strcmp(argv[i],"-p")==0)
164 {
165
166 if(sscanf(argv[i+1],"%d", &port)!=1)
167 {
168 fprintf(stderr,"Incorrect port number!\n");
169 return 1;
170 }
171
172
173 i++;
174 }
175
176 }
177 else
178 {
179 fprintf(stderr,"Unknown argument: %s\n",argv[i]);
180 i++;
181 }
182
183 }
184
185 //We set the port number
186 sin.sin_port = htons(port);
187
188
189 //We want a username
190 if(strlen(pprsip.username)==0)
191 {
192 fprintf(stderr,"You must provide a username!\n");
193 return 1;
194 }
195
196
197 fprintf(stderr,"%d!\n",port);
198
199 /*
200 //DEBUG
201 fprintf(stderr,"*%s*\n",pprsip.username);
202 fprintf(stderr,"*%s*\n",pprsip.datatype1);
203 fprintf(stderr,"*%s*\n",pprsip.datatype2);
204 fprintf(stderr,"*%s*\n",pprsip.datatype3);
205 fprintf(stderr,"*%d*\n",pprsip.accounting);
206
207 return 0;
208 */
209
210
211 //TODO: check args
212 if(!connect(sock, (SOCKADDR*)&sin, sizeof(sin)))
213 {
214 fprintf(stderr,"Connexion succeed!\n");
215
216
217 if(send(sock, &pprsip, sizeof(struct pprsipaor), 0))
218 fprintf(stderr,"sent OK!\n");
219 else
220 fprintf(stderr,"not sent\n");
221
222 }
223 else
224 {
225 fprintf(stderr,"Unable to connect\n");
226 }
227
228 close(sock);
229
230 return 0;
231 }
232
233
234
235
236
237