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.h"
  22.  
  23. #include "utils/http/generics.h"
  24. #include "utils/http/parameter_internal.h"
  25. #include "utils/http/primitives.h"
  26.  
  27. /* See content-disposition.h for documentation */
  28. nserror http_parse_content_disposition(const char *header_value,
  29.                 http_content_disposition **result)
  30. {
  31.         const char *pos = header_value;
  32.         lwc_string *mtype;
  33.         http_parameter *params = NULL;
  34.         http_content_disposition *cd;
  35.         nserror error;
  36.  
  37.         /* disposition-type *( ";" parameter ) */
  38.  
  39.         http__skip_LWS(&pos);
  40.  
  41.         error = http__parse_token(&pos, &mtype);
  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_parameter, NULL, &params);
  50.                 if (error != NSERROR_OK && error != NSERROR_NOT_FOUND) {
  51.                         lwc_string_unref(mtype);
  52.                         return error;
  53.                 }
  54.         }
  55.  
  56.         cd = malloc(sizeof(*cd));
  57.         if (cd == NULL) {
  58.                 http_parameter_list_destroy(params);
  59.                 lwc_string_unref(mtype);
  60.                 return NSERROR_NOMEM;
  61.         }
  62.  
  63.         cd->disposition_type = mtype;
  64.         cd->parameters = params;
  65.  
  66.         *result = cd;
  67.  
  68.         return NSERROR_OK;
  69. }
  70.  
  71. /* See content-disposition.h for documentation */
  72. void http_content_disposition_destroy(http_content_disposition *victim)
  73. {
  74.         lwc_string_unref(victim->disposition_type);
  75.         http_parameter_list_destroy(victim->parameters);
  76.         free(victim);
  77. }
  78.  
  79.