Add misc/url.* with m_url_(un)escaped_form
[libquvi.git] / src / api / http_metainfo_get.c
blob19243090925c7ea775124dcccd5b7ee4ca9ee666
1 /* libquvi
2 * Copyright (C) 2012 Toni Gundogdu <legatvs@gmail.com>
4 * This file is part of libquvi <http://quvi.sourceforge.net/>.
6 * This library is free software: you can redistribute it and/or
7 * modify it under the terms of the GNU Affero General Public
8 * License as published by the Free Software Foundation, either
9 * version 3 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Affero General Public License for more details.
16 * You should have received a copy of the GNU Affero General
17 * Public License along with this library. If not, see
18 * <http://www.gnu.org/licenses/>.
21 /** @file http_metainfo_get.c */
23 #include "config.h"
25 #include <glib.h>
27 #include "quvi.h"
28 /* -- */
29 #include "_quvi_s.h"
30 #include "_quvi_http_metainfo_s.h"
32 static QuviError _http_metainfo_get(_quvi_http_metainfo_t v,
33 QuviHTTPMetaInfoProperty n, ...)
35 QuviError rc;
36 gdouble *dp;
37 va_list arg;
38 gchar **sp;
39 gint type;
41 va_start(arg, n);
42 type = QUVI_HTTP_METAINFO_PROPERTY_TYPE_MASK & (gint) n;
44 dp = NULL;
45 sp = NULL;
47 rc = QUVI_OK;
49 switch (type)
51 case QUVI_HTTP_METAINFO_PROPERTY_TYPE_STRING:
52 sp = va_arg(arg, gchar**);
53 if (sp == NULL)
54 rc = QUVI_ERROR_INVALID_ARG;
55 break;
56 case QUVI_HTTP_METAINFO_PROPERTY_TYPE_DOUBLE:
57 dp = va_arg(arg, gdouble*);
58 if (dp == NULL)
59 rc = QUVI_ERROR_INVALID_ARG;
60 break;
61 default:
62 rc = QUVI_ERROR_INVALID_ARG;
63 break;
65 va_end(arg);
67 if (rc != QUVI_OK)
68 return (rc);
70 switch (n)
72 case QUVI_HTTP_METAINFO_PROPERTY_FILE_EXTENSION:
73 *sp = v->file_ext->str;
74 break;
75 case QUVI_HTTP_METAINFO_PROPERTY_LENGTH_BYTES:
76 *dp = v->length_bytes;
77 break;
78 case QUVI_HTTP_METAINFO_PROPERTY_CONTENT_TYPE:
79 *sp = v->content_type->str;
80 break;
81 default:
82 rc = QUVI_ERROR_INVALID_ARG;
83 break;
85 return (rc);
88 /** @brief Return a HTTP meta-info property
89 @sa @ref http_metainfo
90 @ingroup http_metainfo
92 void quvi_http_metainfo_get(quvi_http_metainfo_t handle,
93 QuviHTTPMetaInfoProperty property, ...)
95 _quvi_http_metainfo_t v;
96 va_list arg;
97 gpointer p;
98 _quvi_t q;
100 /* If G_DISABLE_CHECKS is defined then the check is not performed. */
101 g_return_if_fail(handle != NULL);
103 va_start(arg, property);
104 p = va_arg(arg, gpointer);
105 va_end(arg);
107 v = (_quvi_http_metainfo_t) handle;
108 q = v->handle.quvi;
110 q->status.rc = _http_metainfo_get(v, property, p);
113 /* vim: set ts=2 sw=2 tw=72 expandtab: */