Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Blame | Last modification | View Log | Download | RSS feed

  1. /*
  2.  * Copyright 2010 John-Mark Bell <jmb@netsurf-browser.org>
  3.  *
  4.  * This file is part of NetSurf, http://www.netsurf-browser.org/
  5.  *
  6.  * NetSurf is free software; you can redistribute it and/or modify
  7.  * it under the terms of the GNU General Public License as published by
  8.  * the Free Software Foundation; version 2 of the License.
  9.  *
  10.  * NetSurf is distributed in the hope that it will be useful,
  11.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13.  * GNU General Public License for more details.
  14.  *
  15.  * You should have received a copy of the GNU General Public License
  16.  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  17.  */
  18.  
  19. #include <stdlib.h>
  20.  
  21. #include "utils/http/challenge_internal.h"
  22. #include "utils/http/generics.h"
  23. #include "utils/http/parameter_internal.h"
  24. #include "utils/http/primitives.h"
  25. #include "utils/http/www-authenticate.h"
  26.  
  27. /* See www-authenticate.h for documentation */
  28. nserror http_parse_www_authenticate(const char *header_value,
  29.                 http_www_authenticate **result)
  30. {
  31.         const char *pos = header_value;
  32.         http_challenge *first = NULL;
  33.         http_challenge *list = NULL;
  34.         http_www_authenticate *wa;
  35.         nserror error;
  36.  
  37.         /* 1#challenge */
  38.  
  39.         http__skip_LWS(&pos);
  40.  
  41.         error = http__parse_challenge(&pos, &first);
  42.         if (error != NSERROR_OK)
  43.                 return error;
  44.  
  45.         http__skip_LWS(&pos);
  46.  
  47.         if (*pos == ',') {
  48.                 error = http__item_list_parse(&pos,
  49.                                 http__parse_challenge, first, &list);
  50.                 if (error != NSERROR_OK && error != NSERROR_NOT_FOUND)
  51.                         return error;
  52.         } else {
  53.                 list = first;
  54.         }
  55.  
  56.         wa = malloc(sizeof(*wa));
  57.         if (wa == NULL) {
  58.                 http_challenge_list_destroy(list);
  59.                 return NSERROR_NOMEM;
  60.         }
  61.  
  62.         wa->challenges = list;
  63.  
  64.         *result = wa;
  65.  
  66.         return NSERROR_OK;
  67. }
  68.  
  69. /* See www-authenticate.h for documentation */
  70. void http_www_authenticate_destroy(http_www_authenticate *victim)
  71. {
  72.         http_challenge_list_destroy(victim->challenges);
  73.         free(victim);
  74. }
  75.  
  76.