00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00055 #include "third_party_reg.h"
00056
00057 #include "mod.h"
00058 #include "../../mem/mem.h"
00059 #include "../../mem/shm_mem.h"
00060 #include "../../parser/parse_uri.h"
00061 #include "../../locking.h"
00062 #include "../tm/tm_load.h"
00063 #include "../scscf/scscf_load.h"
00064 #include "sip.h"
00065 #include "ims_pm.h"
00066
00067 extern struct tm_binds isc_tmb;
00069 extern str isc_my_uri;
00070 extern str isc_my_uri_sip;
00072 extern int isc_expires_grace;
00076 extern struct scscf_binds isc_scscfb;
00085 int isc_third_party_reg(struct sip_msg *msg, isc_match *m,isc_mark *mark)
00086 {
00087 r_third_party_registration r;
00088 int expires=0;
00089 str req_uri ={0,0};
00090 str to ={0,0};
00091 str pvni ={0,0};
00092 str pani ={0,0};
00093 str cv ={0,0};
00094
00095 struct hdr_field *hdr;
00096
00097 LOG(L_INFO,"INFO:"M_NAME":isc_third_party_reg: Enter\n");
00098
00099
00100 req_uri.len = m->server_name.len;
00101 req_uri.s = m->server_name.s;
00102
00103
00104 to = cscf_get_public_identity(msg);
00105
00106
00107
00108
00109
00110
00111 expires = cscf_get_max_expires(msg);
00112
00113
00114 pvni = cscf_get_visited_network_id(msg, &hdr);
00115
00116 pani = cscf_get_access_network_info(msg, &hdr);
00117
00118
00119
00120
00121 cv = cscf_get_charging_vector(msg, &hdr);
00122
00123 if (req_uri.s){
00124
00125 memset(&r,0,sizeof(r_third_party_registration));
00126
00127 r.req_uri = req_uri;
00128 r.to = to;
00129 r.from = isc_my_uri_sip;
00130 r.pvni = pvni;
00131 r.pani = pani;
00132 r.cv = cv;
00133 r.service_info = m->service_info;
00134
00135 if (expires<=0) r_send_third_party_reg(&r,0);
00136 else r_send_third_party_reg(&r,expires+isc_expires_grace);
00137 return ISC_RETURN_TRUE;
00138 }else{
00139 return ISC_RETURN_FALSE;
00140 }
00141 }
00142
00143
00144
00145
00146 static str method={"REGISTER",8};
00147 static str event_hdr={"Event: registration\r\n",21};
00148 static str max_fwds_hdr={"Max-Forwards: 10\r\n",18};
00149 static str expires_s={"Expires: ",9};
00150 static str expires_e={"\r\n",2};
00151 static str contact_s={"Contact: <",10};
00152 static str contact_e={">\r\n",3};
00153
00154 static str p_visited_network_id_s={"P-Visited-Network-ID: ",22};
00155 static str p_visited_network_id_e={"\r\n",2};
00156
00157 static str p_access_network_info_s={"P-Access-Network-Info: ",23};
00158 static str p_access_network_info_e={"\r\n",2};
00159
00160 static str p_charging_vector_s={"P-Charging-Vector: ",19};
00161 static str p_charging_vector_e={"\r\n",2};
00162 static str body_s={"<ims-3gpp version=\"1\"><service-info>",36};
00163 static str body_e={"</service-info></ims-3gpp>",26};
00164
00165
00166 #ifdef WITH_IMS_PM
00167 static str zero={0,0};
00168 #endif
00169
00176 int r_send_third_party_reg(r_third_party_registration *r,int expires)
00177 {
00178 str h={0,0};
00179 str b={0,0};
00180
00181 LOG(L_DBG,"DBG:"M_NAME":r_send_third_party_reg: REGISTER to <%.*s>\n",
00182 r->req_uri.len,r->req_uri.s);
00183
00184 h.len = event_hdr.len+max_fwds_hdr.len;
00185 h.len += expires_s.len + 12 + expires_e.len;
00186
00187 h.len += contact_s.len + isc_my_uri_sip.len + contact_e.len;
00188
00189 if (r->pvni.len) h.len += p_visited_network_id_s.len +
00190 p_visited_network_id_e.len + r->pvni.len;
00191
00192 if (r->pani.len) h.len += p_access_network_info_s.len +
00193 p_access_network_info_e.len + r->pani.len;
00194
00195 if (r->cv.len) h.len += p_charging_vector_s.len +
00196 p_charging_vector_e.len + r->cv.len;
00197
00198 h.s = pkg_malloc(h.len);
00199 if (!h.s){
00200 LOG(L_ERR,"ERR:"M_NAME":r_send_third_party_reg: Error allocating %d bytes\n",h.len);
00201 h.len = 0;
00202 return 0;
00203 }
00204
00205 h.len = 0;
00206 STR_APPEND(h,event_hdr);
00207
00208 STR_APPEND(h,max_fwds_hdr);
00209
00210 STR_APPEND(h,expires_s);
00211 sprintf(h.s+h.len,"%d",expires);
00212 h.len += strlen(h.s+h.len);
00213 STR_APPEND(h,expires_e);
00214
00215 STR_APPEND(h,contact_s);
00216 STR_APPEND(h,isc_my_uri_sip);
00217 STR_APPEND(h,contact_e);
00218
00219 if (r->pvni.len) {
00220 STR_APPEND(h,p_visited_network_id_s);
00221 STR_APPEND(h,r->pvni);
00222 STR_APPEND(h,p_visited_network_id_e);
00223 }
00224
00225 if (r->pani.len) {
00226 STR_APPEND(h,p_access_network_info_s);
00227 STR_APPEND(h,r->pani);
00228 STR_APPEND(h,p_access_network_info_e);
00229 }
00230
00231 if (r->cv.len) {
00232 STR_APPEND(h,p_charging_vector_s);
00233 STR_APPEND(h,r->cv);
00234 STR_APPEND(h,p_charging_vector_e);
00235 }
00236 LOG(L_CRIT,"SRV INFO:<%.*s>\n",r->service_info.len, r->service_info.s);
00237 if (r->service_info.len){
00238 b.len = body_s.len+r->service_info.len+body_e.len;
00239 b.s = pkg_malloc(b.len);
00240 if (!b.s){
00241 LOG(L_ERR,"ERR:"M_NAME":r_send_third_party_reg: Error allocating %d bytes\n",b.len);
00242 b.len = 0;
00243 return 0;
00244 }
00245
00246 b.len = 0;
00247 STR_APPEND(b,body_s);
00248 STR_APPEND(b,r->service_info);
00249 STR_APPEND(b,body_e);
00250 }
00251
00252
00253 if (isc_tmb.t_request(&method, &(r->req_uri), &(r->to), &(r->from), &h, &b, 0,
00254 r_third_party_reg_response, &(r->req_uri))<0)
00255 {
00256 LOG(L_ERR,"ERR:"M_NAME":r_send_third_party_reg: Error sending in transaction\n");
00257 goto error;
00258 }
00259 #ifdef WITH_IMS_PM
00260 IMS_PM_LOG(UR_Att3rdPartyReg);
00261 #endif
00262 if (h.s) pkg_free(h.s);
00263 return 1;
00264
00265 error:
00266 if (h.s) pkg_free(h.s);
00267 return 0;
00268 }
00269
00270
00275 void r_third_party_reg_response(struct cell *t,int type,struct tmcb_params *ps)
00276 {
00277 str req_uri;
00278 int expires;
00279 LOG(L_DBG,"DBG:"M_NAME":r_third_party_reg_response: code %d\n",ps->code);
00280 if (!ps->rpl) {
00281 LOG(L_ERR,"INF:"M_NAME":r_third_party_reg_response: No reply\n");
00282 return;
00283 }
00284
00285 #ifdef WITH_IMS_PM
00286 if (ps->code>=200 && ps->code<300)
00287 IMS_PM_LOG01(UR_Succ3rdPartyReg,ps->code);
00288 else if (ps->code>=300) IMS_PM_LOG01(UR_Fail3rdPartyReg,ps->code);
00289 #endif
00290
00291 if (ps->code>=200 && ps->code<300){
00292 if (ps->rpl)
00293 expires = cscf_get_expires_hdr(ps->rpl);
00294 else
00295 return;
00296 req_uri = *((str*) *(ps->param));
00297 }else
00298 if (ps->code==404){
00299 }else{
00300 LOG(L_INFO,"INF:"M_NAME":r_third_party_reg_response: code %d\n",ps->code);
00301 }
00302 }
00303