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

📄 osip_port.c

📁 嵌入式产品中的osip的源代码.
💻 C
📖 第 1 页 / 共 2 页
字号:
/*  The oSIP library implements the Session Initiation Protocol (SIP -rfc3261-)  Copyright (C) 2001,2002,2003  Aymeric MOIZARD jack@atosc.org    This library is free software; you can redistribute it and/or  modify it under the terms of the GNU Lesser General Public  License as published by the Free Software Foundation; either  version 2.1 of the License, or (at your option) any later version.    This library is distributed in the hope that it will be useful,  but WITHOUT ANY WARRANTY; without even the implied warranty of  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU  Lesser General Public License for more details.    You should have received a copy of the GNU Lesser General Public  License along with this library; if not, write to the Free Software  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA*/#ifdef _WIN32_WCE#define _INC_TIME		/* for wce.h */#include <windows.h>#endif#include <stdlib.h>#include <stdio.h>#include <stdarg.h>#include <osipparser2/osip_port.h>#ifdef HAVE_CTYPE_H#include <ctype.h>#endif#include <time.h>#if defined(__VXWORKS_OS__)#include <selectLib.h>#elif (!defined(WIN32) && !defined(_WIN32_WCE))#include <sys/time.h>#elif defined(WIN32)#include <windows.h>#ifdef WIN32_USE_CRYPTO#include <Wincrypt.h>#endif#endif#if defined (HAVE_SYS_UNISTD_H)#  include <sys/unistd.h>#endif#if defined (HAVE_UNISTD_H)#  include <unistd.h>#endif#if defined (HAVE_SYSLOG_H)#  include <syslog.h>#endif#if defined (HAVE_SYS_SELECT_H)#  include <sys/select.h>#endif#ifdef HAVE_PTH_PTHREAD_H#include <pthread.h>#endifFILE *logfile = NULL;int tracing_table[END_TRACE_LEVEL];static int use_syslog = 0;static unsigned int random_seed_set = 0;#ifndef WIN32_USE_CRYPTOunsigned intosip_build_random_number ()#elsestatic unsigned intosip_fallback_random_number ()#endif{  if (!random_seed_set)    {#ifndef WIN32      struct timeval tv;      gettimeofday (&tv, NULL);      srand (tv.tv_usec);#else      srand (time (NULL));#endif      random_seed_set = 1;    }  return rand ();}#ifdef WIN32_USE_CRYPTOunsigned intosip_build_random_number (){  HCRYPTPROV crypto;  BOOL err;  unsigned int num;  err =    CryptAcquireContext (&crypto, NULL, NULL, PROV_RSA_FULL,			 CRYPT_VERIFYCONTEXT);  if (err)    {      err = CryptGenRandom (crypto, sizeof (num), (BYTE *) & num);      CryptReleaseContext (crypto, 0);    }  if (!err)    {      num = osip_fallback_random_number ();    }  return num;}#endif#if defined(__linux)#include <limits.h>#endifintosip_atoi (const char *number){#if defined(__linux) || defined(HAVE_STRTOL)  int i;  if (number == NULL)    return -1;  i = strtol (number, (char **) NULL, 10);  if (i == LONG_MIN || i == LONG_MAX)    return -1;  return i;#endif  return atoi (number);}char *osip_strncpy (char *dest, const char *src, size_t length){#ifdef WIN32  strncpy (dest, src, length);#else  strncpy (dest, src, length);#endif  dest[length] = '\0';  return dest;}/* append string_osip_to_append to string at position cur   size is the current allocated size of the element*/char *__osip_sdp_append_string (char *string, size_t size, char *cur,			  char *string_osip_to_append){  size_t length = strlen (string_osip_to_append);  if (cur - string + length > size)    {      size_t length2;      length2 = cur - string;      string = realloc (string, size + length + 10);      cur = string + length2;	/* the initial allocation may have changed! */    }  osip_strncpy (cur, string_osip_to_append, length);  return cur + strlen (cur);}voidosip_usleep (int useconds){#ifdef WIN32  Sleep (useconds / 1000);#else  struct timeval delay;  int sec;  sec = (int) useconds / 1000000;  if (sec > 0)    {      delay.tv_sec = sec;      delay.tv_usec = 0;    }  else    {      delay.tv_sec = 0;      delay.tv_usec = useconds;    }  select (0, 0, 0, 0, &delay);#endif}char *osip_strdup (const char *ch){  char *copy;  size_t length;  if (ch == NULL)    return NULL;  length = strlen (ch);  copy = (char *) osip_malloc (length + 1);  osip_strncpy (copy, ch, length);  return copy;}char *osip_strdup_without_quote (const char *ch){  char *copy = (char *) osip_malloc (strlen (ch) + 1);  /* remove leading and trailing " */  if ((*ch == '\"'))    {      osip_strncpy (copy, ch + 1, strlen (ch + 1));      osip_strncpy (copy + strlen (copy) - 1, "\0", 1);    }  else    osip_strncpy (copy, ch, strlen (ch));  return copy;}intosip_tolower (char *word){#ifdef HAVE_CTYPE_H  for (; *word; word++)    *word = (char) tolower (*word);#else  int i;  size_t len = strlen (word);  for (i = 0; i <= len - 1; i++)    {      if ('A' <= word[i] && word[i] <= 'Z')	word[i] = word[i] + 32;    }#endif  return 0;}intosip_strcasecmp (const char *s1, const char *s2){#if (!defined WIN32 && !defined _WIN32_WCE)  return strcasecmp (s1, s2);#else  return _stricmp (s1, s2);#endif}intosip_strncasecmp (const char *s1, const char *s2, size_t len){#if (!defined WIN32 && !defined _WIN32_WCE)  return strncasecmp (s1, s2, len);#else  return _strnicmp (s1, s2, len);#endif}/* remove SPACE before and after the content */intosip_clrspace (char *word){  char *pbeg;  char *pend;  size_t len;  if (word == NULL)    return -1;  if (*word == '\0')    return 0;  len = strlen (word);  pbeg = word;  while ((' ' == *pbeg) || ('\r' == *pbeg) || ('\n' == *pbeg)	 || ('\t' == *pbeg))    pbeg++;  pend = word + len - 1;  while ((' ' == *pend) || ('\r' == *pend) || ('\n' == *pend)	 || ('\t' == *pend))    {      pend--;      if (pend < pbeg)	{	  *word = '\0';	  return 0;	}    }  /* Add terminating NULL only if we've cleared room for it */  if (pend + 1 <= word + (len - 1))    pend[1] = '\0';  if (pbeg != word)    memmove (word, pbeg, pend - pbeg + 2);  return 0;}/* __osip_set_next_token:   dest is the place where the value will be allocated   buf is the string where the value is searched   end_separator is the character that MUST be found at the end of the value   next is the final location of the separator + 1   the element MUST be found before any "\r" "\n" "\0" and   end_separator   return -1 on error   return 1 on success*/int__osip_set_next_token (char **dest, char *buf, int end_separator, char **next){  char *sep;			/* separator */  *next = NULL;  sep = buf;  while ((*sep != end_separator) && (*sep != '\0') && (*sep != '\r')	 && (*sep != '\n'))    sep++;  if ((*sep == '\r') || (*sep == '\n'))    {				/* we should continue normally only if this is the separator asked! */      if (*sep != end_separator)	return -1;    }  if (*sep == '\0')    return -1;			/* value must not end with this separator! */  if (sep == buf)    return -1;			/* empty value (or several space!) */  *dest = osip_malloc (sep - (buf) + 1);  osip_strncpy (*dest, buf, sep - buf);  *next = sep + 1;		/* return the position right after the separator */  return 0;}#if 0/*  not yet done!!! :-) */int__osip_set_next_token_better (char **dest, char *buf, int end_separator,			      int *forbidden_tab[], int size_tab, char **next){  char *sep;			/* separator */  *next = NULL;  sep = buf;  while ((*sep != end_separator) && (*sep != '\0') && (*sep != '\r')	 && (*sep != '\n'))    sep++;  if ((*sep == '\r') && (*sep == '\n'))    {				/* we should continue normally only if this is the separator asked! */      if (*sep != end_separator)	return -1;    }  if (*sep == '\0')    return -1;			/* value must not end with this separator! */  if (sep == buf)

⌨️ 快捷键说明

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