⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 register.c

📁 siproxd is a proxy/masquerading for the SIP protocal.
💻 C
📖 第 1 页 / 共 2 页
字号:
   for (i=0; i<URLMAP_SIZE; i++) {      if (urlmap[i].active == 0) {	 if (j < 0) j=i; /* remember first hole */         continue;      }      url2_to=urlmap[i].reg_url;      url2_contact=urlmap[i].true_url;      if ( (compare_url(url1_to, url2_to)==STS_SUCCESS) &&           (compare_url(url1_contact, url2_contact)==STS_SUCCESS) ) {         DEBUGC(DBCLASS_REG, "found entry for %s@%s <-> %s@%s at "                "slot=%i, exp=%li",	        (url1_contact->username) ? url1_contact->username : "*NULL*",                (url1_contact->host) ? url1_contact->host : "*NULL*",	        (url2_to->username) ? url2_to->username : "*NULL*",                (url2_to->host) ? url2_to->host : "*NULL*",		i, urlmap[i].expires-time_now);         break;      }   }   if ( (j < 0) && (i >= URLMAP_SIZE) ) {      /* oops, no free entries left... */      ERROR("URLMAP is full - registration failed");      return STS_FAILURE;   }   if (i >= URLMAP_SIZE) {      /* entry not existing, create new one */      i=j;      /* write entry */      urlmap[i].active=1;      /* Contact: field */      osip_uri_clone( ((osip_contact_t*)(my_msg->contacts->node->element))->url,         	 &urlmap[i].true_url);      /* To: field */      osip_uri_clone( my_msg->to->url,         	 &urlmap[i].reg_url);      DEBUGC(DBCLASS_REG,"create new entry for %s@%s <-> %s@%s at slot=%i",             (url1_contact->username) ? url1_contact->username : "*NULL*",             (url1_contact->host) ? url1_contact->host : "*NULL*",	     (urlmap[i].reg_url->username) ? urlmap[i].reg_url->username : "*NULL*",             (urlmap[i].reg_url->host) ? urlmap[i].reg_url->host : "*NULL*",             i);      /*       * try to figure out if we ought to do some masquerading       */      osip_uri_clone( my_msg->to->url,         	      &urlmap[i].masq_url);      n=configuration.mask_host.used;      if (n != configuration.masked_host.used) {         ERROR("# of mask_host is not equal to # of masked_host in config!");         n=0;      }      DEBUG("%i entries in MASK config table", n);      for (j=0; j<n; j++) {         DEBUG("compare [%s] <-> [%s]",configuration.mask_host.string[j],               my_msg->to->url->host);         if (strcmp(configuration.mask_host.string[j],             my_msg->to->url->host)==0)            break;      }      if (j<n) {          /* we are masquerading this UA, replace the host part of the url */         DEBUGC(DBCLASS_REG,"masquerading UA %s@%s as %s@%s",                (url1_contact->username) ? url1_contact->username : "*NULL*",                (url1_contact->host) ? url1_contact->host : "*NULL*",                (url1_contact->username) ? url1_contact->username : "*NULL*",                configuration.masked_host.string[j]);         urlmap[i].masq_url->host=realloc(urlmap[i].masq_url->host,                                 strlen(configuration.masked_host.string[j])+1);         strcpy(urlmap[i].masq_url->host, configuration.masked_host.string[j]);      }      /*       * for transparent proxying: force device to be masqueraded       * as with the outbound IP       */      if (force_lcl_masq) {         struct in_addr addr;         char *addrstr;         sts = get_ip_by_ifname(configuration.outbound_if,&addr);         addrstr = utils_inet_ntoa(addr);         DEBUGC(DBCLASS_REG,"masquerading UA %s@%s local %s@%s",                (url1_contact->username) ? url1_contact->username : "*NULL*",                (url1_contact->host) ? url1_contact->host : "*NULL*",                (url1_contact->username) ? url1_contact->username : "*NULL*",                addrstr);         urlmap[i].masq_url->host=realloc(urlmap[i].masq_url->host,                                 strlen(addrstr)+1);         strcpy(urlmap[i].masq_url->host, addrstr);      }      /* remember the VIA for later use *///      osip_via_clone( ((osip_via_t*)(my_msg->vias->node->element)),//                      &urlmap[i].via);   } else { /* if new entry */   /*    * Some phones (like BudgeTones *may* dynamically grab a SIP port    * so we might want to update the true_url and reg_url each time    * we get an REGISTER    */      /* Contact: field */      osip_uri_free(urlmap[i].true_url);      osip_uri_clone( ((osip_contact_t*)(my_msg->contacts->node->element))->url,         	 &urlmap[i].true_url);      /* To: field */      osip_uri_free(urlmap[i].reg_url);      osip_uri_clone( my_msg->to->url,         	 &urlmap[i].reg_url);   }   /* give some safety margin for the next update */   if (expires > 0) expires+=30;   /* update registration timeout */   urlmap[i].expires=time_now+expires;   return STS_SUCCESS;}/* * cyclically called to do the aging of the URL mapping table entries * and throw out expired entries. */void register_agemap(void) {   int i;   time_t t;      time(&t);   DEBUGC(DBCLASS_BABBLE,"sip_agemap, t=%i",(int)t);   for (i=0; i<URLMAP_SIZE; i++) {      if ((urlmap[i].active == 1) && (urlmap[i].expires < t)) {	 DEBUGC(DBCLASS_REG,"cleaned entry:%i %s@%s", i,	        urlmap[i].masq_url->username,  urlmap[i].masq_url->host);         urlmap[i].active=0;         osip_uri_free(urlmap[i].true_url);         osip_uri_free(urlmap[i].masq_url);         osip_uri_free(urlmap[i].reg_url);//	 osip_via_free(urlmap[i].via);      }   }   return;}/* * send answer to a registration request. *  flag = STS_SUCCESS    -> positive answer (200) *  flag = STS_FAILURE    -> negative answer (503) *  flag = STS_NEED_AUTH  -> proxy authentication needed (407) * * RETURNS *	STS_SUCCESS on success *	STS_FAILURE on error */int register_response(osip_message_t *request, int flag) {   osip_message_t *response;   int code;   int sts;   osip_via_t *via;   int port;   char *buffer;   struct in_addr addr;   osip_header_t *expires_hdr;   /* ok -> 200, fail -> 503 */   switch (flag) {   case STS_SUCCESS:      code = 200;	/* OK */      break;   case STS_FAILURE:      code = 503;	/* failed */      break;   case STS_NEED_AUTH:      code = 407;	/* proxy authentication needed */      break;   default:      code = 503;	/* failed */      break;   }   /* create the response template */   if ((response=msg_make_template_reply(request, code))==NULL) {      ERROR("register_response: error in msg_make_template_reply");      return STS_FAILURE;   }   /* insert the expiration header */   osip_message_get_expires(request, 0, &expires_hdr);   if (expires_hdr) {      osip_message_set_expires(response, expires_hdr->hvalue);   }   /* if we send back an proxy authentication needed,       include the Proxy-Authenticate field */   if (code == 407) {      auth_include_authrq(response);   }   /* get the IP address from existing VIA header */   osip_message_get_via (response, 0, &via);   if (via == NULL) {      ERROR("register_response: Cannot send response - no via field");      return STS_FAILURE;   }   /* name resolution needed? */   if (utils_inet_aton(via->host,&addr) == 0) {      /* yes, get IP address */      sts = get_ip_by_host(via->host, &addr);      if (sts == STS_FAILURE) {         DEBUGC(DBCLASS_REG, "register_response: cannot resolve VIA [%s]",                via->host);         return STS_FAILURE;      }   }      sts = osip_message_to_str(response, &buffer);   if (sts != 0) {      ERROR("register_response: msg_2char failed");      return STS_FAILURE;   }   /* send answer back */   if (via->port) {      port=atoi(via->port);   } else {      port=configuration.sip_listen_port;   }   sipsock_send_udp(&sip_socket, addr, port, buffer, strlen(buffer), 1);   /* free the resources */   osip_message_free(response);   free(buffer);   return STS_SUCCESS;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -