Пример #1
0
//---------------------------------------------------------------------
void
Node::TransferUserInfoToPred(ChordId node)
{
	uinfo_t *red_cur=red_user_info_list;
	uinfo_t *cur=user_info_list;
	while(red_cur != NULL)
	{
		char *red_aor;
		uinfo_t *red_tmp=red_cur;
		red_cur=red_cur->next;
		osip_uri_to_str(red_tmp->aor->uri,&red_aor);
		if(red_aor)	osip_free(red_aor) ;
			
		char * red_registrar= (char *)osip_malloc(4 + strlen(node.GetAddress()) +1) ;
		sprintf (red_registrar, "sip:%s", node.GetAddress());
		SndUserRegisterRequest(RED_REGISTER,red_tmp,red_registrar ,3600);
		if(red_registrar)	osip_free(red_registrar) ;
		
		REMOVE_ELEMENT(red_user_info_list,red_tmp);
		delete red_tmp;
		

	}
	
	ChordId localnode=getChordId();
	unsigned int uid=0;
	while(cur != NULL)
	{
		
		char *aor;
		uinfo_t *tmp=cur;
		cur=cur->next;
		osip_uri_to_str(tmp->aor->uri,&aor);
		uid=uhash(aor);
		if(aor)	osip_free(aor) ;

		Constants constants(NULL);
		ChordId UserID(uid,&constants);
		if(!UserID.BelongsRightInclusive(node,localnode))
		{
			char * registrar= (char *)osip_malloc(4 + strlen(node.GetAddress()) +1) ;
			sprintf (registrar, "sip:%s", node.GetAddress());
			SndUserRegisterRequest(USER_REGISTRATION,tmp,registrar,3600);
			if(registrar)	osip_free(registrar) ;
		
			REMOVE_ELEMENT(user_info_list,tmp);
			//ADD_ELEMENT(red_user_info_list,tmp);//move this user info to redundant user info list
			delete tmp;
		}
	}

}
Пример #2
0
int
eXosip_call_get_referto (int did, char *refer_to, size_t refer_to_len)
{
  eXosip_dialog_t *jd = NULL;
  eXosip_call_t *jc = NULL;
  osip_transaction_t *tr = NULL;
  osip_uri_t *referto_uri;
  char atmp[256];
  char *referto_tmp = NULL;
  int i;

  if (did <= 0)
    return OSIP_BADPARAMETER;

  eXosip_call_dialog_find (did, &jc, &jd);
  if (jc == NULL || jd == NULL || jd->d_dialog == NULL)
    {
      OSIP_TRACE (osip_trace
                  (__FILE__, __LINE__, OSIP_ERROR, NULL,
                   "eXosip: No call here?\n"));
      return OSIP_NOTFOUND;
    }

  tr = eXosip_find_last_invite (jc, jd);

  if (tr == NULL || tr->orig_request == NULL)
    {
      OSIP_TRACE (osip_trace
                  (__FILE__, __LINE__, OSIP_ERROR, NULL,
                   "eXosip: No transaction for call?\n"));
      return OSIP_NOTFOUND;
    }

  i = osip_uri_clone (jd->d_dialog->remote_uri->url, &referto_uri);
  if (i != 0)
    return i;

  snprintf (atmp, sizeof (atmp), "%s;to-tag=%s;from-tag=%s",
            jd->d_dialog->call_id,
            jd->d_dialog->remote_tag, jd->d_dialog->local_tag);

  osip_uri_uheader_add (referto_uri, osip_strdup ("Replaces"), osip_strdup (atmp));
  i = osip_uri_to_str (referto_uri, &referto_tmp);
  if (i != 0)
    {
      osip_uri_free (referto_uri);
      return i;
    }

  snprintf (refer_to, refer_to_len, "%s", referto_tmp);
  osip_uri_free (referto_uri);

  return OSIP_SUCCESS;
}
Пример #3
0
//---------------------------------------------------------------------
void Node::QueryUser()
{
	/*
	REGISTER sip:[email protected]
	To: <sip:[email protected]>
	From: <sip:[email protected]>

*/
	//char *aor="sip:[email protected]";

	char buf[50];
	printf("input the user aor you want to call\n");
	gets(buf);
	char *aor=buf;
	
	unsigned int uid=uhash(aor);
	Constants constants(NULL);
	ChordId UserID(uid,&constants);
	ChordId pred=mynode->getFingerTable()->getPredecessor();
	ChordId localnode=getChordId();
	
	//for test
	if(UserID.BelongsRightInclusive(pred,localnode))
	{
		printf("\nThe user infomation is on this node\n");
		uinfo_t *user_info=uinfo_t::find_user_info_by_aor(aor,user_info_list);
		char *dest;
		osip_uri_to_str(user_info->bindings->contact->url,&dest);
		printf("user contact is %s\n",dest);
		osip_free(dest);
		return;

	}
	else
	{
		ChordId next_hop=closestPrecedingFinger(UserID);
		//ChordId next_hop=getChordId();
		ChordId empty(-1,&constants);
		if(!next_hop.equals(empty))
		{
			char *tmp=next_hop.GetAddress();
			char *requri = (char *)osip_malloc (4 + strlen(tmp) + 1) ;
			sprintf (requri, "sip:%s", tmp);
			SndUserRegisterRequest(aor,requri);
			if(requri)	osip_free(requri) ;
		}
		else  //do not know where to send
		{
			return ;
		}
		
	}

}
Пример #4
0
int
main (int argc, char **argv)
{
  FILE *urls_file;


  osip_uri_t *url;
  char *a_url;
  char *dest;
  char *res;

  urls_file = fopen (argv[1], "r");
  if (urls_file == NULL)
    {
      fprintf (stdout, "Failed to open %s file.\nUsage: turls urls.txt\n",
               argv[1]);
      exit (0);
    }

  a_url = (char *) osip_malloc (200);
  res = fgets (a_url, 200, urls_file);  /* lines are under 200 */
  while (res != NULL)
    {
      int errcode;

      /* remove the last '\n' before parsing */
      osip_strncpy (a_url + strlen (a_url) - 1, "\0", 1);

      if (0 != strncmp (a_url, "#", 1))
        {
          /* allocate & init url */
          osip_uri_init (&url);
          printf ("=================================================\n");
          printf ("URL TO PARSE: |%s|\n", a_url);
          errcode = osip_uri_parse (url, a_url);
          if (errcode != -1)
            {
              if (osip_uri_to_str (url, &dest) != -1)
                {
                  printf ("result:       |%s|\n", dest);
                  osip_uri_test_accessor_api (url);
                  osip_free (dest);
                }
          } else
            printf ("Bad url format: %s\n", a_url);
          osip_uri_free (url);
          printf ("=================================================\n");
        }
      res = fgets (a_url, 200, urls_file);      /* lines are under 200 */
    }
  osip_free (a_url);
  return 0;
}
Пример #5
0
void 
Node::PrintAllUser()
{
	uinfo_t *cur=user_info_list;
	printf("Registered user:\n");
	while(cur != NULL)
	{
		char *aor;
		int id=0;
		osip_uri_to_str(cur->aor->uri,&aor);
		id=uhash(aor);
		printf("UserId=%d, AOR= %s\n",id,aor);
		if(aor)	osip_free(aor) ;
		cur=cur->next;
	}
	cur = local_user_info_list;
	printf("local user:\n");
	while(cur != NULL)
	{
		char *aor;
		int id=0;
		osip_uri_to_str(cur->aor->uri,&aor);
		id=uhash(aor);
		printf("UserId=%d, AOR= %s\n",id,aor);
		if(aor)		osip_free(aor) ;
		cur=cur->next;
	}
	cur = red_user_info_list;
	printf("Redundancy registered user:\n");
	while(cur != NULL)
	{
		char *aor;
		int id=0;
		osip_uri_to_str(cur->aor->uri,&aor);
		id=uhash(aor);
		printf("UserId=%d, AOR= %s\n",id,aor);
		if(aor)	osip_free(aor) ;
		cur=cur->next;
	}
}
Пример #6
0
int
eXosip_notify_init (eXosip_notify_t ** jn, osip_message_t * inc_subscribe)
{
  osip_contact_t *co;
  char *uri;
  int i;
  char locip[50];

#ifdef SM
  eXosip_get_localip_from_via (inc_subscribe, locip, 49);
#else
  i = _eXosip_find_protocol (inc_subscribe);
  if (i == IPPROTO_UDP)
    {
      eXosip_guess_ip_for_via (eXosip.net_interfaces[0].net_ip_family, locip, 49);
  } else if (i == IPPROTO_TCP)
    {
      eXosip_guess_ip_for_via (eXosip.net_interfaces[1].net_ip_family, locip, 49);
  } else
    {
      OSIP_TRACE (osip_trace
                  (__FILE__, __LINE__, OSIP_ERROR, NULL,
                   "eXosip: unsupported protocol (default to UDP)\n"));
      eXosip_guess_ip_for_via (eXosip.net_interfaces[0].net_ip_family, locip, 49);
      return -1;
    }

#endif
  if (inc_subscribe == NULL
      || inc_subscribe->to == NULL || inc_subscribe->to->url == NULL)
    return -1;
  co = (osip_contact_t *) osip_list_get (inc_subscribe->contacts, 0);
  if (co == NULL || co->url == NULL)
    return -1;

  *jn = (eXosip_notify_t *) osip_malloc (sizeof (eXosip_notify_t));
  if (*jn == NULL)
    return -1;
  memset (*jn, 0, sizeof (eXosip_notify_t));

  i = osip_uri_to_str (co->url, &uri);
  if (i != 0)
    {
      osip_free (*jn);
      *jn = NULL;
      return -1;
    }
  osip_strncpy ((*jn)->n_uri, uri, 254);
  osip_free (uri);

  return 0;
}
static void add_presence_body(osip_message_t *notify, SalPresenceStatus online_status)
{
	char buf[1000];
	char *contact_info;

	osip_from_t *from=NULL;
	from=osip_message_get_from(notify);
	osip_uri_to_str(from->url,&contact_info);

	mk_presence_body (online_status, contact_info, buf, sizeof (buf), presence_style);

	osip_message_set_body(notify, buf, strlen(buf));
	osip_message_set_content_type(notify,
		presence_style ? "application/xpidf+xml" : "application/pidf+xml");

	osip_free(contact_info);
}
Пример #8
0
/* RFC3261 16.5 
 */
int
osip_uri_to_str_canonical (const osip_uri_t * url, char **dest)
{
  int result;

  *dest = NULL;
  result = osip_uri_to_str (url, dest);
  if (result == 0)
    {
      /*
         tmp = strchr(*dest, ";");
         if (tmp !=NULL) {
         buf=strndup(*dest, tmp-(*dest));
         osip_free(*dest);
         *dest=buf;
         }
       */
      __osip_uri_unescape (*dest);
    }
  return result;
}
static int
__osip_message_startline_to_strreq (osip_message_t * sip, char **dest)
{
  const char *sip_version;
  char *tmp;
  char *rquri;
  int i;

  *dest = NULL;
  if ((sip == NULL) || (sip->req_uri == NULL) || (sip->sip_method == NULL))
    return OSIP_BADPARAMETER;

  i = osip_uri_to_str (sip->req_uri, &rquri);
  if (i != 0)
    return i;

  if (sip->sip_version == NULL)
    sip_version = osip_protocol_version;
  else
    sip_version = sip->sip_version;

  *dest = (char *) osip_malloc (strlen (sip->sip_method)
                                + strlen (rquri) + strlen (sip_version) + 3);
  if (*dest == NULL) {
    osip_free (rquri);
    return OSIP_NOMEM;
  }
  tmp = *dest;

  tmp = osip_str_append (tmp, sip->sip_method);
  *tmp = ' ';
  tmp++;
  tmp = osip_str_append (tmp, rquri);
  *tmp = ' ';
  tmp++;
  strcpy (tmp, sip_version);

  osip_free (rquri);
  return OSIP_SUCCESS;
}
int
_eXosip_insubscription_auto_send_notify (int did,
                                         int subscription_status,
                                         int subscription_reason)
{
  osip_message_t *notify;
  int i;
  char xml[4096];
  char *entity;
  eXosip_call_t *jc;
  eXosip_dialog_t *jd;

  if (did <= 0)
    return OSIP_BADPARAMETER;

  i = eXosip_insubscription_build_notify (did, subscription_status,
                                          subscription_reason, &notify);
  if (i != 0)
    {
      return i;
    }

  /* build dialog xml state */
  memset (xml, 0, sizeof (xml));

  i = osip_uri_to_str (notify->from->url, &entity);
  if (i != 0 || entity == NULL)
    {
      osip_message_free (notify);
      return i;
    }
  snprintf (xml, sizeof (xml),
            "<?xml version=\"1.0\"?>" "\r\n"
            "<dialog-info xmlns=\"urn:ietf:params:xml:ns:dialog-info\"" "\r\n"
            "	version=\"2\" state=\"full\"" "\r\n"
            "	entity=\"%s\">" "\r\n", entity);
  osip_free (entity);

  /* loop over all jc/jd */
  for (jc = eXosip.j_calls; jc != NULL; jc = jc->next)
    {
      for (jd = jc->c_dialogs; jd != NULL; jd = jd->next)
        {
          if (jd->d_dialog == NULL)     /* finished call */
            {
          } else
            {
              char tmp_dialog[2048];
              char direction[20];
              char dlg_state[20];
              char *remote_uri = NULL;

              if (jd->d_dialog->type == CALLER)
                strcpy (direction, "initiator");
              else
                strcpy (direction, "recipient");
              if (jd->d_dialog->state == DIALOG_CONFIRMED)
                strcpy (dlg_state, "confirmed");
              else
                strcpy (dlg_state, "early");

              if (jd->d_dialog->remote_uri != NULL
                  && jd->d_dialog->remote_uri->url != NULL)
                {
                  osip_uri_to_str (jd->d_dialog->remote_uri->url, &remote_uri);
                }
              if (remote_uri != NULL)
                {
                  /* add dialog info */
                  snprintf (tmp_dialog, sizeof (tmp_dialog),
                            "	<dialog id=\"%s\" call-id=\"%s\"" "\r\n"
                            "		local-tag=\"%s\" remote-tag=\"%s\""
                            "\r\n" "		direction=\"%s\">"
                            "\r\n"
                            "		<state>%s</state>"
                            "\r\n"
                            "		<remote>"
                            "\r\n"
                            "			<identity>%s</identity>"
                            "\r\n"
                            "		</remote>"
                            "\r\n"
                            "	</dialog>"
                            "\r\n",
                            jd->
                            d_dialog->
                            call_id,
                            jd->
                            d_dialog->
                            call_id,
                            jd->
                            d_dialog->
                            local_tag,
                            jd->
                            d_dialog->
                            remote_tag, direction, dlg_state, remote_uri);
                  strcat (xml, tmp_dialog);
                }
            }
        }
    }
  strcat (xml, "</dialog-info>" "\r\n");
  osip_message_set_content_type (notify, "application/dialog-info+xml");
  osip_message_set_body (notify, xml, strlen (xml));

  return eXosip_insubscription_send_request (did, notify);
}
Пример #11
0
/* private plugin code */
static int plugin_regex_redirect(sip_ticket_t *ticket) {
   osip_uri_t *to_url=ticket->sipmsg->to->url;
   char *url_string=NULL;
   osip_uri_t *new_to_url;
   int  i, sts;
   osip_contact_t *contact = NULL;
   /* character workspaces for regex */
   #define WORKSPACE_SIZE 128
   static char in[WORKSPACE_SIZE+1], rp[WORKSPACE_SIZE+1];

   /* do apply to full To URI... */
   sts = osip_uri_to_str(to_url, &url_string);
   if (sts != 0) {
      ERROR("osip_uri_to_str() failed");
      return STS_FAILURE;
   }
   DEBUGC(DBCLASS_BABBLE, "To URI string: [%s]", url_string);

   /* perform search and replace of the regexes, first match hits */
   for (i = 0; i < plugin_cfg.regex_pattern.used; i++) {
      regmatch_t *pmatch = NULL;
      pmatch = rmatch(url_string, WORKSPACE_SIZE, &re[i]);
      if (pmatch == NULL) continue; /* no match, next */

      /* have a match, do the replacement */
      INFO("Matched rexec rule: %s",plugin_cfg.regex_desc.string[i] );
      strncpy (in, url_string, WORKSPACE_SIZE);
      in[WORKSPACE_SIZE]='\0';
      strncpy (rp, plugin_cfg.regex_replace.string[i], WORKSPACE_SIZE);
      rp[WORKSPACE_SIZE]='\0';

      sts = rreplace(in, WORKSPACE_SIZE, &re[i], pmatch, rp);
      if (sts != STS_SUCCESS) {
         ERROR("regex replace failed: pattern:[%s] replace:[%s]",
               plugin_cfg.regex_pattern.string[i],
               plugin_cfg.regex_replace.string[i]);
         osip_free(url_string);
         return STS_FAILURE;
      }
      /* only do first match */
      break;
   }
   if (i >= plugin_cfg.regex_pattern.used) {
      /* no match */
      osip_free(url_string);
      return STS_SUCCESS;
   }
   /* in: contains the new string */

   sts = osip_uri_init(&new_to_url);
   if (sts != 0) {
      ERROR("Unable to initialize URI");
      osip_free(url_string);
      return STS_FAILURE;
   }

   sts = osip_uri_parse(new_to_url, in);
   if (sts != 0) {
      ERROR("Unable to parse To URI: %s", in);
      osip_uri_free(new_to_url);
      osip_free(url_string);
      return STS_FAILURE;
   }

   /* use a "302 Moved temporarily" response back to the client */
   /* new target is within the Contact Header */

   /* remove all Contact headers in message */
   for (i=0; (contact != NULL) || (i == 0); i++) {
      osip_message_get_contact(ticket->sipmsg, 0, &contact);
      if (contact) {
         osip_list_remove(&(ticket->sipmsg->contacts),0);
         osip_contact_free(contact);
      }
   } /* for i */

   /* insert one new Contact header containing the new target address */
   osip_contact_init(&contact);
   osip_list_add(&(ticket->sipmsg->contacts),contact,0);
   
   /* link the new_to_url into the Contact list */
   contact->url = new_to_url;
   new_to_url = NULL;

   /*
    * Add the 'REDIRECTED_TAG=REDIRECTED_VAL' parameter to URI. Required to figure out
    * if this INVITE has already been processed (redirected) and
    * does not need further attention by this plugin.
    * THIS IS REQUIRED TO AVOID A LOOP
    */
   osip_uri_param_add(&(contact->url->url_params), osip_strdup(REDIRECTED_TAG), 
                      osip_strdup(REDIRECTED_VAL));

   INFO("redirecting %s -> %s", url_string, in);

   /* sent redirect message back to local client */
   add_to_redirected_cache(&redirected_cache, ticket);
   sip_gen_response(ticket, 302 /*Moved temporarily*/);

   /* release resources and return */
   osip_free(url_string);
   return STS_SIP_SENT;
}
Пример #12
0
int
eXosip_add_authentication_information (osip_message_t * req,
                                       osip_message_t * last_response)
{
  osip_authorization_t *aut = NULL;
  osip_www_authenticate_t *wwwauth = NULL;
  osip_proxy_authorization_t *proxy_aut = NULL;
  osip_proxy_authenticate_t *proxyauth = NULL;
  jauthinfo_t *authinfo = NULL;
  int pos;
  int i;

  if (req == NULL
      || req->from == NULL
      || req->from->url == NULL || req->from->url->username == NULL)
    {
      OSIP_TRACE (osip_trace
                  (__FILE__, __LINE__, OSIP_INFO2, NULL,
                   "authinfo: Invalid message\n"));
      return -1;
   }

  if (last_response==NULL)
  {
	  /* we can add all credential that belongs to the same call-id */
	struct eXosip_http_auth *http_auth;
	int pos;

	/* update entries with same call_id */
	for (pos=0;pos<MAX_EXOSIP_HTTP_AUTH;pos++)
	{
		http_auth = &eXosip.http_auths[pos];
		if (http_auth->pszCallId[0]=='\0')
			continue;
		if (osip_strcasecmp(http_auth->pszCallId, req->call_id->number)==0)
		{
			char *uri;

			authinfo = eXosip_find_authentication_info (req->from->url->username,
												  http_auth->wa->realm);
			if (authinfo == NULL)
			{
				OSIP_TRACE (osip_trace
						  (__FILE__, __LINE__, OSIP_INFO2, NULL,
						   "authinfo: No authentication found for %s %s\n",
						   req->from->url->username, http_auth->wa->realm));
				return -1;
			}

			i = osip_uri_to_str (req->req_uri, &uri);
			if (i != 0)
				return -1;

			http_auth->iNonceCount++;
			if (osip_strcasecmp(req->sip_method, "REGISTER")==0)
				i = __eXosip_create_authorization_header (http_auth->wa, uri,
													authinfo->userid,
													authinfo->passwd,
													authinfo->ha1, &aut,
													req->sip_method,
													http_auth->pszCNonce,
													http_auth->iNonceCount);
			else
				i = __eXosip_create_proxy_authorization_header (http_auth->wa, uri,
													authinfo->userid,
													authinfo->passwd,
													authinfo->ha1, &aut,
													req->sip_method,
													http_auth->pszCNonce,
													http_auth->iNonceCount);

			osip_free (uri);
			if (i != 0)
				return -1;

			if (aut != NULL)
			{
				if (osip_strcasecmp(req->sip_method, "REGISTER")==0)
					osip_list_add (&req->authorizations, aut, -1);
				else
					osip_list_add (&req->proxy_authorizations, aut, -1);
				osip_message_force_update (req);
			}
		}
	}
	return 0;
  }

  pos = 0;
  osip_message_get_www_authenticate (last_response, pos, &wwwauth);
  osip_message_get_proxy_authenticate (last_response, pos, &proxyauth);
  if (wwwauth == NULL && proxyauth == NULL)
    {
      OSIP_TRACE (osip_trace
                  (__FILE__, __LINE__, OSIP_INFO2, NULL,
                   "authinfo: No WWW-Authenticate or Proxy-Authenticate\n"));
      return -1;
    }

  while (wwwauth != NULL)
    {
      char *uri;

      authinfo = eXosip_find_authentication_info (req->from->url->username,
                                                  wwwauth->realm);
      if (authinfo == NULL)
        {
          OSIP_TRACE (osip_trace
                      (__FILE__, __LINE__, OSIP_INFO2, NULL,
                       "authinfo: No authentication found for %s %s\n",
                       req->from->url->username, wwwauth->realm));
          return -1;
        }

      i = osip_uri_to_str (req->req_uri, &uri);
      if (i != 0)
        return -1;

      i = __eXosip_create_authorization_header (wwwauth, uri,
                                                authinfo->userid,
                                                authinfo->passwd,
                                                authinfo->ha1, &aut,
                                                req->sip_method,
												"0a4f113b",
												1);
      osip_free (uri);
      if (i != 0)
        return -1;

      if (aut != NULL)
        {
          osip_list_add (&req->authorizations, aut, -1);
          osip_message_force_update (req);
        }

	  if (wwwauth->qop_options!=NULL)
	  {
		  if (osip_strcasecmp(req->sip_method, "REGISTER")==0
			  || osip_strcasecmp(req->sip_method, "INVITE")==0
  			  || osip_strcasecmp(req->sip_method, "SUBSCRIBE")==0)
		  	  _eXosip_store_nonce(req->call_id->number, wwwauth);
		  else
		  {
			  osip_generic_param_t *to_tag=NULL;
			  osip_from_param_get_byname (req->to, "tag", &to_tag);
			  if (to_tag!=NULL)
			  {
				  /* if message is part of a dialog */
			  	  _eXosip_store_nonce(req->call_id->number, wwwauth);
			  }
		  }
	  }

      pos++;
      osip_message_get_www_authenticate (last_response, pos, &wwwauth);
    }

  pos = 0;
  while (proxyauth != NULL)
    {
      char *uri;

      authinfo = eXosip_find_authentication_info (req->from->url->username,
                                                  proxyauth->realm);
      if (authinfo == NULL)
        {
          OSIP_TRACE (osip_trace
                      (__FILE__, __LINE__, OSIP_INFO2, NULL,
                       "authinfo: No authentication found for %s %s\n",
                       req->from->url->username, proxyauth->realm));
          return -1;
        }
      OSIP_TRACE (osip_trace
                  (__FILE__, __LINE__, OSIP_INFO1, NULL,
                   "authinfo: %s\n", authinfo->username));
      i = osip_uri_to_str (req->req_uri, &uri);
      if (i != 0)
        return -1;

      i = __eXosip_create_proxy_authorization_header (proxyauth, uri,
                                                      authinfo->userid,
                                                      authinfo->passwd,
                                                      authinfo->ha1,
                                                      &proxy_aut, req->sip_method,
													  "0a4f113b",
													  1);
      osip_free (uri);
      if (i != 0)
        return -1;

      if (proxy_aut != NULL)
        {
          osip_list_add (&req->proxy_authorizations, proxy_aut, -1);
          osip_message_force_update (req);
        }

	  if (proxyauth->qop_options!=NULL)
	  {
		  if (osip_strcasecmp(req->sip_method, "REGISTER")==0
			  || osip_strcasecmp(req->sip_method, "INVITE")==0
  			  || osip_strcasecmp(req->sip_method, "SUBSCRIBE")==0)
		  	  _eXosip_store_nonce(req->call_id->number, proxyauth);
		  else
		  {
			  osip_generic_param_t *to_tag=NULL;
			  osip_from_param_get_byname (req->to, "tag", &to_tag);
			  if (to_tag!=NULL)
			  {
				  /* if message is part of a dialog */
			  	  _eXosip_store_nonce(req->call_id->number, proxyauth);
			  }
		  }
	  }

      pos++;
      osip_message_get_proxy_authenticate (last_response, pos, &proxyauth);
    }

  return 0;
}
Пример #13
0
/* returns -1 on error. */
int
osip_from_to_str (const osip_from_t * from, char **dest)
{
  char *url;
  char *buf;
  int i;
  size_t len;

  *dest = NULL;
  if ((from == NULL) || (from->url == NULL))
    return -1;

  i = osip_uri_to_str (from->url, &url);
  if (i != 0)
    return -1;

  if (from->displayname == NULL)
    len = strlen (url) + 5;
  else
    len = strlen (url) + strlen (from->displayname) + 5;

  buf = (char *) osip_malloc (len);
  if (buf == NULL)
    {
      osip_free (url);
      return -1;
    }

  if (from->displayname != NULL)
    sprintf (buf, "%s <%s>", from->displayname, url);
  else
    /* from rfc2543bis-04: for authentication related issue!
       "The To and From header fields always include the < and >
       delimiters even if the display-name is empty." */
    sprintf (buf, "<%s>", url);
  osip_free (url);

  {
    int pos = 0;
    osip_generic_param_t *u_param;
    size_t plen;
    char *tmp;

    while (!osip_list_eol (&from->gen_params, pos))
      {
        u_param = (osip_generic_param_t *) osip_list_get (&from->gen_params, pos);

        if (u_param->gvalue == NULL)
          plen = strlen (u_param->gname) + 2;
        else
          plen = strlen (u_param->gname) + strlen (u_param->gvalue) + 3;
        len = len + plen;
        buf = (char *) osip_realloc (buf, len);
        tmp = buf;
        tmp = tmp + strlen (tmp);
        if (u_param->gvalue == NULL)
          sprintf (tmp, ";%s", u_param->gname);
        else
          sprintf (tmp, ";%s=%s", u_param->gname, u_param->gvalue);
        pos++;
      }
  }
  *dest = buf;
  return 0;
}
Пример #14
0
/*
 * SIP_CALCULATE_BRANCH
 *
 * Calculates a branch parameter according to RFC3261 section 16.11
 *
 * The returned 'id' will be HASHHEXLEN + strlen(magic_cookie)
 * characters (32 + 7) long. The caller must supply at least this
 * amount of space in 'id'.
 *
 * RETURNS
 *	STS_SUCCESS on success
 *	STS_FAILURE on error
 */
int  sip_calculate_branch_id (sip_ticket_t *ticket, char *id) {
/* RFC3261 section 16.11 recommends the following procedure:
 *   The stateless proxy MAY use any technique it likes to guarantee
 *   uniqueness of its branch IDs across transactions.  However, the
 *   following procedure is RECOMMENDED.  The proxy examines the
 *   branch ID in the topmost Via header field of the received
 *   request.  If it begins with the magic cookie, the first
 *   component of the branch ID of the outgoing request is computed
 *   as a hash of the received branch ID.  Otherwise, the first
 *   component of the branch ID is computed as a hash of the topmost
 *   Via, the tag in the To header field, the tag in the From header
 *   field, the Call-ID header field, the CSeq number (but not
 *   method), and the Request-URI from the received request.  One of
 *   these fields will always vary across two different
 *   transactions.
 *
 * The branch value will consist of:
 * - magic cookie "z9hG4bK"
 * - 1st part (unique calculated ID
 * - 2nd part (value for loop detection) <<- not yet used by siproxd
 */
   osip_message_t *sip_msg=ticket->sipmsg;
   static char *magic_cookie="z9hG4bK";
   osip_via_t *via;
   osip_uri_param_t *param=NULL;
   osip_call_id_t *call_id=NULL;
   HASHHEX hashstring;

   hashstring[0]='\0';

   /*
    * Examine topmost via and look for a magic cookie.
    * If it is there, I use THIS branch parameter as input for
    * our hash calculation
    */
   via = osip_list_get (sip_msg->vias, 0);
   if (via == NULL) {
      ERROR("have a SIP message without any via header");
      return STS_FAILURE;
   }

   param=NULL;
   osip_via_param_get_byname(via, "branch", &param);
   if (param && param->gvalue) {
      DEBUGC(DBCLASS_BABBLE, "looking for magic cookie [%s]",param->gvalue);
      if (strncmp(param->gvalue, magic_cookie,
                  strlen(magic_cookie))==0) {
         /* calculate MD5 hash */
         MD5_CTX Md5Ctx;
         HASH HA1;

         MD5Init(&Md5Ctx);
         MD5Update(&Md5Ctx, param->gvalue,
                   strlen(param->gvalue));
         MD5Final(HA1, &Md5Ctx);
         CvtHex(HA1, hashstring);

         DEBUGC(DBCLASS_BABBLE, "existing branch -> branch hash [%s]",
                hashstring);
      }
   }

   /*
    * If I don't have a branch parameter in the existing topmost via,
    * then I need:
    *   - the topmost via
    *   - the tag in the To header field
    *   - the tag in the From header field
    *   - the Call-ID header field
    *   - the CSeq number (but not method)
    *   - the Request-URI from the received request
    */
   if (hashstring[0] == '\0') {
      /* calculate MD5 hash */
      MD5_CTX Md5Ctx;
      HASH HA1;
      char *tmp;

      MD5Init(&Md5Ctx);

      /* topmost via */
      osip_via_to_str(via, &tmp);
      if (tmp) {
         MD5Update(&Md5Ctx, tmp, strlen(tmp));
         osip_free(tmp);
      }
     
      /* Tag in To header */
      osip_to_get_tag(sip_msg->to, &param);
      if (param && param->gvalue) {
         MD5Update(&Md5Ctx, param->gvalue, strlen(param->gvalue));
      }

      /* Tag in From header */
      osip_from_get_tag(sip_msg->from, &param);
      if (param && param->gvalue) {
         MD5Update(&Md5Ctx, param->gvalue, strlen(param->gvalue));
      }

      /* Call-ID */
      call_id = osip_message_get_call_id(sip_msg);
      osip_call_id_to_str(call_id, &tmp);
      if (tmp) {
         MD5Update(&Md5Ctx, tmp, strlen(tmp));
         osip_free(tmp);
      }

      /* CSeq number (but not method) */
      tmp = osip_cseq_get_number(sip_msg->cseq);
      if (tmp) {
         MD5Update(&Md5Ctx, tmp, strlen(tmp));
      }
 
      /* Request URI */
      osip_uri_to_str(sip_msg->req_uri, &tmp);
      if (tmp) {
         MD5Update(&Md5Ctx, tmp, strlen(tmp));
         osip_free(tmp);
      }

      MD5Final(HA1, &Md5Ctx);
      CvtHex(HA1, hashstring);

      DEBUGC(DBCLASS_BABBLE, "non-existing branch -> branch hash [%s]",
             hashstring);
   }

   /* include the magic cookie */
   sprintf(id, "%s%s", magic_cookie, hashstring);

   return STS_SUCCESS;
}
Пример #15
0
int
Node::SndUserRegisterRequest(REG_TYPE type,
				uinfo_t *user_info,
				const char *registrar,
				int expires)
{
	char *message1;
	unsigned int len = 0;

	osip_message_t *request;
	osip_event_t *sipevent;
	osip_transaction_t *transaction;
	osip_uri_t *uri;
	
	char *tmp_uri;
	int i;

	i=osip_message_init(&request);
	if(i!=0)
		goto si2perror1;
	osip_message_set_method(request,strdup("REGISTER"));
	osip_message_set_version(request,strdup("SIP/2.0"));
	osip_message_set_status_code(request,0);
	osip_message_set_reason_phrase(request,NULL);

	i=osip_uri_init(&uri);
	if(i!=0)
		goto si2perror2;
	i=osip_uri_parse(uri,osip_strdup(registrar));
	osip_message_set_uri(request,uri);

	//*set to,from and header
	if(type==USER_REGISTRATION)
	{	
		char *dest1;
		char *dest2;
		
		osip_uri_to_str(user_info->aor->uri,&dest1);
		i=osip_message_set_to(request,dest1);
		i=osip_message_set_from(request,dest1);
		if(dest1)	osip_free(dest1) ;
		osip_from_param_add (request->from, osip_strdup ("user"), osip_strdup("user_registration"));

		osip_contact_to_str(user_info->bindings->contact,&dest2);
		i=osip_message_set_contact(request,osip_strdup(dest2));
		if(dest2)	osip_free(dest2) ;
	}

	if(type == RED_REGISTER)
	{
		char *dest1;
		char *dest2;
		osip_uri_to_str(user_info->aor->uri,&dest1);
		i=osip_message_set_to(request,dest1);
		i=osip_message_set_from(request,dest1);
		if(dest1)	osip_free(dest1) ;
		osip_from_param_add (request->from, osip_strdup ("user"), osip_strdup("red_register"));

		osip_contact_to_str(user_info->bindings->contact,&dest2);
		i=osip_message_set_contact(request,osip_strdup(dest2));
		if(dest2)	osip_free(dest2) ;
	}

	if(type==TRANSFER_REGISTRATION)
	{
		char *dest1;
		char *dest2;
		//string tmp_uri;
		osip_uri_to_str(user_info->aor->uri,&dest1);
		osip_message_set_to(request,dest1);
		if(dest1)	osip_free(dest1) ;

		tmp_uri = ChordId2Uri(chordId,false);
		osip_message_set_from(request,tmp_uri);
		osip_from_param_add (request->from, osip_strdup ("user"), osip_strdup("transfer_registration"));
		if(tmp_uri)	osip_free(tmp_uri) ;

		osip_contact_to_str(user_info->bindings->contact,&dest2);
		osip_message_set_contact(request,dest2);
		if(dest2)	osip_free(dest2) ;
	}
	if(type==THIRD_PARTY)
	{
		//todo
	}
		//---set call_id and cseq
	osip_call_id_t *callid;
	osip_cseq_t *cseq;
	char *num;
	char  *cidrand;
	char *register_callid_number ;

	//* call-id is always the same for REGISTRATIONS 
	i = osip_call_id_init(&callid);
	if (i!=0) 
		goto si2perror2;
	cidrand = osip_strdup("BF9598C48B184EBBAFADFE527EED8186") ;
	osip_call_id_set_number(callid, cidrand);
	register_callid_number = cidrand;

	osip_call_id_set_host(callid, osip_strdup("SI2P.COM"));
	request->call_id = callid;

	//cseq
	i = osip_cseq_init(&cseq);
	if (i!=0) 
		goto si2perror2 ;
	num = osip_strdup("1");
	osip_cseq_set_number(cseq, num);
	osip_cseq_set_method(cseq, osip_strdup("REGISTER"));
	request->cseq = cseq;
	 
	//*the Max-Forward header 
	osip_message_set_max_forwards(request, "5"); //* a UA should start a request with 70 

	//* the via header 
	char tmp[200];
    snprintf(tmp, 200, "SIP/2.0/%s %s:%s;rport;branch=z9hG4bK%u", "UDP",
	      localip,
	      localport,
	      via_branch_new_random() );

    osip_message_set_via(request, tmp);

	//* the UA header 
	osip_message_set_user_agent(request, user_agent);

	//*  the expires header 
	char exp[10]; //* MUST never be ouside 1 and 3600 
	snprintf(exp, 9, "%i", expires);
	osip_message_set_expires(request, exp);
	osip_message_set_content_length(request, "0");


	//*** then must wake up osip 
	i = osip_transaction_init(&transaction,
		       NICT,
		       adosip->j_osip,
		       request);
	if (i!=0)
		goto si2perror3 ;

	//* send REGISTER 
	i = osip_message_to_str(request, &message1, &len);
	LogStream("SEND======================================>>\n") ;
	LogStream(message1) ;
	if(message1) osip_free(message1) ;
//	printf("SEND======================================>>\n") ;
//	printf(message1) ;
	sipevent = osip_new_outgoing_sipmessage(request);
	sipevent->transactionid =  transaction->transactionid;
	osip_message_force_update(request);
  
	osip_transaction_add_event(transaction, sipevent);

	adosip->ThreadWakeUp();
	return 0;

si2perror1:
	
	return -1;

si2perror2:
	if(request!=NULL)
		osip_message_free(request);
	return -1;

si2perror3:
	if(transaction!=NULL)
		osip_message_free(request);
	return -1;


}
Пример #16
0
static int
dialog_fill_route_set (osip_dialog_t * dialog, osip_message_t * request)
{
  /* if the pre-existing route set contains a "lr" (compliance
     with bis-08) then the req_uri should contains the remote target
     URI */
  int i;
  int pos = 0;
  osip_uri_param_t *lr_param;
  osip_route_t *route;
  char *last_route;

  /* AMD bug: fixed 17/06/2002 */

  route = (osip_route_t *) osip_list_get (&dialog->route_set, 0);

  osip_uri_uparam_get_byname (route->url, "lr", &lr_param);
  if (lr_param != NULL)         /* the remote target URI is the req_uri! */
    {
      i = osip_uri_clone (dialog->remote_contact_uri->url, &(request->req_uri));
      if (i != 0)
        return i;
      /* "[request] MUST includes a Route header field containing
         the route set values in order." */
      /* AMD bug: fixed 17/06/2002 */
      pos = 0;                  /* first element is at index 0 */
      while (!osip_list_eol (&dialog->route_set, pos))
        {
          osip_route_t *route2;

          route = osip_list_get (&dialog->route_set, pos);
          i = osip_route_clone (route, &route2);
          if (i != 0)
            return i;
          osip_list_add (&request->routes, route2, -1);
          pos++;
        }
      return OSIP_SUCCESS;
    }

  /* if the first URI of route set does not contain "lr", the req_uri
     is set to the first uri of route set */


  i = osip_uri_clone (route->url, &(request->req_uri));
  if (i != 0)
    return i;
  /* add the route set */
  /* "The UAC MUST add a route header field containing
     the remainder of the route set values in order. */
  pos = 0;                      /* yes it is */

  while (!osip_list_eol (&dialog->route_set, pos))      /* not the first one in the list */
    {
      osip_route_t *route2;

      route = osip_list_get (&dialog->route_set, pos);
      i = osip_route_clone (route, &route2);
      if (i != 0)
        return i;
      if (!osip_list_eol (&dialog->route_set, pos + 1))
        osip_list_add (&request->routes, route2, -1);
      else
        osip_route_free (route2);
      pos++;
    }

  /* The UAC MUST then place the remote target URI into
     the route header field as the last value */
  i = osip_uri_to_str (dialog->remote_contact_uri->url, &last_route);
  if (i != 0)
    return i;
  i = osip_message_set_route (request, last_route);
  osip_free (last_route);
  if (i != 0)
    {
      return i;
    }

  /* route header and req_uri set */
  return OSIP_SUCCESS;
}
Пример #17
0
int GB_sipd_register_auth(GB_CONNECT_STATE *gb_cons, int flag)
{
	osip_message_t *reg = NULL;
	PRM_GB_SIPD_CFG gb_cfg;
	char from[GB_URI_MAX_LEN] = {0};
	char proxy[GB_URI_MAX_LEN] = {0};
	int ret;
	char *result = NULL;
	size_t length;
	char localip[20];
	char sipserver_ip[20] = {0};
	char *uri = NULL;
	osip_authorization_t *aut = NULL;
	
	SN_MEMSET(&gb_cfg, 0, sizeof(gb_cfg));
	
	GB_Get_GBCfg(&gb_cfg);

	SN_MEMSET(localip,0,sizeof(localip));
	SN_STRCPY(localip,sizeof(localip),GB_Get_LocalIP());
		
	SN_SPRINTF(sipserver_ip,sizeof(sipserver_ip),"%d.%d.%d.%d",
		gb_cfg.sipserver_ip[0],gb_cfg.sipserver_ip[1],gb_cfg.sipserver_ip[2],gb_cfg.sipserver_ip[3]);

	SN_SPRINTF(from, GB_URI_MAX_LEN, "sip:%s@%s", gb_cfg.deviceID, localip);
	SN_SPRINTF(proxy, GB_URI_MAX_LEN, "sip:%s@%s:%d", gb_cfg.sipserver_ID,sipserver_ip, gb_cfg.sipserver_port);

	if(flag == 0)  // 注册
	{
		ret = gb_generating_register(&reg, Transport_Str[gb_cons->transfer_protocol], from, proxy, NULL, gb_cfg.register_period, localip,gb_cfg.local_port, gb_cons->local_cseq);
	}
	else  //  注销
	{
		ret = gb_generating_register(&reg, Transport_Str[gb_cons->transfer_protocol], from, proxy, NULL, 0, localip,gb_cfg.local_port, gb_cons->local_cseq);
	}
		
	if (ret < 0)
	{
		osip_message_free (reg);
		return -1;
	}

	ret = osip_uri_to_str (reg->req_uri, &uri);
	if (ret != 0)
		return ret;
	
	ret = gb_create_authorization_header (gb_cons->wwwa, uri, ADMIN_NAME, (char *)gb_cfg.reg_pwd, NULL, &aut, "REGISTER", NULL, 0);

	osip_free (uri);
	if (ret != 0)
		return ret;

	if (aut != NULL) 
	{
		if (osip_strcasecmp (reg->sip_method, "REGISTER") == 0)
			osip_list_add (&reg->authorizations, aut, -1);
		else
			osip_list_add (&reg->proxy_authorizations, aut, -1);
		osip_message_force_update (reg);	
	}

	ret = osip_message_to_str(reg, &result, &length);
	if (ret == -1) 
	{
		printf("ERROR: failed while printing message!\n");
		osip_message_free (reg);
		return -1;
	}	
	gb_cons->local_cseq++;
	GB_SocketSendData(gb_cons->connfd,inet_ntoa(gb_cons->remoteAddr.sin_addr), ntohs(gb_cons->remoteAddr.sin_port), result, length, 0);
	SN_FREE(result);
	osip_message_free(reg);
	
	return 0;
}
Пример #18
0
int messages::remote(const char *to, message *msg, const char *digest)
{
    shell::debug(3, "instant message delivered to %s from %s", to, msg->reply);

    voip::msg_t im = NULL;
    int error = SIP_BAD_REQUEST;
    char route[MAX_URI_SIZE];
    srv resolv;
    voip::context_t ctx = resolv.route(to, route, sizeof(route));
    char rewrite[MAX_URI_SIZE];
    const char *schema = NULL;

    if(!ctx)
        return error;

    if(eq(to, "tcp:", 4)) {
        schema = "sip";
        to += 4;
    }
    else if(eq(to, "udp:", 4)) {
        schema = "sip";
        to += 4;
    }

    if(schema) {
        snprintf(rewrite, sizeof(rewrite), "%s:%s", schema, to);
        to = rewrite;
    }

    if(voip::make_request_message(ctx, "MESSAGE", to, msg->from, &im, route)) {
        char *authbuf = new char[1024];
        stringbuf<64> response;
        stringbuf<64> once;
        char nounce[64];
        char *req = NULL;
        osip_uri_to_str(im->req_uri, &req);
        snprintf(authbuf, 1024, "%s:%s", im->sip_method, req);
        Random::uuid(nounce);

        digest_t auth("md5");
        auth.puts(nounce);
        once = *auth;
        auth = registry::getDigest();
        auth.puts(authbuf);
        response = *auth;
        snprintf(authbuf, 1024, "%s:%s:%s", digest, *once, *response);
        auth.reset();
        auth.puts(authbuf);
        response = *auth;
        snprintf(authbuf, 1024,
            "Digest username=\"%s\""
            ",realm=\"%s\""
            ",uri=\"%s\""
            ",response=\"%s\""
            ",nonce=\"%s\""
            ",algorithm=%s"
            ,msg->reply, registry::getRealm(), req, *response, *once, registry::getDigest());
        voip::header(im, AUTHORIZATION, authbuf);
        delete[] authbuf;
        osip_free(req);
    }
    if(im) {
        voip::attach(im, msg->type, msg->body, msg->msglen);
        stack::siplog(im);
        voip::send_request_message(ctx, im);
        error = SIP_OK;
    }
    return error;
}
Пример #19
0
/* returns -1 on error. */
int osip_record_route_to_str(const osip_record_route_t * record_route, char **dest)
{
	char *url;
	char *buf;
	int i;
	size_t len;

	*dest = NULL;
	if ((record_route == NULL) || (record_route->url == NULL))
		return OSIP_BADPARAMETER;

	i = osip_uri_to_str(record_route->url, &url);
	if (i != 0)
		return i;

	if (record_route->displayname == NULL)
		len = strlen(url) + 5;
	else
		len = strlen(url) + strlen(record_route->displayname) + 5;

	buf = (char *) osip_malloc(len);
	if (buf == NULL) {
		osip_free(url);
		return OSIP_NOMEM;
	}

	/* route and record-route always use brackets */
	if (record_route->displayname != NULL)
		sprintf(buf, "%s <%s>", record_route->displayname, url);
	else
		sprintf(buf, "<%s>", url);
	osip_free(url);

	{
		int pos = 0;
		osip_generic_param_t *u_param;
		size_t plen;
		char *tmp;

		while (!osip_list_eol(&record_route->gen_params, pos)) {
			u_param =
				(osip_generic_param_t *) osip_list_get(&record_route->gen_params,
													   pos);

			if (u_param->gvalue == NULL)
				plen = strlen(u_param->gname) + 2;
			else
				plen = strlen(u_param->gname) + strlen(u_param->gvalue) + 3;
			len = len + plen;
			buf = (char *) osip_realloc(buf, len);
			tmp = buf;
			tmp = tmp + strlen(tmp);
			if (u_param->gvalue == NULL)
				sprintf(tmp, ";%s", u_param->gname);
			else
				sprintf(tmp, ";%s=%s", u_param->gname, u_param->gvalue);
			pos++;
		}
	}
	*dest = buf;
	return OSIP_SUCCESS;
}