1 /* libquvi
2  * Copyright (C) 2012  Toni Gundogdu <legatvs@gmail.com>
3  *
4  * This file is part of libquvi <http://quvi.sourceforge.net/>.
5  *
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.
10  *
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.
15  *
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/>.
19  */
20 
21 /** @file http_metainfo_get.c */
22 
23 #include "config.h"
24 
25 #include <glib.h>
26 
27 #include "quvi.h"
28 /* -- */
29 #include "_quvi_s.h"
30 #include "_quvi_http_metainfo_s.h"
31 
_http_metainfo_get(_quvi_http_metainfo_t v,QuviHTTPMetaInfoProperty n,...)32 static QuviError _http_metainfo_get(_quvi_http_metainfo_t v,
33                                     QuviHTTPMetaInfoProperty n, ...)
34 {
35   QuviError rc;
36   gdouble *dp;
37   va_list arg;
38   gchar **sp;
39   gint type;
40 
41   va_start(arg, n);
42   type = QUVI_HTTP_METAINFO_PROPERTY_TYPE_MASK & (gint) n;
43 
44   dp = NULL;
45   sp = NULL;
46 
47   rc = QUVI_OK;
48 
49   switch (type)
50     {
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;
64     }
65   va_end(arg);
66 
67   if (rc != QUVI_OK)
68     return (rc);
69 
70   switch (n)
71     {
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;
84     }
85   return (rc);
86 }
87 
88 /** @brief Return a HTTP meta-info property
89 @sa @ref http_metainfo
90 @ingroup http_metainfo
91 */
quvi_http_metainfo_get(quvi_http_metainfo_t handle,QuviHTTPMetaInfoProperty property,...)92 void quvi_http_metainfo_get(quvi_http_metainfo_t handle,
93                             QuviHTTPMetaInfoProperty property, ...)
94 {
95   _quvi_http_metainfo_t v;
96   va_list arg;
97   gpointer p;
98   _quvi_t q;
99 
100   /* If G_DISABLE_CHECKS is defined then the check is not performed. */
101   g_return_if_fail(handle != NULL);
102 
103   va_start(arg, property);
104   p = va_arg(arg, gpointer);
105   va_end(arg);
106 
107   v = (_quvi_http_metainfo_t) handle;
108   q = v->handle.quvi;
109 
110   q->status.rc = _http_metainfo_get(v, property, p);
111 }
112 
113 /* vim: set ts=2 sw=2 tw=72 expandtab: */
114