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

📄 ppluinfo.c

📁 用于linux环境下的SIP服务器
💻 C
📖 第 1 页 / 共 2 页
字号:
  bind->when = now + length;	/* registration will expire in 'length' seconds */  /* avoid too much sorting... */  i = osip_contact_param_get_byname (dest, "q", &q);  if (i != 0      || (q != NULL && q->gvalue != NULL && 0 == strncmp (q->gvalue, "1", 1)))    {      ADD_ELEMENT (uinfo->bindings, bind);    }  else    {      APPEND_ELEMENT (binding_t, uinfo->bindings, bind);    }  ppl_uinfo_sort (uinfo);  if (uinfo->bindings==NULL)    uinfo->status = 2;  else    uinfo->status = 1;  return 0;}/** * Add a new binding (a contact header) to a uinfo. * This method also record the Path fields (rfc3327.txt) */PPL_DECLARE (int)ppl_uinfo_add_binding_with_path (ppl_uinfo_t * uinfo, osip_contact_t * con,				 char *exp, char *path){  int i;  osip_contact_t *dest;  binding_t *bind;  osip_generic_param_t *exp_p;  osip_generic_param_t *q;  ppl_time_t now;  int length;  char *tmp;  if (uinfo == NULL)    return -1;  now = ppl_time ();  if (con == NULL)    return -1;  if (con->displayname != NULL && 0 == strcmp (con->displayname, "*"))    {      ppl_uinfo_remove_all_bindings (uinfo);      return 0;    }  /*  we MUST check if the contact info already exist */  for (bind = uinfo->bindings; bind != NULL; bind = bind->next)    {      if (bind->contact == NULL || bind->contact->url == NULL || con->url == NULL)	/* no */	{	}      else if (bind->contact->url->username != NULL	       && con->url->username != NULL	       && bind->contact->url->host != NULL && con->url->host != NULL)	{	  if (0 ==	      strcasecmp (bind->contact->url->username, con->url->username)	      && 0 == strcasecmp (bind->contact->url->host, con->url->host))	    {			/* find a match! replace the entry... */	      /* TODO?: ip and FQDN also must match... */#ifndef ENABLE_MPATROL /* just to ease local test of forking proxy */	      ppl_uinfo_remove_binding (uinfo, bind);#endif	      break;	    }	}      else if (bind->contact->url->username == NULL	       && con->url->username == NULL	       && bind->contact->url->host != NULL && con->url->host != NULL)	if (0 == strcasecmp (bind->contact->url->host, con->url->host))	  {	    ppl_uinfo_remove_binding (uinfo, bind);	    break;	  }    }  bind = (binding_t *) osip_malloc (sizeof (binding_t));  bind->next = NULL;  bind->parent = NULL;  i = osip_contact_clone (con, &dest);  if (i != 0)    {      if (uinfo->bindings==NULL)	uinfo->status = 2;      else	uinfo->status = 1;      osip_free (bind);      return -1;    }  bind->path = osip_strdup(path);  i = osip_contact_param_get_byname (dest, "expires", &exp_p);  if (i != 0)    {      if (exp != NULL)	tmp = osip_strdup (exp);      else	tmp = osip_strdup ("3600");      osip_contact_param_add (dest, osip_strdup ("expires"), tmp);      length = atoi (tmp);    }  else    {      length = atoi (exp_p->gvalue);    }  bind->contact = dest;  if (length <= 0)    {				/* this registration is expired! */      if (uinfo->bindings==NULL)	uinfo->status = 2;      else	uinfo->status = 1;      osip_contact_free (bind->contact);      osip_free (bind->path);      osip_free (bind);      return 0;    }  bind->when = now + length;	/* registration will expire in 'length' seconds */  /* avoid too much sorting... */  i = osip_contact_param_get_byname (dest, "q", &q);  if (i != 0      || (q != NULL && q->gvalue != NULL && 0 == strncmp (q->gvalue, "1", 1)))    {      ADD_ELEMENT (uinfo->bindings, bind);    }  else    {      APPEND_ELEMENT (binding_t, uinfo->bindings, bind);    }  ppl_uinfo_sort (uinfo);  if (uinfo->bindings==NULL)    uinfo->status = 2;  else    uinfo->status = 1;  return 0;}/** * Remove a binding. */PPL_DECLARE (int)ppl_uinfo_remove_binding (ppl_uinfo_t * uinfo, binding_t * bind){  if (uinfo == NULL || bind == NULL)    return -1;  REMOVE_ELEMENT (uinfo->bindings, bind);  osip_contact_free (bind->contact);  osip_free (bind->path);  osip_free (bind);  return 0;}/** * Add a authorized third party in uinfo. */PPL_DECLARE (int) ppl_uinfo_add_third_party (ppl_uinfo_t * uinfo, osip_uri_t * url){  aor_t *aor;  osip_uri_t *dest;  int i;  aor = (aor_t *) osip_malloc (sizeof (aor_t));  if (aor == NULL)    return -1;  aor->url = NULL;  aor->next = NULL;  aor->parent = NULL;  i = osip_uri_clone (url, &dest);  if (i != 0)    {      osip_free (aor);      return -1;    }  aor->url = dest;  ADD_ELEMENT (uinfo->aor_3rd_parties, aor);  return 0;}/** * Delete a binding entry. (internal!) */PPL_DECLARE (void) ppl_uinfo_binding_free (binding_t * bind){  if (bind == NULL)    return;  osip_contact_free (bind->contact);  osip_free (bind->path);  osip_free (bind);  return;}/** * Delete all entries. */PPL_DECLARE (void) ppl_uinfo_remove (ppl_uinfo_t * uinfo){  aor_t *aor;  binding_t *bind;  if (uinfo == NULL)    return;  if (dbm!=NULL      &&uinfo->aor!=NULL      &&uinfo->aor->url!=NULL      &&uinfo->aor->url->username!=NULL)    {      ppl_dbm_delete(dbm, uinfo->aor->url->username);    }  REMOVE_ELEMENT (user_infos, uinfo);  osip_free (uinfo->login);  osip_free (uinfo->passwd);  for (aor = uinfo->aor; aor != NULL; aor = uinfo->aor)    {      REMOVE_ELEMENT (uinfo->aor, aor);      osip_uri_free (aor->url);      osip_free (aor);    }  for (aor = uinfo->aor_3rd_parties; aor != NULL;       aor = uinfo->aor_3rd_parties)    {      REMOVE_ELEMENT (uinfo->aor_3rd_parties, aor);      osip_uri_free (aor->url);      osip_free (aor);    }  for (bind = uinfo->bindings; bind != NULL; bind = uinfo->bindings)    {      REMOVE_ELEMENT (uinfo->bindings, bind);      ppl_uinfo_binding_free (bind);    }  osip_free (uinfo);  return;}/** * Remove all bindings for this user (and force deletion if force==1). */static void_ppl_uinfo_remove_all_bindings (ppl_uinfo_t * uinfo, int force){  binding_t *b;  if (force == 1)    {      if (uinfo->bindings==NULL)	uinfo->status = 2;      ppl_uinfo_remove (uinfo);      return;    }  for (b = uinfo->bindings; b != NULL; b = uinfo->bindings)    {      REMOVE_ELEMENT (uinfo->bindings, b);      osip_contact_free (b->contact);      osip_free (b->path);      osip_free (b);    }}/** * Remove all bindings for this user (and delete if it does not contains * any static entry). */PPL_DECLARE (void)ppl_uinfo_remove_all_bindings (ppl_uinfo_t * uinfo){  _ppl_uinfo_remove_all_bindings (uinfo, -1);  if (uinfo->bindings==NULL)    uinfo->status = 2;}PPL_DECLARE (void)ppl_uinfo_store_bindings (ppl_uinfo_t * uinfo){#if defined(HAVE_GDBM_H) || defined(HAVE_GDBM_NDBM_H) || defined(HAVE_DB_H) || defined(HAVE_DB1_DB_H) || defined(HAVE_DB2_DB_H) || defined(HAVE_DB3_DB_H) || defined(HAVE_NDBM_H) || defined(HAVE_DBM_H)  if (dbm!=NULL)    ppl_dbm_store(dbm, uinfo);#endif}/** * Delete all entries. */PPL_DECLARE (void)ppl_uinfo_free_all (){  ppl_uinfo_t *uinfo;  for (uinfo = user_infos; uinfo != NULL; uinfo = user_infos)    {      ppl_uinfo_remove (uinfo);    }  osip_mutex_destroy (ppl_uinfo_mutex);}/** * Close dbm file. */PPL_DECLARE (void)ppl_uinfo_close_dbm (){#if defined(HAVE_GDBM_H) || defined(HAVE_GDBM_NDBM_H) || defined(HAVE_DB_H) || defined(HAVE_DB1_DB_H) || defined(HAVE_DB2_DB_H) || defined(HAVE_DB3_DB_H) || defined(HAVE_NDBM_H) || defined(HAVE_DBM_H)  ppl_uinfo_t *uinfo;  int modified = 0;  int i;  /* force update for expired registrations */  for (uinfo = user_infos; uinfo != NULL; uinfo = uinfo->next)    {      binding_t *b;      binding_t *bnext;      modified = 0;      for (bnext = uinfo->bindings; bnext != NULL;)	{	  b = bnext;	  bnext = b->next;	  i = ppl_uinfo_check_binding (b);	  if (i != 0)	    {			/* binding is expired */	      ppl_uinfo_remove_binding (uinfo, b);	      modified = 1;	    }	}      if (modified==1)	ppl_uinfo_store_bindings(uinfo);    }  if (dbm!=NULL)    {      ppl_dbm_close(dbm);      osip_free(dbm);      dbm=NULL;    }#endif  }

⌨️ 快捷键说明

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