~thomas-voss/location-service/fix-1347887

« back to all changes in this revision

Viewing changes to tests/mongoose.h

This MP consolidates multiple related changes together, with the goal of:

(1.) Make the service instance accessible via a cli. Useful for testing scenarios.
(2.) To cut down time-to-first-fix (ttff) by:
  (2.1) Leveraging SUPL and other supplementary data downloaded over ordinary data connections.
  (2.2) Enabling network-based positioning providers to acquire fast position estimates.

In more detail:

* Added tests for daemon and cli.
* Unified daemon and cli header and implementation files.
* Add a command-line interface to the service.
* Split up provider selection policy to rely on an interface ProviderEnumerator to ease in testing.
* Trimmed down on types.
* Removed connectivity API draft to prepare for simpler approach.
* Refactored includes.
* Added a configuration option to handle cell and wifi ID reporting.
* Add a mock for a connectivity API exposed to providers and reporters.
* Add units for connectivity api.
* Refactor cell class into namespace radio. Fixes: 1226204, 1248973, 1281817

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// Copyright (c) 2004-2013 Sergey Lyubka <valenok@gmail.com>
 
2
// Copyright (c) 2013-2014 Cesanta Software Limited
 
3
// All rights reserved
 
4
//
 
5
// This library is dual-licensed: you can redistribute it and/or modify
 
6
// it under the terms of the GNU General Public License version 2 as
 
7
// published by the Free Software Foundation. For the terms of this
 
8
// license, see <http://www.gnu.org/licenses/>.
 
9
//
 
10
// You are free to use this library under the terms of the GNU General
 
11
// Public License, but WITHOUT ANY WARRANTY; without even the implied
 
12
// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 
13
// See the GNU General Public License for more details.
 
14
//
 
15
// Alternatively, you can license this library under a commercial
 
16
// license, as set out in <http://cesanta.com/>.
 
17
//
 
18
// NOTE: Detailed API documentation is at http://cesanta.com/#docs
 
19
 
 
20
#ifndef MONGOOSE_HEADER_INCLUDED
 
21
#define  MONGOOSE_HEADER_INCLUDED
 
22
 
 
23
#define MONGOOSE_VERSION "5.4"
 
24
 
 
25
#include <stdio.h>      // required for FILE
 
26
#include <stddef.h>     // required for size_t
 
27
 
 
28
#ifdef __cplusplus
 
29
extern "C" {
 
30
#endif // __cplusplus
 
31
 
 
32
// This structure contains information about HTTP request.
 
33
struct mg_connection {
 
34
  const char *request_method; // "GET", "POST", etc
 
35
  const char *uri;            // URL-decoded URI
 
36
  const char *http_version;   // E.g. "1.0", "1.1"
 
37
  const char *query_string;   // URL part after '?', not including '?', or NULL
 
38
 
 
39
  char remote_ip[48];         // Max IPv6 string length is 45 characters
 
40
  char local_ip[48];          // Local IP address
 
41
  unsigned short remote_port; // Client's port
 
42
  unsigned short local_port;  // Local port number
 
43
 
 
44
  int num_headers;            // Number of HTTP headers
 
45
  struct mg_header {
 
46
    const char *name;         // HTTP header name
 
47
    const char *value;        // HTTP header value
 
48
  } http_headers[30];
 
49
 
 
50
  char *content;              // POST (or websocket message) data, or NULL
 
51
  size_t content_len;         // Data length
 
52
 
 
53
  int is_websocket;           // Connection is a websocket connection
 
54
  int status_code;            // HTTP status code for HTTP error handler
 
55
  int wsbits;                 // First byte of the websocket frame
 
56
  void *server_param;         // Parameter passed to mg_add_uri_handler()
 
57
  void *connection_param;     // Placeholder for connection-specific data
 
58
  void *callback_param;       // Needed by mg_iterate_over_connections()
 
59
};
 
60
 
 
61
struct mg_server; // Opaque structure describing server instance
 
62
enum mg_result { MG_FALSE, MG_TRUE, MG_MORE };
 
63
enum mg_event {
 
64
  MG_POLL = 100,  // Callback return value is ignored
 
65
  MG_CONNECT,     // If callback returns MG_FALSE, connect fails
 
66
  MG_AUTH,        // If callback returns MG_FALSE, authentication fails
 
67
  MG_REQUEST,     // If callback returns MG_FALSE, Mongoose continues with req
 
68
  MG_REPLY,       // If callback returns MG_FALSE, Mongoose closes connection
 
69
  MG_CLOSE,       // Connection is closed, callback return value is ignored
 
70
  MG_WS_HANDSHAKE,  // New websocket connection, handshake request
 
71
  MG_HTTP_ERROR   // If callback returns MG_FALSE, Mongoose continues with err
 
72
};
 
73
typedef int (*mg_handler_t)(struct mg_connection *, enum mg_event);
 
74
 
 
75
// Websocket opcodes, from http://tools.ietf.org/html/rfc6455
 
76
enum {
 
77
  WEBSOCKET_OPCODE_CONTINUATION = 0x0,
 
78
  WEBSOCKET_OPCODE_TEXT = 0x1,
 
79
  WEBSOCKET_OPCODE_BINARY = 0x2,
 
80
  WEBSOCKET_OPCODE_CONNECTION_CLOSE = 0x8,
 
81
  WEBSOCKET_OPCODE_PING = 0x9,
 
82
  WEBSOCKET_OPCODE_PONG = 0xa
 
83
};
 
84
 
 
85
// Server management functions
 
86
struct mg_server *mg_create_server(void *server_param, mg_handler_t handler);
 
87
void mg_destroy_server(struct mg_server **);
 
88
const char *mg_set_option(struct mg_server *, const char *opt, const char *val);
 
89
int mg_poll_server(struct mg_server *, int milliseconds);
 
90
const char **mg_get_valid_option_names(void);
 
91
const char *mg_get_option(const struct mg_server *server, const char *name);
 
92
void mg_set_listening_socket(struct mg_server *, int sock);
 
93
int mg_get_listening_socket(struct mg_server *);
 
94
void mg_iterate_over_connections(struct mg_server *, mg_handler_t, void *);
 
95
void mg_wakeup_server(struct mg_server *);
 
96
void mg_wakeup_server_ex(struct mg_server *, mg_handler_t, const char *, ...);
 
97
struct mg_connection *mg_connect(struct mg_server *, const char *, int, int);
 
98
 
 
99
// Connection management functions
 
100
void mg_send_status(struct mg_connection *, int status_code);
 
101
void mg_send_header(struct mg_connection *, const char *name, const char *val);
 
102
void mg_send_data(struct mg_connection *, const void *data, int data_len);
 
103
void mg_printf_data(struct mg_connection *, const char *format, ...);
 
104
 
 
105
int mg_websocket_write(struct mg_connection *, int opcode,
 
106
                       const char *data, size_t data_len);
 
107
int mg_websocket_printf(struct mg_connection* conn, int opcode,
 
108
                        const char *fmt, ...);
 
109
 
 
110
// Deprecated in favor of mg_send_* interface
 
111
int mg_write(struct mg_connection *, const void *buf, int len);
 
112
int mg_printf(struct mg_connection *conn, const char *fmt, ...);
 
113
 
 
114
const char *mg_get_header(const struct mg_connection *, const char *name);
 
115
const char *mg_get_mime_type(const char *name, const char *default_mime_type);
 
116
int mg_get_var(const struct mg_connection *conn, const char *var_name,
 
117
               char *buf, size_t buf_len);
 
118
int mg_parse_header(const char *hdr, const char *var_name, char *buf, size_t);
 
119
int mg_parse_multipart(const char *buf, int buf_len,
 
120
                       char *var_name, int var_name_len,
 
121
                       char *file_name, int file_name_len,
 
122
                       const char **data, int *data_len);
 
123
 
 
124
// Utility functions
 
125
void *mg_start_thread(void *(*func)(void *), void *param);
 
126
char *mg_md5(char buf[33], ...);
 
127
int mg_authorize_digest(struct mg_connection *c, FILE *fp);
 
128
int mg_url_encode(const char *src, size_t s_len, char *dst, size_t dst_len);
 
129
int mg_url_decode(const char *src, int src_len, char *dst, int dst_len, int);
 
130
 
 
131
// Templates support
 
132
struct mg_expansion {
 
133
  const char *keyword;
 
134
  void (*handler)(struct mg_connection *);
 
135
};
 
136
void mg_template(struct mg_connection *, const char *text,
 
137
                 struct mg_expansion *expansions);
 
138
 
 
139
 
 
140
#ifdef __cplusplus
 
141
}
 
142
#endif // __cplusplus
 
143
 
 
144
#endif // MONGOOSE_HEADER_INCLUDED