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

📄 osip_www_authenticate.c

📁 libosip2-3.0.3最新版本
💻 C
📖 第 1 页 / 共 2 页
字号:
/*  The oSIP library implements the Session Initiation Protocol (SIP -rfc3261-)  Copyright (C) 2001,2002,2003,2004,2005,2006,2007 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*/#include <stdlib.h>#include <stdio.h>#include <osipparser2/osip_port.h>#include <osipparser2/osip_message.h>#include <osipparser2/osip_parser.h>#include "parser.h"intosip_www_authenticate_init (osip_www_authenticate_t ** dest){  *dest =    (osip_www_authenticate_t *) osip_malloc (sizeof (osip_www_authenticate_t));  if (*dest == NULL)    return -1;  memset (*dest, 0, sizeof (osip_www_authenticate_t));  return 0;}/* fills the www-authenticate header of message.               *//* INPUT :  char *hvalue | value of header.   *//* OUTPUT: osip_message_t *sip | structure to save results. *//* returns -1 on error. */intosip_message_set_www_authenticate (osip_message_t * sip, const char *hvalue){  osip_www_authenticate_t *www_authenticate;  int i;  if (hvalue == NULL || hvalue[0] == '\0')    return 0;  if (sip == NULL)    return -1;  i = osip_www_authenticate_init (&www_authenticate);  if (i != 0)    return -1;  i = osip_www_authenticate_parse (www_authenticate, hvalue);  if (i != 0)    {      osip_www_authenticate_free (www_authenticate);      return -1;    }  sip->message_property = 2;  osip_list_add (&sip->www_authenticates, www_authenticate, -1);  return 0;}int__osip_quoted_string_set (const char *name, const char *str,                          char **result, const char **next){  *next = str;  if (*result != NULL)    return 0;                   /* already parsed */  *next = NULL;  while ((' ' == *str) || ('\t' == *str) || (',' == *str))    if (*str)      str++;    else      return -1;                /* bad header format */  if (strlen (str) <= strlen (name))    return -1;                  /* bad header format... */  if (osip_strncasecmp (name, str, strlen (name)) == 0)    {      const char *quote1;      const char *quote2;      const char *tmp;      const char *hack = strchr (str, '=');      if (hack == NULL)        return -1;      while (' ' == *(hack - 1))        /* get rid of extra spaces */        hack--;      if ((size_t) (hack - str) != strlen (name))        {          *next = str;          return 0;        }      quote1 = __osip_quote_find (str);      if (quote1 == NULL)        return -1;              /* bad header format... */      quote2 = __osip_quote_find (quote1 + 1);      if (quote2 == NULL)        return -1;              /* bad header format... */      if (quote2 - quote1 == 1)        {          /* this is a special case! The quote contains nothing! */          /* example:   Digest opaque="",cnonce=""               */          /* in this case, we just forget the parameter... this  */          /* this should prevent from user manipulating empty    */          /* strings */          tmp = quote2 + 1;     /* next element start here */          for (; *tmp == ' ' || *tmp == '\t'; tmp++)            {            }          for (; *tmp == '\n' || *tmp == '\r'; tmp++)            {            }                   /* skip LWS */          *next = NULL;          if (*tmp == '\0')     /* end of header detected */            return 0;          if (*tmp != '\t' && *tmp != ' ')            /* LWS here ? */            *next = tmp;          else            {                   /* it is: skip it... */              for (; *tmp == ' ' || *tmp == '\t'; tmp++)                {                }              if (*tmp == '\0') /* end of header detected */                return 0;              *next = tmp;            }          return 0;        }      *result = (char *) osip_malloc (quote2 - quote1 + 3);      if (*result == NULL)        return -1;      osip_strncpy (*result, quote1, quote2 - quote1 + 1);      tmp = quote2 + 1;         /* next element start here */      for (; *tmp == ' ' || *tmp == '\t'; tmp++)        {        }      for (; *tmp == '\n' || *tmp == '\r'; tmp++)        {        }                       /* skip LWS */      *next = NULL;      if (*tmp == '\0')         /* end of header detected */        return 0;      if (*tmp != '\t' && *tmp != ' ')        /* LWS here ? */        *next = tmp;      else        {                       /* it is: skip it... */          for (; *tmp == ' ' || *tmp == '\t'; tmp++)            {            }          if (*tmp == '\0')     /* end of header detected */            return 0;          *next = tmp;        }  } else    *next = str;                /* wrong header asked! */  return 0;}int__osip_token_set (const char *name, const char *str, char **result,                  const char **next){  const char *beg;  const char *tmp;  *next = str;  if (*result != NULL)    return 0;                   /* already parsed */  *next = NULL;  beg = strchr (str, '=');  if (beg == NULL)    return -1;                  /* bad header format... */  if (strlen (str) < 6)    return 0;                   /* end of header... */  while ((' ' == *str) || ('\t' == *str) || (',' == *str))    if (*str)      str++;    else      return -1;                /* bad header format */  if (osip_strncasecmp (name, str, strlen (name)) == 0)    {      const char *end;      end = strchr (str, ',');      if (end == NULL)        end = str + strlen (str);       /* This is the end of the header */      if (end - beg < 2)        return -1;      *result = (char *) osip_malloc (end - beg);      if (*result == NULL)        return -1;      osip_clrncpy (*result, beg + 1, end - beg - 1);      /* make sure the element does not contain more parameter */      tmp = (*end) ? (end + 1) : end;      for (; *tmp == ' ' || *tmp == '\t'; tmp++)        {        }      for (; *tmp == '\n' || *tmp == '\r'; tmp++)        {        }                       /* skip LWS */      *next = NULL;      if (*tmp == '\0')         /* end of header detected */        return 0;      if (*tmp != '\t' && *tmp != ' ')        /* LWS here ? */        *next = tmp;      else        {                       /* it is: skip it... */          for (; *tmp == ' ' || *tmp == '\t'; tmp++)            {            }          if (*tmp == '\0')     /* end of header detected */            return 0;          *next = tmp;        }  } else    *next = str;                /* next element start here */  return 0;}/* fills the www-authenticate strucuture.                      *//* INPUT : char *hvalue | value of header.         *//* OUTPUT: osip_message_t *sip | structure to save results. *//* returns -1 on error. *//* TODO:   digest-challenge tken has no order preference??   verify many situations (extra SP....)*/intosip_www_authenticate_parse (osip_www_authenticate_t * wwwa, const char *hvalue){  const char *space;  const char *next = NULL;  space = strchr (hvalue, ' '); /* SEARCH FOR SPACE */  if (space == NULL)    return -1;  if (space - hvalue + 1 < 2)    return -1;  wwwa->auth_type = (char *) osip_malloc (space - hvalue + 1);  if (wwwa->auth_type == NULL)    return -1;  osip_strncpy (wwwa->auth_type, hvalue, space - hvalue);  for (;;)    {      int parse_ok = 0;      if (__osip_quoted_string_set ("realm", space, &(wwwa->realm), &next))        return -1;      if (next == NULL)        return 0;               /* end of header detected! */      else if (next != space)        {          space = next;          parse_ok++;        }      if (__osip_quoted_string_set ("domain", space, &(wwwa->domain), &next))        return -1;      if (next == NULL)        return 0;               /* end of header detected! */      else if (next != space)        {          space = next;          parse_ok++;        }      if (__osip_quoted_string_set ("nonce", space, &(wwwa->nonce), &next))        return -1;      if (next == NULL)        return 0;               /* end of header detected! */      else if (next != space)        {          space = next;          parse_ok++;        }      if (__osip_quoted_string_set ("opaque", space, &(wwwa->opaque), &next))        return -1;      if (next == NULL)        return 0;               /* end of header detected! */      else if (next != space)        {          space = next;          parse_ok++;        }      if (__osip_token_set ("stale", space, &(wwwa->stale), &next))        return -1;      if (next == NULL)        return 0;               /* end of header detected! */      else if (next != space)        {          space = next;          parse_ok++;        }      if (__osip_token_set ("algorithm", space, &(wwwa->algorithm), &next))        return -1;      if (next == NULL)        return 0;               /* end of header detected! */

⌨️ 快捷键说明

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