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

📄 osip_authorization.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_authorization_init (osip_authorization_t ** dest){  *dest = (osip_authorization_t *) osip_malloc (sizeof (osip_authorization_t));  if (*dest == NULL)    return -1;  (*dest)->auth_type = NULL;  (*dest)->username = NULL;  (*dest)->realm = NULL;  (*dest)->nonce = NULL;  (*dest)->uri = NULL;  (*dest)->response = NULL;  (*dest)->digest = NULL;       /* DO NOT USE IT IN AUTHORIZATION_T HEADER?? */  (*dest)->algorithm = NULL;    /* optionnal, default is "md5" */  (*dest)->cnonce = NULL;       /* optionnal */  (*dest)->opaque = NULL;       /* optionnal */  (*dest)->message_qop = NULL;  /* optionnal */  (*dest)->nonce_count = NULL;  /* optionnal */  (*dest)->auth_param = NULL;   /* for other headers --NOT IMPLEMENTED-- */  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_authorization (osip_message_t * sip, const char *hvalue){  osip_authorization_t *authorization;  int i;  if (hvalue == NULL || hvalue[0] == '\0')    return 0;  if (sip == NULL)    return -1;  i = osip_authorization_init (&authorization);  if (i != 0)    return -1;  i = osip_authorization_parse (authorization, hvalue);  if (i != 0)    {      osip_authorization_free (authorization);      return -1;    }  sip->message_property = 2;  osip_list_add (&sip->authorizations, authorization, -1);  return 0;}/* fills the www-authenticate structure.           *//* 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_authorization_parse (osip_authorization_t * auth, 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)    return -1;  auth->auth_type = (char *) osip_malloc (space - hvalue + 1);  osip_strncpy (auth->auth_type, hvalue, space - hvalue);  for (;;)    {      int parse_ok = 0;      if (__osip_quoted_string_set ("username", space, &(auth->username), &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 ("realm", space, &(auth->realm), &next))        return -1;      if (next == NULL)        return 0;      else if (next != space)        {          space = next;          parse_ok++;        }      if (__osip_quoted_string_set ("nonce", space, &(auth->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 ("uri", space, &(auth->uri), &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 ("response", space, &(auth->response), &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 ("digest", space, &(auth->digest), &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, &(auth->algorithm), &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 ("cnonce", space, &(auth->cnonce), &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, &(auth->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 ("qop", space, &(auth->message_qop), &next))        return -1;      if (next == NULL)        return 0;               /* end of header detected! */      else if (next != space)        {          space = next;          parse_ok++;        }      if (__osip_token_set ("nc", space, &(auth->nonce_count), &next))        return -1;      if (next == NULL)        return 0;               /* end of header detected! */      else if (next != space)        {          space = next;          parse_ok++;        }      /* nothing was recognized:         here, we should handle a list of unknown tokens where:         token1 = ( token2 | quoted_text ) */      /* TODO */      if (0 == parse_ok)        {          const char *quote1, *quote2, *tmp;          /* CAUTION */          /* parameter not understood!!! I'm too lazy to handle IT */          /* let's simply bypass it */          if (strlen (space) < 1)            return 0;          tmp = strchr (space + 1, ',');          if (tmp == NULL)      /* it was the last header */            return 0;          quote1 = __osip_quote_find (space);          if ((quote1 != NULL) && (quote1 < tmp))       /* this may be a quoted string! */            {              quote2 = __osip_quote_find (quote1 + 1);              if (quote2 == NULL)                return -1;      /* bad header format... */              if (tmp < quote2) /* the comma is inside the quotes! */                space = strchr (quote2, ',');              else                space = tmp;              if (space == NULL)        /* it was the last header */                return 0;          } else            space = tmp;          /* continue parsing... */        }    }  return 0;                     /* ok */}#ifndef MINISIZE/* returns the authorization header.   *//* INPUT : osip_message_t *sip | sip message.   *//* returns null on error. */intosip_message_get_authorization (const osip_message_t * sip, int pos,                                osip_authorization_t ** dest){  osip_authorization_t *authorization;  *dest = NULL;  if (osip_list_size (&sip->authorizations) <= pos)    return -1;                  /* does not exist */  authorization =    (osip_authorization_t *) osip_list_get (&sip->authorizations, pos);  *dest = authorization;  return pos;}#endifchar *osip_authorization_get_auth_type (const osip_authorization_t * authorization){  return authorization->auth_type;}voidosip_authorization_set_auth_type (osip_authorization_t * authorization,                                  char *auth_type){  authorization->auth_type = (char *) auth_type;}char *osip_authorization_get_username (osip_authorization_t * authorization){  return authorization->username;}voidosip_authorization_set_username (osip_authorization_t * authorization,                                 char *username){  authorization->username = (char *) username;}char *osip_authorization_get_realm (osip_authorization_t * authorization){  return authorization->realm;}voidosip_authorization_set_realm (osip_authorization_t * authorization, char *realm){  authorization->realm = (char *) realm;}char *osip_authorization_get_nonce (osip_authorization_t * authorization){  return authorization->nonce;}voidosip_authorization_set_nonce (osip_authorization_t * authorization, char *nonce){  authorization->nonce = (char *) nonce;}char *osip_authorization_get_uri (osip_authorization_t * authorization){  return authorization->uri;}voidosip_authorization_set_uri (osip_authorization_t * authorization, char *uri){  authorization->uri = (char *) uri;}char *osip_authorization_get_response (osip_authorization_t * authorization){

⌨️ 快捷键说明

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