blob: f28beefb4409b6c7d90be38074ead5502b3ad9ad [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//This callback is specific to SUSCRIBER LOCATOR. We must look for the "serving" SIP server
39int app_sip_SL_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;
45 struct avp_hdr *avphdr;
46 union avp_value value;
47
48 //Result_Code to return in the answer
49 char result[55];
50 int ret=0;
51
52
53 if (msg == NULL)
54 return EINVAL;
55
56
57
58 // Create answer header
59 qry = *msg;
60 CHECK_FCT( fd_msg_new_answer_from_req ( fd_g_config->cnf_dict, msg, 0 ) );
61 ans = *msg;
62
63
64 //Add the Auth-Application-Id
65 {
66 CHECK_FCT( fd_msg_avp_new ( sip_dict.Auth_Application_Id, 0, &avp ) );
67 value.i32 = 6;
68 CHECK_FCT( fd_msg_avp_setvalue ( avp, &value ) );
69 CHECK_FCT( fd_msg_avp_add ( ans, MSG_BRW_LAST_CHILD, avp) );
70 }
71
72 // Add the Auth-Session-State AVP
73 {
74
75 CHECK_FCT( fd_msg_search_avp ( qry, sip_dict.Auth_Session_State, &avp) );
76 CHECK_FCT( fd_msg_avp_hdr( avp, &avphdr ) );
77
78 CHECK_FCT( fd_msg_avp_new ( sip_dict.Auth_Session_State, 0, &avp ) );
79 CHECK_FCT( fd_msg_avp_setvalue( avp, avphdr->avp_value ) );
80 CHECK_FCT( fd_msg_avp_add( ans, MSG_BRW_LAST_CHILD, avp ) );
81 }
82
83
84 // Add the Redirect Host AVP
85 {
86 CHECK_FCT( fd_msg_search_avp ( qry, sip_dict.SIP_AOR, &avp) );
87 CHECK_FCT( fd_msg_avp_hdr( avp, &avphdr ) );
88 size_t diameterurilen;
89 char * diameter_uri=NULL;
90
91
92
93 ret=get_diameter_uri(avphdr->avp_value->os.data, avphdr->avp_value->os.len, &diameter_uri, &diameterurilen);
94
95 //found
96 if(ret==0)
97 {
98 if(diameter_uri==NULL)
99 {
100 //There is a problem because we must get a Diameter_URI here
101 strcpy(result,"DIAMETER_UNABLE_TO_COMPLY");
102 goto out;
103 }
104 else
105 {
106 CHECK_FCT( fd_msg_avp_new ( sip_dict.Redirect_Host, 0, &avp ) );
107 value.os.data=(unsigned char *)diameter_uri;
108 value.os.len=diameterurilen;
109 CHECK_FCT( fd_msg_avp_setvalue( avp, &value ) );
110 CHECK_FCT( fd_msg_avp_add( ans, MSG_BRW_LAST_CHILD, avp ) );
111
112 CHECK_FCT( fd_msg_avp_new ( sip_dict.Redirect_Host_Usage, 0, &avp ) );
113 value.i32=ALL_USER; //All the request about the same user must be sent to this server
114 CHECK_FCT( fd_msg_avp_setvalue( avp, &value ) );
115 CHECK_FCT( fd_msg_avp_add( ans, MSG_BRW_LAST_CHILD, avp ) );
116 strcpy(result,"DIAMETER_SUCCESS");
117 }
118 }
119 else if(ret==1)
120 {//not found
121 //We don't know this SIP_AOR in SL
122 strcpy(result,"DIAMETER_ERROR_USER_UNKNOWN");
123 goto out;
124 }
125 else
126 {// returned 2, impossible to make request
127 //We couldn't make the request, we must stop process!
128 strcpy(result,"DIAMETER_UNABLE_TO_COMPLY");
129 goto out;
130 }
131 }
132
133
134out:
135 CHECK_FCT( fd_msg_rescode_set( ans, result, NULL, NULL, 1 ) );
136
137
138
139 CHECK_FCT( fd_msg_send( msg, NULL, NULL ));
140
141
142
143 return 0;
144}