blob: e2c372a5d294505cc3b0427bdf77982fa604f0f7 [file] [log] [blame]
Brian Waters13d96012017-12-08 16:53:31 -06001/*********************************************************************************************************
2* Software License Agreement (BSD License) *
3* Author: Alexandre Westfahl <awestfahl@freediameter.net> *
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#include "app_sip.h"
37
38
39int app_sip_LIR_cb( struct msg ** msg, struct avp * paramavp, struct session * sess, void * opaque, enum disp_action * act)
40{
41 TRACE_ENTRY("%p %p %p %p", msg, paramavp, sess, act);
42
43 struct msg *ans, *qry;
44 struct avp *avp, *groupedavp;
45 struct avp_hdr *avphdr;
46 union avp_value value;
47 int ret=0;
48
49 //Result_Code to return in the answer
50 char result[55];
51
52 if (msg == NULL)
53 return EINVAL;
54
55
56 // Create answer header
57 qry = *msg;
58 CHECK_FCT( fd_msg_new_answer_from_req ( fd_g_config->cnf_dict, msg, 0 ) );
59 ans = *msg;
60
61 //Add the Auth-Application-Id
62 {
63 CHECK_FCT( fd_msg_avp_new ( sip_dict.Auth_Application_Id, 0, &avp ) );
64 value.i32 = 6;
65 CHECK_FCT( fd_msg_avp_setvalue ( avp, &value ) );
66 CHECK_FCT( fd_msg_avp_add ( ans, MSG_BRW_LAST_CHILD, avp) );
67 }
68 // Add the Auth-Session-State AVP
69 {
70
71 CHECK_FCT( fd_msg_search_avp ( qry, sip_dict.Auth_Session_State, &avp) );
72 CHECK_FCT( fd_msg_avp_hdr( avp, &avphdr ) );
73
74 CHECK_FCT( fd_msg_avp_new ( sip_dict.Auth_Session_State, 0, &avp ) );
75 CHECK_FCT( fd_msg_avp_setvalue( avp, avphdr->avp_value ) );
76 CHECK_FCT( fd_msg_avp_add( ans, MSG_BRW_LAST_CHILD, avp ) );
77 }
78
79
80 //Add a SIP_Server_URI
81 {
82 CHECK_FCT( fd_msg_search_avp ( qry, sip_dict.SIP_AOR, &avp) );
83 CHECK_FCT( fd_msg_avp_hdr( avp, &avphdr ) );
84
85
86
87
88
89 ret=exist_username(avphdr->avp_value->os.data, avphdr->avp_value->os.len);
90
91
92 if(ret==2)
93 {//error
94 /*
95 If the Diameter server cannot process the Diameter LIR command, e.g.,
96 due to a database error, the Diameter server MUST set the Result-Code
97 AVP value to DIAMETER_UNABLE_TO_COMPLY and return it in a Diameter
98 LIA message.
99 */
100 strcpy(result,"DIAMETER_UNABLE_TO_COMPLY");
101 goto out;
102 }
103 else if(ret==1)
104 {//not found
105 /*
106 One of the errors that the Diameter server may find is that the
107 SIP-AOR AVP value is not a valid user in the realm. In such cases,
108 the Diameter server MUST set the Result-Code AVP value to
109 DIAMETER_ERROR_USER_UNKNOWN and return it in a Diameter LIA message.
110
111 */
112 strcpy(result,"DIAMETER_ERROR_USER_UNKNOWN");
113 goto out;
114 }
115
116 //If we arrive here, the user is known
117 size_t sipserverurilen;
118 unsigned char * sipserver_uri=NULL;
119
120 ret=get_sipserver_uri(avphdr->avp_value->os.data, avphdr->avp_value->os.len, &sipserver_uri, &sipserverurilen);
121
122
123 if(ret==0)
124 {//found
125 if(sipserver_uri==NULL)
126 {
127 //There is a problem because we must get a Diameter_URI here
128 strcpy(result,"DIAMETER_UNABLE_TO_COMPLY");
129 goto out;
130 }
131 else
132 {
133 CHECK_FCT( fd_msg_avp_new ( sip_dict.SIP_Server_URI, 0, &avp ) );
134 value.os.data=(unsigned char *)sipserver_uri;
135 value.os.len=sipserverurilen;
136 CHECK_FCT( fd_msg_avp_setvalue ( avp, &value ) );
137 CHECK_FCT( fd_msg_avp_add ( ans, MSG_BRW_LAST_CHILD, avp) );
138
139 strcpy(result,"DIAMETER_SUCCESS");
140 }
141 }
142 else if(ret==1)
143 {//not found
144 //We don't know this SIP_AOR in SL, that means
145 strcpy(result,"DIAMETER_ERROR_USER_UNKNOWN");
146 goto out;
147 }
148 else
149 {// returned 2, impossible to make request
150 //We couldn't make the request, we must stop process!
151 strcpy(result,"DIAMETER_UNABLE_TO_COMPLY");
152 goto out;
153 }
154
155 //Adding SIP-Server-Capabilities
156 CHECK_FCT( fd_msg_avp_new ( sip_dict.SIP_Server_Capabilities, 0, &groupedavp ) );
157 //We add mandatory and optional capabilities
158 ret=get_sipserver_cap(avphdr->avp_value->os.data, avphdr->avp_value->os.len, &groupedavp);
159
160
161 if(ret==0)
162 {//found
163 if(sipserver_uri==NULL)
164 {
165 //There is a problem because we must get a Diameter_URI here
166 strcpy(result,"DIAMETER_UNABLE_TO_COMPLY");
167 CHECK_FCT( fd_msg_free( groupedavp ) );
168 goto out;
169 }
170 else
171 {
172
173 CHECK_FCT( fd_msg_avp_add ( ans, MSG_BRW_LAST_CHILD, groupedavp) );
174
175 strcpy(result,"DIAMETER_SUCCESS");
176 }
177 }
178 else if(ret==1)
179 {//not found
180 //We don't know this SIP_AOR in SL, that means
181 strcpy(result,"DIAMETER_ERROR_IDENTITY_NOT_REGISTERED");
182 CHECK_FCT( fd_msg_free( groupedavp ) );
183 goto out;
184 }
185 else
186 {// returned 2, impossible to make request
187 //We couldn't make the request, we must stop process!
188 strcpy(result,"DIAMETER_UNABLE_TO_COMPLY");
189 CHECK_FCT( fd_msg_free( groupedavp ) );
190 goto out;
191 }
192
193
194
195 }
196
197
198
199
200out:
201 CHECK_FCT( fd_msg_rescode_set( ans, result, NULL, NULL, 1 ) );
202
203 CHECK_FCT( fd_msg_send( msg, NULL, NULL ));
204
205
206
207 return 0;
208}