1 #ifndef __GSK_HTTP_RESPONSE_H_
2 #define __GSK_HTTP_RESPONSE_H_
3 
4 #ifndef __GSK_HTTP_HEADER_H_
5 #include "gskhttpheader.h"
6 #endif
7 
8 G_BEGIN_DECLS
9 
10 typedef struct _GskHttpResponseClass GskHttpResponseClass;
11 typedef struct _GskHttpResponse GskHttpResponse;
12 
13 #define GSK_TYPE_HTTP_RESPONSE             (gsk_http_response_get_type ())
14 #define GSK_HTTP_RESPONSE(obj)             (G_TYPE_CHECK_INSTANCE_CAST ((obj), GSK_TYPE_HTTP_RESPONSE, GskHttpResponse))
15 #define GSK_HTTP_RESPONSE_CLASS(klass)     (G_TYPE_CHECK_CLASS_CAST ((klass), GSK_TYPE_HTTP_RESPONSE, GskHttpResponseClass))
16 #define GSK_HTTP_RESPONSE_GET_CLASS(obj)   (G_TYPE_INSTANCE_GET_CLASS ((obj), GSK_TYPE_HTTP_RESPONSE, GskHttpResponseClass))
17 #define GSK_IS_HTTP_RESPONSE(obj)          (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GSK_TYPE_HTTP_RESPONSE))
18 #define GSK_IS_HTTP_RESPONSE_CLASS(klass)  (G_TYPE_CHECK_CLASS_TYPE ((klass), GSK_TYPE_HTTP_RESPONSE))
19 
20 struct _GskHttpResponseClass
21 {
22   GskHttpHeaderClass base_class;
23 };
24 struct _GskHttpResponse
25 {
26   GskHttpHeader base_instance;
27 
28   GskHttpStatus             status_code;
29   int                       age;                  /* Age */
30 
31   /* initially allowed_verbs == 0;
32    * since it is an error not to allow any verbs;
33    * otherwise it is a bitwise-OR: (1 << GSK_HTTP_VERB_*)
34    */
35   guint                     allowed_verbs;
36 
37   GskHttpResponseCacheDirective *cache_control;        /* Cache-Control */
38 
39   unsigned                  has_md5sum : 1;
40   unsigned char             md5sum[16];           /* Content-MD5 (14.15) */
41 
42   /* List of Set-Cookie: headers. */
43   GSList                   *set_cookies;
44 
45   /* The `Location' to redirect to. */
46   char                     *location;
47 
48   /* may be set to ((time_t) -1) to omit them. */
49   glong                     expires;
50   char                     *expires_str;
51 
52   /* The ``Entity-Tag'', cf RFC 2616, Sections 14.24, 14.26, 14.44. */
53   char                     *etag;
54 
55   GskHttpAuthenticate      *proxy_authenticate;
56 
57   /* This is the WWW-Authenticate: header line. */
58   GskHttpAuthenticate      *authenticate;
59 
60   /* If `retry_after_relative', the retry_after is the number
61    * of seconds to wait before retrying; otherwise,
62    * it is a unix-time indicting when to retry.
63    *
64    * (Corresponding to the `Retry-After' header, cf RFC 2616, 14.37)
65    */
66   guint                     has_retry_after : 1;
67   gboolean                  retry_after_relative;
68   glong                     retry_after;
69 
70   /* The Last-Modified header.  If != -1, this is the unix-time
71    * the message-body-contents were last modified. (RFC 2616, section 14.29)
72    */
73   glong                     last_modified;
74 
75   char                     *server;        /* The Server: header */
76 };
77 
78 /* Responses. */
79 GskHttpResponse *gsk_http_response_new_blank    (void);
80 
81 /* Redirects should be accompanied by an HTML body saying the URL. */
82 GskHttpResponse *gsk_http_response_new_redirect (const char    *location);
83 
84 GskHttpResponse *gsk_http_response_from_request (GskHttpRequest *request,
85 						 GskHttpStatus   status_code,
86 						 gint64          length);
87 
88 gboolean   gsk_http_response_process_first_line (GskHttpResponse *response,
89 				                 const char      *line);
90 
91 void       gsk_http_response_set_retry_after   (GskHttpResponse *response,
92                                                 gboolean         is_relative,
93                                                 glong            time);
94 void       gsk_http_response_set_no_retry_after(GskHttpResponse *response);
95 
96 void       gsk_http_response_set_authenticate (GskHttpResponse *response,
97 					       gboolean         is_proxy_auth,
98 					       GskHttpAuthenticate *auth);
99 GskHttpAuthenticate*
100            gsk_http_response_peek_authenticate(GskHttpResponse *response,
101 				               gboolean         is_proxy_auth);
102 
103 /* --- setting / getting --- */
104 gboolean   gsk_http_response_has_content_body   (GskHttpResponse *response,
105                                                  GskHttpRequest  *request);
106 void       gsk_http_response_set_cache_control(
107 					    GskHttpResponse *response,
108 				            GskHttpResponseCacheDirective *directive);
109 #define    gsk_http_response_set_status_code(response, status)	\
110   G_STMT_START{ GSK_HTTP_RESPONSE(response)->status_code = (status); G_STMT_END
111 #define    gsk_http_response_get_status_code(response) \
112                (GSK_HTTP_RESPONSE(response)->status_code)
113 void       gsk_http_response_set_allowed_verbs  (GskHttpResponse *response,
114                                                  guint            allowed);
115 #define gsk_http_response_get_allowed_verbs(header)		              \
116   (GSK_HTTP_RESPONSE(header)->allowed_verbs)
117 /* md5sum may be NULL to unset it */
118 void             gsk_http_response_set_md5      (GskHttpResponse *response,
119                                                  const guint8    *md5sum);
120 const guint8    *gsk_http_response_peek_md5     (GskHttpResponse *response);
121 #define gsk_http_response_set_location(response, location)		      \
122   g_object_set (GSK_HTTP_RESPONSE(response), "location", (const char *) (location), NULL)
123 #define gsk_http_response_peek_location(response)		              \
124   (GSK_HTTP_RESPONSE(response)->location)
125 #define gsk_http_response_set_etag(response, etag)			      \
126   g_object_set (GSK_HTTP_RESPONSE(response), "etag", (const char *)(etag), NULL)
127 #define gsk_http_response_peek_etag(response)				      \
128   (GSK_HTTP_RESPONSE(response)->etag)
129 #define gsk_http_response_set_server(response, server)			      \
130   g_object_set (GSK_HTTP_RESPONSE(response), "server", (const char *) (server), NULL)
131 #define gsk_http_response_peek_server(response)				      \
132   (GSK_HTTP_RESPONSE(response)->server)
133 #define gsk_http_response_set_expires(response, expires)	              \
134   g_object_set (GSK_HTTP_RESPONSE(response), "expires", (long) (expires), NULL)
135 #define gsk_http_response_get_expires(response)				      \
136   (GSK_HTTP_RESPONSE(response)->expires)
137 #define gsk_http_response_peek_cache_control(response)	                      \
138 	(GSK_HTTP_RESPONSE(response)->cache_control)
139 #define gsk_http_response_set_age(response, age)	              	      \
140   g_object_set (GSK_HTTP_RESPONSE(response), "age", (long) (age), NULL)
141 #define gsk_http_response_get_age(response)		                      \
142 	(GSK_HTTP_RESPONSE(response)->age)
143 #define gsk_http_response_set_last_modified(response, last_modified)	      \
144   g_object_set (GSK_HTTP_RESPONSE(response), "last-modified", (long) (last_modified), NULL)
145 #define gsk_http_response_get_last_modified(response)		              \
146   (GSK_HTTP_RESPONSE(response)->last_modified)
147 
148 #define gsk_http_response_set_content_type gsk_http_header_set_content_type
149 #define gsk_http_response_get_content_type gsk_http_header_get_content_type
150 #define gsk_http_response_set_content_subtype gsk_http_header_set_content_subtype
151 #define gsk_http_response_get_content_subtype gsk_http_header_get_content_subtype
152 
153 G_END_DECLS
154 
155 #endif
156