This file is indexed.

/usr/include/libxr/xr-http.h is in libxr1-dev 1.0-2.1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
/* 
 * Copyright 2006-2008 Ondrej Jirman <ondrej.jirman@zonio.net>
 * 
 * This file is part of libxr.
 *
 * Libxr is free software: you can redistribute it and/or modify it under the
 * terms of the GNU Lesser General Public License as published by the Free
 * Software Foundation, either version 2 of the License, or (at your option) any
 * later version.
 *
 * Libxr is distributed in the hope that it will be useful, but WITHOUT ANY
 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
 * A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
 * details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with libxr.  If not, see <http://www.gnu.org/licenses/>.
 */

#ifndef __XR_HTTP_H__
#define __XR_HTTP_H__

#include <glib.h>
#include <openssl/bio.h>

/** @file xr-http.h
 *
 * HTTP Transport
 *
 * xr_http object exists as long as HTTP connection exists. It is used to server
 * multiple requests/responses.
 *
 * xr_http object is created using xr_http_new(bio) and then user is supposed to
 * call xr_http_read_header() that will receive and parse HTTP header. After
 * that user can call one of xr_http_read() functions to read body of the HTTP
 * request or response.
 *
 * When request is received, user must generate response using
 * xr_http_write_header() and optionally body using xr_http_write(). Header
 * values can be set using xr_http_setup_request() or xr_http_setup_response()
 * and xr_http_set_header() functions.
 */

/** Opaque HTTP object.
 */
typedef struct _xr_http xr_http;

/** Message type (request/response).
 */
typedef enum {
  XR_HTTP_NONE,
  XR_HTTP_REQUEST,
  XR_HTTP_RESPONSE
} xr_http_message_type;

#define XR_HTTP_ERROR xr_http_error_quark()

typedef enum
{
  XR_HTTP_ERROR_FAILED = 1
} XRHttpError;

G_BEGIN_DECLS

/** Initialize HTTP transport. Called internally from xr_init().
 */
void xr_http_init();

/** Create new HTTP transport object.
 * 
 * @param bio OpenSSL BIO object used as underlaying transport.
 * 
 * @return New HTTP transport object.
 */
xr_http* xr_http_new(BIO* bio);

/** Destroy HTTP transport object.
 * 
 * @param http HTTP transport object.
 */
void xr_http_free(xr_http* http);

/* receive API */

/** Read HTTP message header.
 * 
 * @param http HTTP transport object.
 * @param err Error object.
 * 
 * @return TRUE on success, FALSE on error.
 */
gboolean xr_http_read_header(xr_http* http, GError** err);

/** Get specific HTTP header from incomming messages by its name.
 * 
 * @param http HTTP transport object.
 * @param name Case insensitive header name (e.g. Content-Type).
 * 
 * @return Header value.
 */
const char* xr_http_get_header(xr_http* http, const char* name);

/** Set Authorization: Basic header.
 * 
 * @param http HTTP transport object.
 * @param username Username.
 * @param password Password.
 */
void xr_http_set_basic_auth(xr_http* http, const char* username, const char* password);

/** Decode Authorization header.
 * 
 * @param http HTTP transport object.
 * @param username Username will be stored there.
 * @param password Password will be stored there.
 * 
 * @return TRUE if Authorization header was set and valid and username/password
 * was decoded, FALSE otherwise. Caller must free username and password if TRUE
 * was returned.
 */
gboolean xr_http_get_basic_auth(xr_http* http, char** username, char** password);

/** Get HTTP method.
 * 
 * @param http HTTP transport object.
 * 
 * @return Method name (GET/POST/...).
 */
const char* xr_http_get_method(xr_http* http);

/** Get HTTP response code.
 * 
 * @param http HTTP transport object.
 * 
 * @return 200 on success.
 */
int xr_http_get_code(xr_http* http);

/** Get resource (only if xr_http_get_message_type() == XR_HTTP_REQUEST).
 * 
 * @param http HTTP transport object.
 * 
 * @return Resource string (/blah/blah?test).
 */
const char* xr_http_get_resource(xr_http* http);

/** Get HTTP request version.
 * 
 * @param http HTTP transport object.
 * 
 * @return 0 if '1.0', 1 if '1.1'.
 */
int xr_http_get_version(xr_http* http);

/** Get message type.
 * 
 * @param http HTTP transport object.
 * 
 * @return XR_HTTP_REQUEST, XR_HTTP_RESPONSE or XR_HTTP_NONE if header was not
 *   read yet.
 */
xr_http_message_type xr_http_get_message_type(xr_http* http);

/** Get length of the message body (Content-Length header value).
 *
 * This function may return -1 if Content-Length was not specified.
 * 
 * @param http HTTP transport object.
 * 
 * @return Message body length.
 */
gssize xr_http_get_message_length(xr_http* http);

/** Read HTTP message body.
 * 
 * @param http HTTP transport object.
 * @param buffer Target buffer.
 * @param length Target buffer length.
 * @param err Error object.
 * 
 * @return -1 on error, actual length that was read.
 */
gssize xr_http_read(xr_http* http, char* buffer, gsize length, GError** err);

/** Read whole message body into a GString object.
 * 
 * @param http HTTP transport object.
 * @param err Error object.
 * 
 * @return GString object with returned data or NULL on error.
 */
GString* xr_http_read_all(xr_http* http, GError** err);

/* transmit API */

/** Set HTTP header for outgoing message.
 * 
 * @param http HTTP transport object.
 * @param name Case insensitive header name (e.g. Content-Type).
 * @param value Header value.
 */
void xr_http_set_header(xr_http* http, const char* name, const char* value);

/** Set outgoing message type.
 * 
 * @param http HTTP transport object.
 * @param type XR_HTTP_REQUEST or XR_HTTP_RESPONSE.
 */
void xr_http_set_message_type(xr_http* http, xr_http_message_type type);

/** Set Content-Length header for outgoing message.
 * 
 * @param http HTTP transport object.
 * @param length Mesasge body length.
 */
void xr_http_set_message_length(xr_http* http, gsize length);

/** Setup outgoing request.
 * 
 * @param http HTTP transport object.
 * @param method HTTP method name (GET/POST).
 * @param resource HTTP resource value.
 * @param host Host header value.
 */
void xr_http_setup_request(xr_http* http, const char* method, const char* resource, const char* host);

/** Setup outgoing response.
 * 
 * @param http HTTP transport object.
 * @param code HTTP response code (200, 404, etc.).
 */
void xr_http_setup_response(xr_http* http, int code);

/** Write outgoing message header.
 *
 * You should call xr_http_setup_*() and xr_http_set_message_length() functions
 * before calling this.
 * 
 * @param http HTTP transport object.
 * @param err Error object.
 * 
 * @return TRUE on success, FALSE on error.
 */
gboolean xr_http_write_header(xr_http* http, GError** err);

/** Write response body.
 *
 * This function will automatically call xr_http_write_header() if it was not
 * called before.
 *
 * This method may be called multiple times to write response iteratively.
 * 
 * @param http HTTP transport object.
 * @param buffer Source buffer.
 * @param length Data length.
 * @param err Error object.
 * 
 * @return TRUE on success, FALSE on error.
 */
gboolean xr_http_write(xr_http* http, const char* buffer, gsize length, GError** err);

/** Complete message.
 *
 * Must be called after body is written by possibly multiple xr_http_write()
 * calls or directly after xr_http_write_header().
 * 
 * @param http HTTP transport object.
 * @param err Error object.
 * 
 * @return TRUE on success, FALSE on error.
 */
gboolean xr_http_write_complete(xr_http* http, GError** err);

/** Write whole message body at once from the GString.
 * 
 * @param http HTTP transport object. 
 * @param buffer Source buffer.
 * @param length Data length. (It may be -1 if buffer contains zero-terminated string.)
 * @param err Error object.
 * 
 * @return TRUE on success, FALSE on error.
 */
gboolean xr_http_write_all(xr_http* http, const char* buffer, gssize length, GError** err);

/** Check if object is ready to receive or send message.
 * 
 * @param http HTTP transport object. 
 * 
 * @return TRUE if ready.
 */
gboolean xr_http_is_ready(xr_http* http);

/** Check if object has pending request to be read within given time.
 * 
 * @param http HTTP transport object. 
 * @param timeout The timeout value (in second) for waiting incoming request.
 * 
 * @return TRUE if ready.
 */
gboolean xr_http_has_pending_request(xr_http* http, time_t timeout);

GQuark xr_http_error_quark();

G_END_DECLS

#endif