~ubuntu-branches/ubuntu/trusty/argyll/trusty-proposed

« back to all changes in this revision

Viewing changes to spectro/mongoose.h

  • Committer: Package Import Robot
  • Author(s): Artur Rona
  • Date: 2014-02-12 00:35:39 UTC
  • mfrom: (13.1.24 sid)
  • Revision ID: package-import@ubuntu.com-20140212003539-24tautzlitsiz61w
Tags: 1.5.1-5ubuntu1
* Merge from Debian unstable. (LP: #1275572) Remaining changes:
  - debian/control:
    + Build-depend on libtiff-dev rather than libtiff4-dev.
  - debian/control, debian/patches/06_fix_udev_rule.patch:
    + Fix udev rules to actually work; ENV{ACL_MANAGE} has
      stopped working ages ago, and with logind it's now the
      "uaccess" tag. Dropping also consolekit from Recommends.
  - debian/patches/drop-usb-db.patch:
    + Use hwdb builtin, instead of the obsolete usb-db
      in the udev rules.
* debian/patches/05_ftbfs-underlinkage.diff:
  - Dropped change, no needed anymore.
* Refresh the patches.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
// Copyright (c) 2004-2011 Sergey Lyubka
 
1
// Copyright (c) 2004-2012 Sergey Lyubka
2
2
//
3
3
// Permission is hereby granted, free of charge, to any person obtaining a copy
4
4
// of this software and associated documentation files (the "Software"), to deal
21
21
#ifndef MONGOOSE_HEADER_INCLUDED
22
22
#define  MONGOOSE_HEADER_INCLUDED
23
23
 
 
24
#include <stdio.h>
24
25
#include <stddef.h>
25
26
 
26
27
#ifdef __cplusplus
33
34
 
34
35
// This structure contains information about the HTTP request.
35
36
struct mg_request_info {
36
 
  void *user_data;       // User-defined pointer passed to mg_start()
37
37
  char *request_method;  // "GET", "POST", etc
38
38
  char *uri;             // URL-decoded URI
39
39
  char *http_version;    // E.g. "1.0", "1.1"
40
40
  char *query_string;    // URL part after '?' (not including '?') or NULL
41
41
  char *remote_user;     // Authenticated user, or NULL if no auth used
42
 
  char *log_message;     // Mongoose error log message, MG_EVENT_LOG only
43
42
  long remote_ip;        // Client's IP address
44
43
  int remote_port;       // Client's port
45
 
  int status_code;       // HTTP reply status code, e.g. 200
46
44
  int is_ssl;            // 1 if SSL-ed, 0 if not
47
45
  int num_headers;       // Number of headers
48
46
  struct mg_header {
51
49
  } http_headers[64];    // Maximum 64 headers
52
50
};
53
51
 
 
52
 
54
53
// Various events on which user-defined function is called by Mongoose.
55
54
enum mg_event {
56
 
  MG_NEW_REQUEST,   // New HTTP request has arrived from the client
57
 
  MG_HTTP_ERROR,    // HTTP error must be returned to the client
58
 
  MG_EVENT_LOG,     // Mongoose logs an event, request_info.log_message
59
 
  MG_INIT_SSL,      // Mongoose initializes SSL. Instead of mg_connection *,
60
 
                    // SSL context is passed to the callback function.
61
 
  MG_REQUEST_COMPLETE  // Mongoose has finished handling the request
 
55
  MG_NEW_REQUEST,       // New HTTP request has arrived from the client
 
56
  MG_REQUEST_COMPLETE,  // Mongoose has finished handling the request
 
57
  MG_HTTP_ERROR,        // HTTP error must be returned to the client
 
58
  MG_EVENT_LOG,         // Mongoose logs an event, request_info.log_message
 
59
  MG_INIT_SSL,          // SSL initialization, sent before certificate setup
 
60
  MG_WEBSOCKET_CONNECT, // Sent on HTTP connect, before websocket handshake.
 
61
                        // If user callback returns NULL, then mongoose proceeds
 
62
                        // with handshake, otherwise it closes the connection.
 
63
  MG_WEBSOCKET_READY,   // Handshake has been successfully completed.
 
64
  MG_WEBSOCKET_MESSAGE, // Incoming message from the client
 
65
  MG_WEBSOCKET_CLOSE,   // Client has closed the connection
62
66
};
63
67
 
 
68
 
64
69
// Prototype for the user-defined function. Mongoose calls this function
65
70
// on every MG_* event.
66
71
//
68
73
//   event: which event has been triggered.
69
74
//   conn: opaque connection handler. Could be used to read, write data to the
70
75
//         client, etc. See functions below that have "mg_connection *" arg.
71
 
//   request_info: Information about HTTP request.
72
76
//
73
77
// Return:
74
78
//   If handler returns non-NULL, that means that handler has processed the
77
81
//   If handler returns NULL, that means that handler has not processed
78
82
//   the request. Handler must not send any data to the client in this case.
79
83
//   Mongoose proceeds with request handling as if nothing happened.
80
 
typedef void * (*mg_callback_t)(enum mg_event event,
81
 
                                struct mg_connection *conn,
82
 
                                const struct mg_request_info *request_info);
 
84
typedef void *(*mg_callback_t)(enum mg_event event, struct mg_connection *conn);
83
85
 
84
86
 
85
87
// Start web server.
151
153
                             const char *user,
152
154
                             const char *password);
153
155
 
 
156
 
 
157
// Return information associated with the request.
 
158
// These functions always succeed.
 
159
const struct mg_request_info *mg_get_request_info(const struct mg_connection *);
 
160
void *mg_get_user_data(struct mg_connection *);
 
161
const char *mg_get_log_message(const struct mg_connection *);
 
162
int mg_get_reply_status_code(const struct mg_connection *);
 
163
void *mg_get_ssl_context(const struct mg_connection *);
 
164
 
 
165
 
154
166
// Send data to the client.
 
167
// Return:
 
168
//  0   when the connection has been closed
 
169
//  -1  on error
 
170
//  number of bytes written on success
155
171
int mg_write(struct mg_connection *, const void *buf, size_t len);
156
172
 
157
173
 
158
174
// Send data to the browser using printf() semantics.
159
175
//
160
176
// Works exactly like mg_write(), but allows to do message formatting.
161
 
// Note that mg_printf() uses internal buffer of size IO_BUF_SIZE
162
 
// (8 Kb by default) as temporary message storage for formatting. Do not
163
 
// print data that is bigger than that, otherwise it will be truncated.
164
 
int mg_printf(struct mg_connection *, const char *fmt, ...)
 
177
// Below are the macros for enabling compiler-specific checks for
 
178
// printf-like arguments.
 
179
 
 
180
#undef PRINTF_FORMAT_STRING
 
181
#if _MSC_VER >= 1400
 
182
#include <sal.h>
 
183
#if _MSC_VER > 1400
 
184
#define PRINTF_FORMAT_STRING(s) _Printf_format_string_ s
 
185
#else
 
186
#define PRINTF_FORMAT_STRING(s) __format_string s
 
187
#endif
 
188
#else
 
189
#define PRINTF_FORMAT_STRING(s) s
 
190
#endif
 
191
 
165
192
#ifdef __GNUC__
166
 
__attribute__((format(printf, 2, 3)))
 
193
#define PRINTF_ARGS(x, y) __attribute__((format(printf, x, y)))
 
194
#else
 
195
#define PRINTF_ARGS(x, y)
167
196
#endif
168
 
;
 
197
 
 
198
int mg_printf(struct mg_connection *,
 
199
              PRINTF_FORMAT_STRING(const char *fmt), ...) PRINTF_ARGS(2, 3);
169
200
 
170
201
 
171
202
// Send contents of the entire file together with HTTP headers.
196
227
//
197
228
// Return:
198
229
//   On success, length of the decoded variable.
199
 
//   On error, -1 (variable not found, or destination buffer is too small).
 
230
//   On error:
 
231
//      -1 (variable not found, or destination buffer is too small).
 
232
//      -2 (destination buffer is NULL or zero length).
200
233
//
201
 
// Destination buffer is guaranteed to be '\0' - terminated. In case of
202
 
// failure, dst[0] == '\0'.
 
234
// Destination buffer is guaranteed to be '\0' - terminated if it is not
 
235
// NULL or zero length. In case of failure, dst[0] == '\0'.
203
236
int mg_get_var(const char *data, size_t data_len,
204
237
               const char *var_name, char *buf, size_t buf_len);
205
238
 
211
244
//
212
245
// Return:
213
246
//   On success, value length.
214
 
//   On error, 0 (either "Cookie:" header is not present at all, or the
 
247
//   On error, -1 (either "Cookie:" header is not present at all, or the
215
248
//   requested parameter is not found, or destination buffer is too small
216
249
//   to hold the value).
217
250
int mg_get_cookie(const struct mg_connection *,
218
251
                  const char *cookie_name, char *buf, size_t buf_len);
219
252
 
220
253
 
 
254
// Connect to the remote web server.
 
255
// Return:
 
256
//   On success, valid pointer to the new connection
 
257
//   On error, NULL
 
258
struct mg_connection *mg_connect(struct mg_context *ctx,
 
259
                                 const char *host, int port, int use_ssl);
 
260
 
 
261
 
 
262
// Close the connection opened by mg_connect().
 
263
void mg_close_connection(struct mg_connection *conn);
 
264
 
 
265
 
 
266
// Download given URL to a given file.
 
267
//   url: URL to download
 
268
//   path: file name where to save the data
 
269
//   request_info: pointer to a structure that will hold parsed reply headers
 
270
//   buf, bul_len: a buffer for the reply headers
 
271
// Return:
 
272
//   On error, NULL
 
273
//   On success, opened file stream to the downloaded contents. The stream
 
274
//   is positioned to the end of the file. It is the user's responsibility
 
275
//   to fclose() the opened file stream.
 
276
FILE *mg_fetch(struct mg_context *ctx, const char *url, const char *path,
 
277
               char *buf, size_t buf_len, struct mg_request_info *request_info);
 
278
 
 
279
 
 
280
// Convenience function -- create detached thread.
 
281
// Return: 0 on success, non-0 on error.
 
282
typedef void * (*mg_thread_func_t)(void *);
 
283
int mg_start_thread(mg_thread_func_t f, void *p);
 
284
 
 
285
 
 
286
// Return builtin mime type for the given file name.
 
287
// For unrecognized extensions, "text/plain" is returned.
 
288
const char *mg_get_builtin_mime_type(const char *file_name);
 
289
 
 
290
 
221
291
// Return Mongoose version.
222
292
const char *mg_version(void);
223
293
 
224
294
 
225
295
// MD5 hash given strings.
226
296
// Buffer 'buf' must be 33 bytes long. Varargs is a NULL terminated list of
227
 
// asciiz strings. When function returns, buf will contain human-readable
 
297
// ASCIIz strings. When function returns, buf will contain human-readable
228
298
// MD5 hash. Example:
229
299
//   char buf[33];
230
300
//   mg_md5(buf, "aa", "bb", NULL);
231
 
void mg_md5(char *buf, ...);
 
301
void mg_md5(char buf[33], ...);
232
302
 
233
303
 
234
304
#ifdef __cplusplus