| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
#include "app_sip.h" |
| 37 |
#include <sys/types.h> |
| 38 |
#include <sys/socket.h> |
| 39 |
#include <netinet/in.h> |
| 40 |
#include <arpa/inet.h> |
| 41 |
#include <unistd.h> |
| 42 |
typedef int SOCKET; |
| 43 |
typedef struct sockaddr_in SOCKADDR_IN; |
| 44 |
typedef struct sockaddr SOCKADDR; |
| 45 |
|
| 46 |
|
| 47 |
void *rtr_socket(void *arg) |
| 48 |
{ |
| 49 |
SOCKET sock; |
| 50 |
SOCKADDR_IN sin, csin; |
| 51 |
struct rtrsipaor rtrsip; |
| 52 |
int rcvbytes=0; |
| 53 |
sock = socket(AF_INET, SOCK_STREAM, 0); |
| 54 |
sin.sin_addr.s_addr = inet_addr("127.0.0.1"); |
| 55 |
sin.sin_family = AF_INET; |
| 56 |
sin.sin_port = htons(as_conf->rtr_port); |
| 57 |
socklen_t sinsize = sizeof(csin); |
| 58 |
int accepted=0; |
| 59 |
|
| 60 |
if(!bind(sock, (SOCKADDR*)&sin, sizeof(sin))) |
| 61 |
{ |
| 62 |
if(listen(sock,1)) |
| 63 |
{ |
| 64 |
TRACE_DEBUG(INFO,"ERROR on listen!"); |
| 65 |
} |
| 66 |
|
| 67 |
while(1) |
| 68 |
{ |
| 69 |
accepted=accept(sock, (struct sockaddr *)&csin,&sinsize); |
| 70 |
if(accepted>-1) |
| 71 |
{ |
| 72 |
rcvbytes=recv(accepted, &rtrsip, sizeof(struct rtrsipaor),0); |
| 73 |
|
| 74 |
if(rcvbytes>-1) |
| 75 |
{ |
| 76 |
|
| 77 |
app_sip_RTR_cb(&rtrsip); |
| 78 |
} |
| 79 |
} |
| 80 |
} |
| 81 |
} |
| 82 |
else |
| 83 |
TRACE_DEBUG(INFO,"Can't create socket!"); |
| 84 |
|
| 85 |
|
| 86 |
pthread_exit(NULL); |
| 87 |
|
| 88 |
} |
| 89 |
|
| 90 |
int app_sip_RTR_cb(struct rtrsipaor *structure) |
| 91 |
{ |
| 92 |
TRACE_ENTRY("%p", structure); |
| 93 |
|
| 94 |
int got_username=0; |
| 95 |
int got_streason=0; |
| 96 |
int num_aor=0; |
| 97 |
struct dict_object * rtr_model=NULL; |
| 98 |
struct msg * message=NULL; |
| 99 |
struct avp *groupedavp=NULL, *avp=NULL; |
| 100 |
union avp_value value; |
| 101 |
|
| 102 |
|
| 103 |
if(structure->username[0]!='\0') |
| 104 |
got_username=1; |
| 105 |
|
| 106 |
if(structure->sip_aor1[0]!='\0') |
| 107 |
{ |
| 108 |
num_aor++; |
| 109 |
if(structure->sip_aor2[0]!='\0') |
| 110 |
{ |
| 111 |
num_aor++; |
| 112 |
if(structure->sip_aor3[0]!='\0') |
| 113 |
num_aor++; |
| 114 |
} |
| 115 |
} |
| 116 |
|
| 117 |
if(structure->strreason!='\0') |
| 118 |
got_streason=1; |
| 119 |
|
| 120 |
|
| 121 |
TRACE_DEBUG(FULL,"Request for %d SIP_AOR to be deregistred.",num_aor); |
| 122 |
|
| 123 |
if((got_username + num_aor)==0) |
| 124 |
{ |
| 125 |
|
| 126 |
TRACE_DEBUG(INFO,"Can not proceed because there is no SIP_AOR or Username"); |
| 127 |
return EINVAL; |
| 128 |
} |
| 129 |
if(structure->reason<0) |
| 130 |
{ |
| 131 |
|
| 132 |
TRACE_DEBUG(INFO,"Incorrect Reason-Code"); |
| 133 |
return EINVAL; |
| 134 |
} |
| 135 |
|
| 136 |
if(structure->desthost[0]=='\0') |
| 137 |
{ |
| 138 |
|
| 139 |
TRACE_DEBUG(INFO,"No Destination_Host was provided!"); |
| 140 |
return EINVAL; |
| 141 |
} |
| 142 |
|
| 143 |
CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_COMMAND, CMD_BY_NAME, "Registration-Termination-Request", &rtr_model, ENOENT) ); |
| 144 |
CHECK_FCT( fd_msg_new (rtr_model, 0, &message)); |
| 145 |
|
| 146 |
|
| 147 |
{ |
| 148 |
#define APP_SIP_SID_OPT "app_sip" |
| 149 |
CHECK_FCT( fd_msg_new_session( message, (os0_t)APP_SIP_SID_OPT, CONSTSTRLEN(APP_SIP_SID_OPT) ) ); |
| 150 |
} |
| 151 |
|
| 152 |
|
| 153 |
{ |
| 154 |
CHECK_FCT( fd_msg_avp_new ( sip_dict.Auth_Application_Id, 0, &avp ) ); |
| 155 |
value.i32 = 6; |
| 156 |
CHECK_FCT( fd_msg_avp_setvalue ( avp, &value ) ); |
| 157 |
CHECK_FCT( fd_msg_avp_add ( message, MSG_BRW_LAST_CHILD, avp) ); |
| 158 |
} |
| 159 |
|
| 160 |
|
| 161 |
{ |
| 162 |
CHECK_FCT( fd_msg_avp_new ( sip_dict.Auth_Session_State, 0, &avp ) ); |
| 163 |
value.i32=1; |
| 164 |
CHECK_FCT( fd_msg_avp_setvalue( avp, &value ) ); |
| 165 |
CHECK_FCT( fd_msg_avp_add( message, MSG_BRW_LAST_CHILD, avp ) ); |
| 166 |
} |
| 167 |
|
| 168 |
|
| 169 |
CHECK_FCT( fd_msg_add_origin ( message, 0 )); |
| 170 |
|
| 171 |
|
| 172 |
{ |
| 173 |
CHECK_FCT( fd_msg_avp_new ( sip_dict.Destination_Host, 0, &avp ) ); |
| 174 |
value.os.data=(unsigned char *)structure->desthost; |
| 175 |
value.os.len=(size_t)strlen(structure->desthost); |
| 176 |
CHECK_FCT( fd_msg_avp_setvalue( avp, &value ) ); |
| 177 |
CHECK_FCT( fd_msg_avp_add( message, MSG_BRW_LAST_CHILD, avp ) ); |
| 178 |
} |
| 179 |
|
| 180 |
|
| 181 |
|
| 182 |
{ |
| 183 |
CHECK_FCT( fd_msg_avp_new ( sip_dict.SIP_Deregistration_Reason, 0, &groupedavp ) ); |
| 184 |
|
| 185 |
|
| 186 |
CHECK_FCT( fd_msg_avp_new ( sip_dict.SIP_Reason_Code, 0, &avp ) ); |
| 187 |
value.i32=structure->reason; |
| 188 |
CHECK_FCT( fd_msg_avp_setvalue( avp, &value ) ); |
| 189 |
CHECK_FCT( fd_msg_avp_add( groupedavp, MSG_BRW_LAST_CHILD, avp ) ); |
| 190 |
|
| 191 |
if(got_streason) |
| 192 |
{ |
| 193 |
|
| 194 |
CHECK_FCT( fd_msg_avp_new ( sip_dict.SIP_Reason_Info, 0, &avp ) ); |
| 195 |
value.os.data=(unsigned char *)structure->strreason; |
| 196 |
value.os.len=(size_t)strlen(structure->strreason); |
| 197 |
CHECK_FCT( fd_msg_avp_setvalue( avp, &value ) ); |
| 198 |
CHECK_FCT( fd_msg_avp_add( groupedavp, MSG_BRW_LAST_CHILD, avp ) ); |
| 199 |
} |
| 200 |
|
| 201 |
|
| 202 |
CHECK_FCT( fd_msg_avp_add( message, MSG_BRW_LAST_CHILD, groupedavp ) ); |
| 203 |
} |
| 204 |
|
| 205 |
|
| 206 |
{ |
| 207 |
if(got_username) |
| 208 |
{ |
| 209 |
CHECK_FCT( fd_msg_avp_new ( sip_dict.User_Name, 0, &avp ) ); |
| 210 |
value.os.data=(unsigned char *)structure->username; |
| 211 |
value.os.len=(size_t)strlen(structure->username); |
| 212 |
CHECK_FCT( fd_msg_avp_setvalue( avp, &value ) ); |
| 213 |
CHECK_FCT( fd_msg_avp_add( message, MSG_BRW_LAST_CHILD, avp ) ); |
| 214 |
} |
| 215 |
} |
| 216 |
|
| 217 |
|
| 218 |
{ |
| 219 |
if(num_aor>0) |
| 220 |
{ |
| 221 |
CHECK_FCT( fd_msg_avp_new ( sip_dict.SIP_AOR, 0, &avp ) ); |
| 222 |
value.os.data=(unsigned char *)structure->sip_aor1; |
| 223 |
value.os.len=(size_t)strlen(structure->sip_aor1); |
| 224 |
CHECK_FCT( fd_msg_avp_setvalue( avp, &value ) ); |
| 225 |
CHECK_FCT( fd_msg_avp_add( message, MSG_BRW_LAST_CHILD, avp ) ); |
| 226 |
if(num_aor>1) |
| 227 |
{ |
| 228 |
CHECK_FCT( fd_msg_avp_new ( sip_dict.SIP_AOR, 0, &avp ) ); |
| 229 |
value.os.data=(unsigned char *)structure->sip_aor2; |
| 230 |
value.os.len=(size_t)strlen(structure->sip_aor2); |
| 231 |
CHECK_FCT( fd_msg_avp_setvalue( avp, &value ) ); |
| 232 |
CHECK_FCT( fd_msg_avp_add( message, MSG_BRW_LAST_CHILD, avp ) ); |
| 233 |
if(num_aor>2) |
| 234 |
{ |
| 235 |
CHECK_FCT( fd_msg_avp_new ( sip_dict.SIP_AOR, 0, &avp ) ); |
| 236 |
value.os.data=(unsigned char *)structure->sip_aor3; |
| 237 |
value.os.len=(size_t)strlen(structure->sip_aor3); |
| 238 |
CHECK_FCT( fd_msg_avp_setvalue( avp, &value ) ); |
| 239 |
CHECK_FCT( fd_msg_avp_add( message, MSG_BRW_LAST_CHILD, avp ) ); |
| 240 |
} |
| 241 |
} |
| 242 |
} |
| 243 |
} |
| 244 |
|
| 245 |
|
| 246 |
|
| 247 |
CHECK_FCT( fd_msg_send( &message, NULL, NULL )); |
| 248 |
|
| 249 |
return 0; |
| 250 |
} |
| 251 |
|
| 252 |
|
| 253 |
int app_sip_RTA_cb( struct msg ** msg, struct avp * paramavp, struct session * sess, void * opaque, enum disp_action * act) |
| 254 |
{ |
| 255 |
|
| 256 |
|
| 257 |
|
| 258 |
|
| 259 |
|
| 260 |
|
| 261 |
|
| 262 |
|
| 263 |
|
| 264 |
|
| 265 |
|
| 266 |
|
| 267 |
|
| 268 |
|
| 269 |
|
| 270 |
|
| 271 |
|
| 272 |
|
| 273 |
|
| 274 |
|
| 275 |
|
| 276 |
|
| 277 |
|
| 278 |
|
| 279 |
|
| 280 |
|
| 281 |
|
| 282 |
|
| 283 |
|
| 284 |
|
| 285 |
|
| 286 |
|
| 287 |
|
| 288 |
|
| 289 |
|
| 290 |
|
| 291 |
|
| 292 |
|
| 293 |
|
| 294 |
|
| 295 |
|
| 296 |
|
| 297 |
|
| 298 |
|
| 299 |
|
| 300 |
|
| 301 |
|
| 302 |
|
| 303 |
|
| 304 |
|
| 305 |
|
| 306 |
|
| 307 |
|
| 308 |
|
| 309 |
|
| 310 |
|
| 311 |
|
| 312 |
return 0; |
| 313 |
|
| 314 |
} |
| 315 |
|