Mercurial > hg > batmud > maputils
annotate mapsearch.c @ 1815:7ac487466456
Fixes to the block parsing.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Mon, 30 Oct 2017 02:53:05 +0200 |
parents | daf7dcc635d6 |
children | 89829bd4122f |
rev | line source |
---|---|
1784
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1 /* |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
2 * PupuMaps Search WebSockets server |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
3 * Written by Matti 'ccr' Hämäläinen <ccr@tnsp.org> |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
4 * (C) Copyright 2017 Tecnic Software productions (TNSP) |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
5 */ |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
6 #include "th_args.h" |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
7 #include "th_config.h" |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
8 #include "liblocfile.h" |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
9 #include "libmaputils.h" |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
10 #include <libwebsockets.h> |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
11 |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
12 |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
13 /* Default settings etc. constants |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
14 */ |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
15 #define SET_MAX_MAPS 16 // Maximum number of maps allowed to be loaded |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
16 #define SET_MAX_LISTEN 4 // Maximum number of interfaces to listen |
1803
88406bf2d1e5
Up the max hardcoded matches/results limit.
Matti Hamalainen <ccr@tnsp.org>
parents:
1801
diff
changeset
|
17 #define SET_MAX_MATCHES 64 // Maximum number of match results per query |
1784
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
18 |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
19 |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
20 // List of default SSL/TLS ciphers to use/allowed |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
21 #define SET_DEF_CIPHERS \ |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
22 "ECDHE-ECDSA-AES256-GCM-SHA384:" \ |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
23 "ECDHE-RSA-AES256-GCM-SHA384:" \ |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
24 "DHE-RSA-AES256-GCM-SHA384:" \ |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
25 "ECDHE-RSA-AES256-SHA384:" \ |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
26 "HIGH:!aNULL:!eNULL:!EXPORT:" \ |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
27 "!DES:!MD5:!PSK:!RC4:!HMAC_SHA1:" \ |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
28 "!SHA1:!DHE-RSA-AES128-GCM-SHA256:" \ |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
29 "!DHE-RSA-AES128-SHA256:" \ |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
30 "!AES128-GCM-SHA256:" \ |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
31 "!AES128-SHA256:" \ |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
32 "!DHE-RSA-AES256-SHA256:" \ |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
33 "!AES256-GCM-SHA384:" \ |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
34 "!AES256-SHA256" |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
35 |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
36 |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
37 /* Structure that holds information about one listen interface |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
38 */ |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
39 typedef struct |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
40 { |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
41 char *interface; // Listen interface (* = listen all) |
1814
daf7dcc635d6
Improve SSL/TLS support by adding vhost name to the SSL listener spec and set
Matti Hamalainen <ccr@tnsp.org>
parents:
1812
diff
changeset
|
42 char *vhostname; // Vhost name |
1784
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
43 int port; // Port number |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
44 |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
45 BOOL useIPv6; |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
46 BOOL useSSL; // Use SSL/TLS? |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
47 char *sslCertFile, // Certificate file |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
48 *sslKeyFile, // Key file |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
49 *sslCAFile; // CA file |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
50 |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
51 struct lws_vhost *vhost; // LWS vhost info |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
52 } MAPListenerCtx; |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
53 |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
54 |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
55 /* Structure for holding information about one map and its locations |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
56 */ |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
57 typedef struct |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
58 { |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
59 char *mapFilename; // Filename of the map data |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
60 LocFileInfo locFile; // Location file info struct |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
61 MapBlock *map; // Map data, when loaded |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
62 MapLocations loc; // Map locations, when loaded |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
63 } MAPInfoCtx; |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
64 |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
65 |
1789
513c467f3a87
Implement basic search functionality. Has bugs and limitations to be rid of.
Matti Hamalainen <ccr@tnsp.org>
parents:
1786
diff
changeset
|
66 typedef struct |
513c467f3a87
Implement basic search functionality. Has bugs and limitations to be rid of.
Matti Hamalainen <ccr@tnsp.org>
parents:
1786
diff
changeset
|
67 { |
513c467f3a87
Implement basic search functionality. Has bugs and limitations to be rid of.
Matti Hamalainen <ccr@tnsp.org>
parents:
1786
diff
changeset
|
68 char *map; |
513c467f3a87
Implement basic search functionality. Has bugs and limitations to be rid of.
Matti Hamalainen <ccr@tnsp.org>
parents:
1786
diff
changeset
|
69 int mx, my, wx, wy; |
513c467f3a87
Implement basic search functionality. Has bugs and limitations to be rid of.
Matti Hamalainen <ccr@tnsp.org>
parents:
1786
diff
changeset
|
70 double accuracy; |
513c467f3a87
Implement basic search functionality. Has bugs and limitations to be rid of.
Matti Hamalainen <ccr@tnsp.org>
parents:
1786
diff
changeset
|
71 BOOL centered; |
513c467f3a87
Implement basic search functionality. Has bugs and limitations to be rid of.
Matti Hamalainen <ccr@tnsp.org>
parents:
1786
diff
changeset
|
72 } MAPMatch; |
513c467f3a87
Implement basic search functionality. Has bugs and limitations to be rid of.
Matti Hamalainen <ccr@tnsp.org>
parents:
1786
diff
changeset
|
73 |
513c467f3a87
Implement basic search functionality. Has bugs and limitations to be rid of.
Matti Hamalainen <ccr@tnsp.org>
parents:
1786
diff
changeset
|
74 |
1784
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
75 /* Options |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
76 */ |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
77 MAPInfoCtx optMaps[SET_MAX_MAPS]; |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
78 MAPListenerCtx *optListenTo[SET_MAX_LISTEN]; |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
79 int optNMaps = 0; |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
80 int optNListenTo = 0; |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
81 char *optCleanChars = " *@?%C"; |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
82 char *optSSLCipherList = SET_DEF_CIPHERS; |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
83 struct lws_context *setLWSContext = NULL; |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
84 int optWorldXC = 0, optWorldYC = 0; |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
85 |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
86 |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
87 /* Arguments |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
88 */ |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
89 static const th_optarg optList[] = |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
90 { |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
91 { 0, '?', "help", "Show this help and be so very much verbose that it almost hurts you", OPT_NONE }, |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
92 { 1, 'v', "verbose", "Be more verbose", OPT_NONE }, |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
93 { 2, 'l', "listen", "Listen to interface (see below)", OPT_ARGREQ }, |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
94 { 3, 0, "ssl-ciphers", "Specify list of SSL/TLS ciphers", OPT_ARGREQ }, |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
95 { 4, 0, "clean-chars", "String of characters to 'clean up' from map blocks.", OPT_ARGREQ }, |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
96 { 5, 'w', "world-origin", "Specify the world origin <x, y> which map offsets relate to.", OPT_ARGREQ }, |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
97 }; |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
98 |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
99 static const int optListN = sizeof(optList) / sizeof(optList[0]); |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
100 |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
101 |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
102 void argShowHelp(void) |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
103 { |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
104 th_print_banner(stdout, th_prog_name, "[options] <map spec>"); |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
105 th_args_help(stdout, optList, optListN, 0); |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
106 |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
107 fprintf(stdout, |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
108 "\n" |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
109 "Listening interface(s) are specified with following syntax:\n" |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
110 "-l \"[@]<interface/IP/host>:<port>[=<SSL/TLS spec>]\"\n" |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
111 "\n" |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
112 "IPv6 addresses should be specified with the square bracket notation.\n" |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
113 "To force IPv6, use IPv6 address [] or prefix spec with @. In order to\n" |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
114 "listen to all interfaces, you can specify an asterisk (*) as host. Example:\n" |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
115 "\n" |
1814
daf7dcc635d6
Improve SSL/TLS support by adding vhost name to the SSL listener spec and set
Matti Hamalainen <ccr@tnsp.org>
parents:
1812
diff
changeset
|
116 "-l *:3491 -l *:3492=<vhostname for SNI>:<ssl_cert_file.crt>:<ssl_key_file.key>:<ca_file.crt>\n" |
1784
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
117 "\n" |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
118 "Would listen for normal WebSocket (ws://) connections on port 3491 and for\n" |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
119 "secure SSL/TLS WebSocket (wss://) connections on port 3492 of all interfaces.\n" |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
120 "\n" |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
121 "Maps and location files for each map are specified as follows:\n" |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
122 "<filename.map>:<locfilename.loc>:<map/continent name>[:<world x-offset>:<world y-offset>]\n" |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
123 ); |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
124 } |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
125 |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
126 |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
127 BOOL mapParseCoordPair(const char *str, int *xc, int *yc) |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
128 { |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
129 char *piece, *tmp, *fmt = th_strdup(str); |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
130 BOOL ret = FALSE; |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
131 |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
132 if ((piece = strchr(fmt, ':')) == NULL) |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
133 goto err; |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
134 *piece++ = 0; |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
135 |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
136 tmp = th_strdup_trim(fmt, TH_TRIM_BOTH); |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
137 *xc = atoi(tmp); |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
138 th_free(tmp); |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
139 |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
140 tmp = th_strdup_trim(piece, TH_TRIM_BOTH); |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
141 *yc = atoi(tmp); |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
142 th_free(tmp); |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
143 |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
144 ret = TRUE; |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
145 |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
146 err: |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
147 th_free(fmt); |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
148 return ret; |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
149 } |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
150 |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
151 |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
152 BOOL mapParseMapSpec(const char *str, MAPInfoCtx *info) |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
153 { |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
154 char *piece, *start, *fmt = th_strdup(str); |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
155 BOOL ret = FALSE; |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
156 |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
157 // Check for map filename end |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
158 if ((piece = strchr(fmt, ':')) == NULL) |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
159 goto err; |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
160 *piece++ = 0; |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
161 |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
162 info->mapFilename = th_strdup_trim(fmt, TH_TRIM_BOTH); |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
163 start = piece; |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
164 |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
165 // Check for loc filename end |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
166 if ((piece = strchr(start, ':')) == NULL) |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
167 goto err; |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
168 *piece++ = 0; |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
169 |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
170 info->locFile.filename = th_strdup_trim(start, TH_TRIM_BOTH); |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
171 start = piece; |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
172 |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
173 // Check for world x-offset separator |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
174 if ((piece = strchr(start, ':')) != NULL) |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
175 *piece++ = 0; |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
176 |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
177 info->locFile.continent = th_strdup_trim(start, TH_TRIM_BOTH); |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
178 |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
179 // Get world X/Y offsets, if any |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
180 if (piece != NULL && |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
181 !mapParseCoordPair(piece, &info->locFile.x, &info->locFile.y)) |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
182 goto err; |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
183 |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
184 ret = TRUE; |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
185 |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
186 err: |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
187 th_free(fmt); |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
188 return ret; |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
189 } |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
190 |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
191 |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
192 MAPListenerCtx *mapNewListenCtx(void) |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
193 { |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
194 return th_malloc0(sizeof(MAPListenerCtx)); |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
195 } |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
196 |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
197 |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
198 void mapFreeListenCtxR(MAPListenerCtx *ctx) |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
199 { |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
200 if (ctx != NULL) |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
201 { |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
202 th_free(ctx->interface); |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
203 th_free(ctx->sslCertFile); |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
204 th_free(ctx->sslKeyFile); |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
205 th_free(ctx->sslCAFile); |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
206 } |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
207 } |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
208 |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
209 |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
210 void mapFreeListenCtx(MAPListenerCtx *ctx) |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
211 { |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
212 mapFreeListenCtxR(ctx); |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
213 th_free(ctx); |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
214 } |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
215 |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
216 |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
217 MAPListenerCtx *mapParseListenerSpec(const char *cfmt) |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
218 { |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
219 char *start, *end, *flags, *port = NULL, *interface, *fmt = th_strdup(cfmt); |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
220 BOOL ret = FALSE; |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
221 MAPListenerCtx *ctx; |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
222 |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
223 if ((ctx = mapNewListenCtx()) == NULL) |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
224 goto out; |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
225 |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
226 interface = fmt; |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
227 if (*interface == '@') |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
228 { |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
229 interface++; |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
230 ctx->useIPv6 = TRUE; |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
231 } |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
232 |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
233 if (*interface == '[') |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
234 { |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
235 // IPv6 IP address is handled in a special case |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
236 interface++; |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
237 if ((end = strchr(interface, ']')) == NULL) |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
238 { |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
239 THERR("Invalid IPv6 IP address '%s'.\n", cfmt); |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
240 goto out; |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
241 } |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
242 *end++ = 0; |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
243 ctx->useIPv6 = TRUE; |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
244 } |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
245 else |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
246 { |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
247 end = strchr(interface, ':'); |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
248 } |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
249 |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
250 // Find port number separator |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
251 if (end == NULL || *end != ':') |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
252 { |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
253 THERR("Missing listening port in '%s'.\n", cfmt); |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
254 goto out; |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
255 } |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
256 *end++ = 0; |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
257 start = end; |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
258 |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
259 // Check for '=flags' at the end |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
260 if ((flags = strchr(start, '=')) != NULL) |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
261 *flags++ = 0; |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
262 |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
263 // Get the interface name |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
264 ctx->interface = th_strdup_trim(interface, TH_TRIM_BOTH); |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
265 if (strcmp(ctx->interface, "*") == 0) |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
266 { |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
267 th_free(ctx->interface); |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
268 ctx->interface = NULL; |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
269 } |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
270 |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
271 // Get port number |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
272 if ((port = th_strdup_trim(start, TH_TRIM_BOTH)) == NULL) |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
273 { |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
274 THERR("Missing listening port in '%s'.\n", cfmt); |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
275 goto out; |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
276 } |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
277 ctx->port = atoi(port); |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
278 |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
279 // Parse the SSL/TLS spec, if any |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
280 if (flags != NULL) |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
281 { |
1814
daf7dcc635d6
Improve SSL/TLS support by adding vhost name to the SSL listener spec and set
Matti Hamalainen <ccr@tnsp.org>
parents:
1812
diff
changeset
|
282 char *cstart, *cend; |
daf7dcc635d6
Improve SSL/TLS support by adding vhost name to the SSL listener spec and set
Matti Hamalainen <ccr@tnsp.org>
parents:
1812
diff
changeset
|
283 |
daf7dcc635d6
Improve SSL/TLS support by adding vhost name to the SSL listener spec and set
Matti Hamalainen <ccr@tnsp.org>
parents:
1812
diff
changeset
|
284 // Check for separator |
daf7dcc635d6
Improve SSL/TLS support by adding vhost name to the SSL listener spec and set
Matti Hamalainen <ccr@tnsp.org>
parents:
1812
diff
changeset
|
285 cstart = flags; |
1784
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
286 if ((cend = strchr(cstart, ':')) == NULL) |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
287 { |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
288 THERR("Invalid SSL/TLS spec '%s'\n", flags); |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
289 goto out; |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
290 } |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
291 *cend++ = 0; |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
292 |
1814
daf7dcc635d6
Improve SSL/TLS support by adding vhost name to the SSL listener spec and set
Matti Hamalainen <ccr@tnsp.org>
parents:
1812
diff
changeset
|
293 // Get the vhost name |
daf7dcc635d6
Improve SSL/TLS support by adding vhost name to the SSL listener spec and set
Matti Hamalainen <ccr@tnsp.org>
parents:
1812
diff
changeset
|
294 ctx->vhostname = th_strdup_trim(cstart, TH_TRIM_BOTH); |
daf7dcc635d6
Improve SSL/TLS support by adding vhost name to the SSL listener spec and set
Matti Hamalainen <ccr@tnsp.org>
parents:
1812
diff
changeset
|
295 if (strlen(ctx->vhostname) == 0) |
daf7dcc635d6
Improve SSL/TLS support by adding vhost name to the SSL listener spec and set
Matti Hamalainen <ccr@tnsp.org>
parents:
1812
diff
changeset
|
296 { |
daf7dcc635d6
Improve SSL/TLS support by adding vhost name to the SSL listener spec and set
Matti Hamalainen <ccr@tnsp.org>
parents:
1812
diff
changeset
|
297 th_free(ctx->vhostname); |
daf7dcc635d6
Improve SSL/TLS support by adding vhost name to the SSL listener spec and set
Matti Hamalainen <ccr@tnsp.org>
parents:
1812
diff
changeset
|
298 ctx->vhostname = NULL; |
daf7dcc635d6
Improve SSL/TLS support by adding vhost name to the SSL listener spec and set
Matti Hamalainen <ccr@tnsp.org>
parents:
1812
diff
changeset
|
299 } |
daf7dcc635d6
Improve SSL/TLS support by adding vhost name to the SSL listener spec and set
Matti Hamalainen <ccr@tnsp.org>
parents:
1812
diff
changeset
|
300 |
daf7dcc635d6
Improve SSL/TLS support by adding vhost name to the SSL listener spec and set
Matti Hamalainen <ccr@tnsp.org>
parents:
1812
diff
changeset
|
301 // Check for separator |
1784
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
302 cstart = cend; |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
303 if ((cend = strchr(cend, ':')) == NULL) |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
304 { |
1814
daf7dcc635d6
Improve SSL/TLS support by adding vhost name to the SSL listener spec and set
Matti Hamalainen <ccr@tnsp.org>
parents:
1812
diff
changeset
|
305 THERR("Invalid SSL/TLS spec, missing certificate file.\n"); |
1784
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
306 goto out; |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
307 } |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
308 *cend++ = 0; |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
309 |
1814
daf7dcc635d6
Improve SSL/TLS support by adding vhost name to the SSL listener spec and set
Matti Hamalainen <ccr@tnsp.org>
parents:
1812
diff
changeset
|
310 // Get certificate file path |
daf7dcc635d6
Improve SSL/TLS support by adding vhost name to the SSL listener spec and set
Matti Hamalainen <ccr@tnsp.org>
parents:
1812
diff
changeset
|
311 ctx->sslCertFile = th_strdup_trim(cstart, TH_TRIM_BOTH); |
daf7dcc635d6
Improve SSL/TLS support by adding vhost name to the SSL listener spec and set
Matti Hamalainen <ccr@tnsp.org>
parents:
1812
diff
changeset
|
312 |
daf7dcc635d6
Improve SSL/TLS support by adding vhost name to the SSL listener spec and set
Matti Hamalainen <ccr@tnsp.org>
parents:
1812
diff
changeset
|
313 // Check for separator |
daf7dcc635d6
Improve SSL/TLS support by adding vhost name to the SSL listener spec and set
Matti Hamalainen <ccr@tnsp.org>
parents:
1812
diff
changeset
|
314 cstart = cend; |
daf7dcc635d6
Improve SSL/TLS support by adding vhost name to the SSL listener spec and set
Matti Hamalainen <ccr@tnsp.org>
parents:
1812
diff
changeset
|
315 if ((cend = strchr(cend, ':')) == NULL) |
daf7dcc635d6
Improve SSL/TLS support by adding vhost name to the SSL listener spec and set
Matti Hamalainen <ccr@tnsp.org>
parents:
1812
diff
changeset
|
316 { |
daf7dcc635d6
Improve SSL/TLS support by adding vhost name to the SSL listener spec and set
Matti Hamalainen <ccr@tnsp.org>
parents:
1812
diff
changeset
|
317 THERR("Invalid SSL/TLS spec, missing key file.\n"); |
daf7dcc635d6
Improve SSL/TLS support by adding vhost name to the SSL listener spec and set
Matti Hamalainen <ccr@tnsp.org>
parents:
1812
diff
changeset
|
318 goto out; |
daf7dcc635d6
Improve SSL/TLS support by adding vhost name to the SSL listener spec and set
Matti Hamalainen <ccr@tnsp.org>
parents:
1812
diff
changeset
|
319 } |
daf7dcc635d6
Improve SSL/TLS support by adding vhost name to the SSL listener spec and set
Matti Hamalainen <ccr@tnsp.org>
parents:
1812
diff
changeset
|
320 *cend++ = 0; |
daf7dcc635d6
Improve SSL/TLS support by adding vhost name to the SSL listener spec and set
Matti Hamalainen <ccr@tnsp.org>
parents:
1812
diff
changeset
|
321 |
daf7dcc635d6
Improve SSL/TLS support by adding vhost name to the SSL listener spec and set
Matti Hamalainen <ccr@tnsp.org>
parents:
1812
diff
changeset
|
322 // Get the rest |
1784
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
323 ctx->sslKeyFile = th_strdup_trim(cstart, TH_TRIM_BOTH); |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
324 ctx->sslCAFile = th_strdup_trim(cend, TH_TRIM_BOTH); |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
325 ctx->useSSL = TRUE; |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
326 } |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
327 |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
328 // Check for duplicates |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
329 for (int n = 0; n < optNListenTo; n++) |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
330 { |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
331 MAPListenerCtx *chk = optListenTo[n]; |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
332 if (( |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
333 (ctx->interface == NULL && chk->interface == NULL) || |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
334 (ctx->interface != NULL && chk->interface != NULL && strcmp(ctx->interface, chk->interface) == 0)) && |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
335 chk->port == ctx->port) |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
336 { |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
337 THERR("Duplicate listener spec (%s:%d)\n", |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
338 ctx->interface != NULL ? ctx->interface : "*", ctx->port); |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
339 goto out; |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
340 } |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
341 } |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
342 ret = TRUE; |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
343 |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
344 out: |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
345 th_free(fmt); |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
346 th_free(port); |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
347 |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
348 if (ret) |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
349 return ctx; |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
350 |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
351 mapFreeListenCtx(ctx); |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
352 return NULL; |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
353 } |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
354 |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
355 |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
356 BOOL argHandleOpt(const int optN, char *optArg, char *currArg) |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
357 { |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
358 switch (optN) |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
359 { |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
360 case 0: |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
361 argShowHelp(); |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
362 exit(0); |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
363 break; |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
364 |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
365 case 1: |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
366 th_verbosityLevel++; |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
367 break; |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
368 |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
369 case 2: |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
370 if (optNListenTo < SET_MAX_LISTEN) |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
371 { |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
372 MAPListenerCtx *ctx; |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
373 if ((ctx = mapParseListenerSpec(optArg)) != NULL) |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
374 optListenTo[optNListenTo++] = ctx; |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
375 else |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
376 return FALSE; |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
377 } |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
378 else |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
379 { |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
380 THERR("Maximum number of listener specs already specified.\n"); |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
381 return FALSE; |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
382 } |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
383 break; |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
384 |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
385 case 3: |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
386 optSSLCipherList = optArg; |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
387 break; |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
388 |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
389 case 4: |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
390 optCleanChars = optArg; |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
391 break; |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
392 |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
393 case 5: |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
394 if (!mapParseCoordPair(optArg, &optWorldXC, &optWorldYC)) |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
395 { |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
396 THERR("Invalid world origin coordinates '%s'.\n", optArg); |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
397 return FALSE; |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
398 } |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
399 break; |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
400 |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
401 default: |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
402 THERR("Unknown option '%s'.\n", currArg); |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
403 return FALSE; |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
404 } |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
405 |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
406 return TRUE; |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
407 } |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
408 |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
409 |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
410 BOOL argHandleFile(char *currArg) |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
411 { |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
412 if (optNMaps < SET_MAX_MAPS) |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
413 { |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
414 if (!mapParseMapSpec(currArg, &optMaps[optNMaps])) |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
415 { |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
416 THERR("Invalid map spec '%s'.\n", currArg); |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
417 return FALSE; |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
418 } |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
419 |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
420 optNMaps++; |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
421 return TRUE; |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
422 } |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
423 else |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
424 { |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
425 THERR("Maximum number of map specs already specified.\n"); |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
426 return FALSE; |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
427 } |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
428 } |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
429 |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
430 |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
431 void mapSigHandler(uv_signal_t *watcher, int signum) |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
432 { |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
433 (void) signum; |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
434 |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
435 THERR("Signal %d caught, exiting...\n", watcher->signum); |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
436 |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
437 switch (watcher->signum) |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
438 { |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
439 case SIGTERM: |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
440 case SIGINT: |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
441 break; |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
442 |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
443 default: |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
444 signal(SIGABRT, SIG_DFL); |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
445 abort(); |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
446 break; |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
447 } |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
448 |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
449 lws_libuv_stop(setLWSContext); |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
450 } |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
451 |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
452 |
1785
7ec862ed6514
Implement some of the necessary search helper functions related to map block parsing and so on.
Matti Hamalainen <ccr@tnsp.org>
parents:
1784
diff
changeset
|
453 void mapBlockGetDimensions(const unsigned char *data, const size_t len, int *width, int *height) |
7ec862ed6514
Implement some of the necessary search helper functions related to map block parsing and so on.
Matti Hamalainen <ccr@tnsp.org>
parents:
1784
diff
changeset
|
454 { |
7ec862ed6514
Implement some of the necessary search helper functions related to map block parsing and so on.
Matti Hamalainen <ccr@tnsp.org>
parents:
1784
diff
changeset
|
455 size_t offs = 0; |
7ec862ed6514
Implement some of the necessary search helper functions related to map block parsing and so on.
Matti Hamalainen <ccr@tnsp.org>
parents:
1784
diff
changeset
|
456 int x = 0, x2 = 0; |
7ec862ed6514
Implement some of the necessary search helper functions related to map block parsing and so on.
Matti Hamalainen <ccr@tnsp.org>
parents:
1784
diff
changeset
|
457 |
1815
7ac487466456
Fixes to the block parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1814
diff
changeset
|
458 *width = *height = 0; |
1785
7ec862ed6514
Implement some of the necessary search helper functions related to map block parsing and so on.
Matti Hamalainen <ccr@tnsp.org>
parents:
1784
diff
changeset
|
459 |
7ec862ed6514
Implement some of the necessary search helper functions related to map block parsing and so on.
Matti Hamalainen <ccr@tnsp.org>
parents:
1784
diff
changeset
|
460 while (offs < len) |
7ec862ed6514
Implement some of the necessary search helper functions related to map block parsing and so on.
Matti Hamalainen <ccr@tnsp.org>
parents:
1784
diff
changeset
|
461 { |
1815
7ac487466456
Fixes to the block parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1814
diff
changeset
|
462 const unsigned char ch = data[offs++]; |
7ac487466456
Fixes to the block parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1814
diff
changeset
|
463 if (ch == '\n') |
1785
7ec862ed6514
Implement some of the necessary search helper functions related to map block parsing and so on.
Matti Hamalainen <ccr@tnsp.org>
parents:
1784
diff
changeset
|
464 { |
7ec862ed6514
Implement some of the necessary search helper functions related to map block parsing and so on.
Matti Hamalainen <ccr@tnsp.org>
parents:
1784
diff
changeset
|
465 if (x > *width) |
7ec862ed6514
Implement some of the necessary search helper functions related to map block parsing and so on.
Matti Hamalainen <ccr@tnsp.org>
parents:
1784
diff
changeset
|
466 *width = x; |
7ec862ed6514
Implement some of the necessary search helper functions related to map block parsing and so on.
Matti Hamalainen <ccr@tnsp.org>
parents:
1784
diff
changeset
|
467 |
1815
7ac487466456
Fixes to the block parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1814
diff
changeset
|
468 (*height)++; |
1785
7ec862ed6514
Implement some of the necessary search helper functions related to map block parsing and so on.
Matti Hamalainen <ccr@tnsp.org>
parents:
1784
diff
changeset
|
469 x = x2 = 0; |
7ec862ed6514
Implement some of the necessary search helper functions related to map block parsing and so on.
Matti Hamalainen <ccr@tnsp.org>
parents:
1784
diff
changeset
|
470 } |
7ec862ed6514
Implement some of the necessary search helper functions related to map block parsing and so on.
Matti Hamalainen <ccr@tnsp.org>
parents:
1784
diff
changeset
|
471 else |
7ec862ed6514
Implement some of the necessary search helper functions related to map block parsing and so on.
Matti Hamalainen <ccr@tnsp.org>
parents:
1784
diff
changeset
|
472 { |
7ec862ed6514
Implement some of the necessary search helper functions related to map block parsing and so on.
Matti Hamalainen <ccr@tnsp.org>
parents:
1784
diff
changeset
|
473 x2++; |
1815
7ac487466456
Fixes to the block parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1814
diff
changeset
|
474 if (ch != ' ') |
1785
7ec862ed6514
Implement some of the necessary search helper functions related to map block parsing and so on.
Matti Hamalainen <ccr@tnsp.org>
parents:
1784
diff
changeset
|
475 x = x2; |
7ec862ed6514
Implement some of the necessary search helper functions related to map block parsing and so on.
Matti Hamalainen <ccr@tnsp.org>
parents:
1784
diff
changeset
|
476 } |
7ec862ed6514
Implement some of the necessary search helper functions related to map block parsing and so on.
Matti Hamalainen <ccr@tnsp.org>
parents:
1784
diff
changeset
|
477 } |
7ec862ed6514
Implement some of the necessary search helper functions related to map block parsing and so on.
Matti Hamalainen <ccr@tnsp.org>
parents:
1784
diff
changeset
|
478 |
1815
7ac487466456
Fixes to the block parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1814
diff
changeset
|
479 if (x > *width) |
7ac487466456
Fixes to the block parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1814
diff
changeset
|
480 *width = x; |
7ac487466456
Fixes to the block parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1814
diff
changeset
|
481 |
1785
7ec862ed6514
Implement some of the necessary search helper functions related to map block parsing and so on.
Matti Hamalainen <ccr@tnsp.org>
parents:
1784
diff
changeset
|
482 if (x > 0) |
7ec862ed6514
Implement some of the necessary search helper functions related to map block parsing and so on.
Matti Hamalainen <ccr@tnsp.org>
parents:
1784
diff
changeset
|
483 (*height)++; |
7ec862ed6514
Implement some of the necessary search helper functions related to map block parsing and so on.
Matti Hamalainen <ccr@tnsp.org>
parents:
1784
diff
changeset
|
484 } |
7ec862ed6514
Implement some of the necessary search helper functions related to map block parsing and so on.
Matti Hamalainen <ccr@tnsp.org>
parents:
1784
diff
changeset
|
485 |
7ec862ed6514
Implement some of the necessary search helper functions related to map block parsing and so on.
Matti Hamalainen <ccr@tnsp.org>
parents:
1784
diff
changeset
|
486 |
7ec862ed6514
Implement some of the necessary search helper functions related to map block parsing and so on.
Matti Hamalainen <ccr@tnsp.org>
parents:
1784
diff
changeset
|
487 BOOL mapBlockParse(const unsigned char *data, const size_t len, MapBlock *res) |
7ec862ed6514
Implement some of the necessary search helper functions related to map block parsing and so on.
Matti Hamalainen <ccr@tnsp.org>
parents:
1784
diff
changeset
|
488 { |
7ec862ed6514
Implement some of the necessary search helper functions related to map block parsing and so on.
Matti Hamalainen <ccr@tnsp.org>
parents:
1784
diff
changeset
|
489 size_t offs = 0; |
7ec862ed6514
Implement some of the necessary search helper functions related to map block parsing and so on.
Matti Hamalainen <ccr@tnsp.org>
parents:
1784
diff
changeset
|
490 |
1815
7ac487466456
Fixes to the block parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1814
diff
changeset
|
491 for (int yc = 0; yc < res->height; yc++) |
7ac487466456
Fixes to the block parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1814
diff
changeset
|
492 { |
7ac487466456
Fixes to the block parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1814
diff
changeset
|
493 unsigned char *dp = res->data + (yc * res->scansize); |
7ac487466456
Fixes to the block parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1814
diff
changeset
|
494 for (int xc = 0; xc < res->width; xc++) |
1785
7ec862ed6514
Implement some of the necessary search helper functions related to map block parsing and so on.
Matti Hamalainen <ccr@tnsp.org>
parents:
1784
diff
changeset
|
495 { |
1815
7ac487466456
Fixes to the block parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1814
diff
changeset
|
496 if (offs < len) |
1785
7ec862ed6514
Implement some of the necessary search helper functions related to map block parsing and so on.
Matti Hamalainen <ccr@tnsp.org>
parents:
1784
diff
changeset
|
497 { |
1815
7ac487466456
Fixes to the block parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1814
diff
changeset
|
498 dp[xc] = data[offs++]; |
1785
7ec862ed6514
Implement some of the necessary search helper functions related to map block parsing and so on.
Matti Hamalainen <ccr@tnsp.org>
parents:
1784
diff
changeset
|
499 } |
7ec862ed6514
Implement some of the necessary search helper functions related to map block parsing and so on.
Matti Hamalainen <ccr@tnsp.org>
parents:
1784
diff
changeset
|
500 } |
1815
7ac487466456
Fixes to the block parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1814
diff
changeset
|
501 while (offs < len && data[offs] != '\n') |
7ac487466456
Fixes to the block parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1814
diff
changeset
|
502 offs++; |
1785
7ec862ed6514
Implement some of the necessary search helper functions related to map block parsing and so on.
Matti Hamalainen <ccr@tnsp.org>
parents:
1784
diff
changeset
|
503 } |
7ec862ed6514
Implement some of the necessary search helper functions related to map block parsing and so on.
Matti Hamalainen <ccr@tnsp.org>
parents:
1784
diff
changeset
|
504 |
1815
7ac487466456
Fixes to the block parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1814
diff
changeset
|
505 return offs == len; |
1785
7ec862ed6514
Implement some of the necessary search helper functions related to map block parsing and so on.
Matti Hamalainen <ccr@tnsp.org>
parents:
1784
diff
changeset
|
506 } |
7ec862ed6514
Implement some of the necessary search helper functions related to map block parsing and so on.
Matti Hamalainen <ccr@tnsp.org>
parents:
1784
diff
changeset
|
507 |
7ec862ed6514
Implement some of the necessary search helper functions related to map block parsing and so on.
Matti Hamalainen <ccr@tnsp.org>
parents:
1784
diff
changeset
|
508 |
1808
54607b2d0c8c
Don't use strchr() for the center finding algorithm, it is not fit to our purpose.
Matti Hamalainen <ccr@tnsp.org>
parents:
1806
diff
changeset
|
509 BOOL mapStrChr(const unsigned char *symbols, const size_t nsymbols, const unsigned char ch) |
54607b2d0c8c
Don't use strchr() for the center finding algorithm, it is not fit to our purpose.
Matti Hamalainen <ccr@tnsp.org>
parents:
1806
diff
changeset
|
510 { |
54607b2d0c8c
Don't use strchr() for the center finding algorithm, it is not fit to our purpose.
Matti Hamalainen <ccr@tnsp.org>
parents:
1806
diff
changeset
|
511 for (size_t n = 0; n < nsymbols; n++) |
54607b2d0c8c
Don't use strchr() for the center finding algorithm, it is not fit to our purpose.
Matti Hamalainen <ccr@tnsp.org>
parents:
1806
diff
changeset
|
512 if (symbols[n] == ch) |
54607b2d0c8c
Don't use strchr() for the center finding algorithm, it is not fit to our purpose.
Matti Hamalainen <ccr@tnsp.org>
parents:
1806
diff
changeset
|
513 return TRUE; |
54607b2d0c8c
Don't use strchr() for the center finding algorithm, it is not fit to our purpose.
Matti Hamalainen <ccr@tnsp.org>
parents:
1806
diff
changeset
|
514 |
54607b2d0c8c
Don't use strchr() for the center finding algorithm, it is not fit to our purpose.
Matti Hamalainen <ccr@tnsp.org>
parents:
1806
diff
changeset
|
515 return FALSE; |
54607b2d0c8c
Don't use strchr() for the center finding algorithm, it is not fit to our purpose.
Matti Hamalainen <ccr@tnsp.org>
parents:
1806
diff
changeset
|
516 } |
54607b2d0c8c
Don't use strchr() for the center finding algorithm, it is not fit to our purpose.
Matti Hamalainen <ccr@tnsp.org>
parents:
1806
diff
changeset
|
517 |
54607b2d0c8c
Don't use strchr() for the center finding algorithm, it is not fit to our purpose.
Matti Hamalainen <ccr@tnsp.org>
parents:
1806
diff
changeset
|
518 |
54607b2d0c8c
Don't use strchr() for the center finding algorithm, it is not fit to our purpose.
Matti Hamalainen <ccr@tnsp.org>
parents:
1806
diff
changeset
|
519 BOOL mapBlockFindCenter(const MapBlock *block, const unsigned char *symbols, const size_t nsymbols, int *cx, int *cy, const int tolerance) |
1785
7ec862ed6514
Implement some of the necessary search helper functions related to map block parsing and so on.
Matti Hamalainen <ccr@tnsp.org>
parents:
1784
diff
changeset
|
520 { |
7ec862ed6514
Implement some of the necessary search helper functions related to map block parsing and so on.
Matti Hamalainen <ccr@tnsp.org>
parents:
1784
diff
changeset
|
521 const int |
7ec862ed6514
Implement some of the necessary search helper functions related to map block parsing and so on.
Matti Hamalainen <ccr@tnsp.org>
parents:
1784
diff
changeset
|
522 x0 = (block->width * tolerance) / 100, |
7ec862ed6514
Implement some of the necessary search helper functions related to map block parsing and so on.
Matti Hamalainen <ccr@tnsp.org>
parents:
1784
diff
changeset
|
523 x1 = (block->width * (100 - tolerance)) / 100, |
7ec862ed6514
Implement some of the necessary search helper functions related to map block parsing and so on.
Matti Hamalainen <ccr@tnsp.org>
parents:
1784
diff
changeset
|
524 y0 = (block->height * tolerance) / 100, |
7ec862ed6514
Implement some of the necessary search helper functions related to map block parsing and so on.
Matti Hamalainen <ccr@tnsp.org>
parents:
1784
diff
changeset
|
525 y1 = (block->height * (100 - tolerance)) / 100; |
7ec862ed6514
Implement some of the necessary search helper functions related to map block parsing and so on.
Matti Hamalainen <ccr@tnsp.org>
parents:
1784
diff
changeset
|
526 |
1798
76dce42776f8
Set center coordinates to zero by default.
Matti Hamalainen <ccr@tnsp.org>
parents:
1797
diff
changeset
|
527 *cx = *cy = 0; |
1785
7ec862ed6514
Implement some of the necessary search helper functions related to map block parsing and so on.
Matti Hamalainen <ccr@tnsp.org>
parents:
1784
diff
changeset
|
528 for (int yc = 0; yc < block->height; yc++) |
7ec862ed6514
Implement some of the necessary search helper functions related to map block parsing and so on.
Matti Hamalainen <ccr@tnsp.org>
parents:
1784
diff
changeset
|
529 { |
7ec862ed6514
Implement some of the necessary search helper functions related to map block parsing and so on.
Matti Hamalainen <ccr@tnsp.org>
parents:
1784
diff
changeset
|
530 unsigned char *dp = block->data + (yc * block->scansize); |
7ec862ed6514
Implement some of the necessary search helper functions related to map block parsing and so on.
Matti Hamalainen <ccr@tnsp.org>
parents:
1784
diff
changeset
|
531 for (int xc = 0; xc < block->width; xc++) |
7ec862ed6514
Implement some of the necessary search helper functions related to map block parsing and so on.
Matti Hamalainen <ccr@tnsp.org>
parents:
1784
diff
changeset
|
532 { |
7ec862ed6514
Implement some of the necessary search helper functions related to map block parsing and so on.
Matti Hamalainen <ccr@tnsp.org>
parents:
1784
diff
changeset
|
533 if (xc >= x0 && xc <= x1 && |
7ec862ed6514
Implement some of the necessary search helper functions related to map block parsing and so on.
Matti Hamalainen <ccr@tnsp.org>
parents:
1784
diff
changeset
|
534 yc >= y0 && yc <= y1 && |
1808
54607b2d0c8c
Don't use strchr() for the center finding algorithm, it is not fit to our purpose.
Matti Hamalainen <ccr@tnsp.org>
parents:
1806
diff
changeset
|
535 mapStrChr(symbols, nsymbols, dp[xc])) |
1785
7ec862ed6514
Implement some of the necessary search helper functions related to map block parsing and so on.
Matti Hamalainen <ccr@tnsp.org>
parents:
1784
diff
changeset
|
536 { |
7ec862ed6514
Implement some of the necessary search helper functions related to map block parsing and so on.
Matti Hamalainen <ccr@tnsp.org>
parents:
1784
diff
changeset
|
537 *cx = xc; |
7ec862ed6514
Implement some of the necessary search helper functions related to map block parsing and so on.
Matti Hamalainen <ccr@tnsp.org>
parents:
1784
diff
changeset
|
538 *cy = yc; |
7ec862ed6514
Implement some of the necessary search helper functions related to map block parsing and so on.
Matti Hamalainen <ccr@tnsp.org>
parents:
1784
diff
changeset
|
539 return TRUE; |
7ec862ed6514
Implement some of the necessary search helper functions related to map block parsing and so on.
Matti Hamalainen <ccr@tnsp.org>
parents:
1784
diff
changeset
|
540 } |
7ec862ed6514
Implement some of the necessary search helper functions related to map block parsing and so on.
Matti Hamalainen <ccr@tnsp.org>
parents:
1784
diff
changeset
|
541 } |
7ec862ed6514
Implement some of the necessary search helper functions related to map block parsing and so on.
Matti Hamalainen <ccr@tnsp.org>
parents:
1784
diff
changeset
|
542 } |
7ec862ed6514
Implement some of the necessary search helper functions related to map block parsing and so on.
Matti Hamalainen <ccr@tnsp.org>
parents:
1784
diff
changeset
|
543 |
7ec862ed6514
Implement some of the necessary search helper functions related to map block parsing and so on.
Matti Hamalainen <ccr@tnsp.org>
parents:
1784
diff
changeset
|
544 return FALSE; |
7ec862ed6514
Implement some of the necessary search helper functions related to map block parsing and so on.
Matti Hamalainen <ccr@tnsp.org>
parents:
1784
diff
changeset
|
545 } |
7ec862ed6514
Implement some of the necessary search helper functions related to map block parsing and so on.
Matti Hamalainen <ccr@tnsp.org>
parents:
1784
diff
changeset
|
546 |
7ec862ed6514
Implement some of the necessary search helper functions related to map block parsing and so on.
Matti Hamalainen <ccr@tnsp.org>
parents:
1784
diff
changeset
|
547 |
1786
eb98e57d3969
Bring in mapBlockGetEntropy() as we will be using it in the search server.
Matti Hamalainen <ccr@tnsp.org>
parents:
1785
diff
changeset
|
548 int mapBlockGetEntropy(const MapBlock *map, const char *exclude, const int nexclude) |
eb98e57d3969
Bring in mapBlockGetEntropy() as we will be using it in the search server.
Matti Hamalainen <ccr@tnsp.org>
parents:
1785
diff
changeset
|
549 { |
eb98e57d3969
Bring in mapBlockGetEntropy() as we will be using it in the search server.
Matti Hamalainen <ccr@tnsp.org>
parents:
1785
diff
changeset
|
550 unsigned char *list; |
eb98e57d3969
Bring in mapBlockGetEntropy() as we will be using it in the search server.
Matti Hamalainen <ccr@tnsp.org>
parents:
1785
diff
changeset
|
551 int num, i; |
eb98e57d3969
Bring in mapBlockGetEntropy() as we will be using it in the search server.
Matti Hamalainen <ccr@tnsp.org>
parents:
1785
diff
changeset
|
552 |
eb98e57d3969
Bring in mapBlockGetEntropy() as we will be using it in the search server.
Matti Hamalainen <ccr@tnsp.org>
parents:
1785
diff
changeset
|
553 // Allocate memory for entropy array |
eb98e57d3969
Bring in mapBlockGetEntropy() as we will be using it in the search server.
Matti Hamalainen <ccr@tnsp.org>
parents:
1785
diff
changeset
|
554 if ((list = th_malloc0(256)) == NULL) |
eb98e57d3969
Bring in mapBlockGetEntropy() as we will be using it in the search server.
Matti Hamalainen <ccr@tnsp.org>
parents:
1785
diff
changeset
|
555 return -1; |
eb98e57d3969
Bring in mapBlockGetEntropy() as we will be using it in the search server.
Matti Hamalainen <ccr@tnsp.org>
parents:
1785
diff
changeset
|
556 |
eb98e57d3969
Bring in mapBlockGetEntropy() as we will be using it in the search server.
Matti Hamalainen <ccr@tnsp.org>
parents:
1785
diff
changeset
|
557 // Collect sums into entropy array |
eb98e57d3969
Bring in mapBlockGetEntropy() as we will be using it in the search server.
Matti Hamalainen <ccr@tnsp.org>
parents:
1785
diff
changeset
|
558 for (int y = 0; y < map->height; y++) |
eb98e57d3969
Bring in mapBlockGetEntropy() as we will be using it in the search server.
Matti Hamalainen <ccr@tnsp.org>
parents:
1785
diff
changeset
|
559 { |
eb98e57d3969
Bring in mapBlockGetEntropy() as we will be using it in the search server.
Matti Hamalainen <ccr@tnsp.org>
parents:
1785
diff
changeset
|
560 unsigned char *c = map->data + (y * map->scansize); |
eb98e57d3969
Bring in mapBlockGetEntropy() as we will be using it in the search server.
Matti Hamalainen <ccr@tnsp.org>
parents:
1785
diff
changeset
|
561 for (int x = 0; x < map->width; x++) |
eb98e57d3969
Bring in mapBlockGetEntropy() as we will be using it in the search server.
Matti Hamalainen <ccr@tnsp.org>
parents:
1785
diff
changeset
|
562 { |
eb98e57d3969
Bring in mapBlockGetEntropy() as we will be using it in the search server.
Matti Hamalainen <ccr@tnsp.org>
parents:
1785
diff
changeset
|
563 list[*c]++; |
eb98e57d3969
Bring in mapBlockGetEntropy() as we will be using it in the search server.
Matti Hamalainen <ccr@tnsp.org>
parents:
1785
diff
changeset
|
564 c++; |
eb98e57d3969
Bring in mapBlockGetEntropy() as we will be using it in the search server.
Matti Hamalainen <ccr@tnsp.org>
parents:
1785
diff
changeset
|
565 } |
eb98e57d3969
Bring in mapBlockGetEntropy() as we will be using it in the search server.
Matti Hamalainen <ccr@tnsp.org>
parents:
1785
diff
changeset
|
566 } |
eb98e57d3969
Bring in mapBlockGetEntropy() as we will be using it in the search server.
Matti Hamalainen <ccr@tnsp.org>
parents:
1785
diff
changeset
|
567 |
eb98e57d3969
Bring in mapBlockGetEntropy() as we will be using it in the search server.
Matti Hamalainen <ccr@tnsp.org>
parents:
1785
diff
changeset
|
568 // Handle exclusions |
eb98e57d3969
Bring in mapBlockGetEntropy() as we will be using it in the search server.
Matti Hamalainen <ccr@tnsp.org>
parents:
1785
diff
changeset
|
569 if (exclude != NULL && nexclude > 0) |
eb98e57d3969
Bring in mapBlockGetEntropy() as we will be using it in the search server.
Matti Hamalainen <ccr@tnsp.org>
parents:
1785
diff
changeset
|
570 { |
eb98e57d3969
Bring in mapBlockGetEntropy() as we will be using it in the search server.
Matti Hamalainen <ccr@tnsp.org>
parents:
1785
diff
changeset
|
571 for (i = 0; i < nexclude; i++) |
eb98e57d3969
Bring in mapBlockGetEntropy() as we will be using it in the search server.
Matti Hamalainen <ccr@tnsp.org>
parents:
1785
diff
changeset
|
572 list[(int) exclude[i]] = 0; |
eb98e57d3969
Bring in mapBlockGetEntropy() as we will be using it in the search server.
Matti Hamalainen <ccr@tnsp.org>
parents:
1785
diff
changeset
|
573 } |
eb98e57d3969
Bring in mapBlockGetEntropy() as we will be using it in the search server.
Matti Hamalainen <ccr@tnsp.org>
parents:
1785
diff
changeset
|
574 |
eb98e57d3969
Bring in mapBlockGetEntropy() as we will be using it in the search server.
Matti Hamalainen <ccr@tnsp.org>
parents:
1785
diff
changeset
|
575 // Calculate simple entropy |
eb98e57d3969
Bring in mapBlockGetEntropy() as we will be using it in the search server.
Matti Hamalainen <ccr@tnsp.org>
parents:
1785
diff
changeset
|
576 for (num = 0, i = 0; i < 256; i++) |
eb98e57d3969
Bring in mapBlockGetEntropy() as we will be using it in the search server.
Matti Hamalainen <ccr@tnsp.org>
parents:
1785
diff
changeset
|
577 if (list[i]) num++; |
eb98e57d3969
Bring in mapBlockGetEntropy() as we will be using it in the search server.
Matti Hamalainen <ccr@tnsp.org>
parents:
1785
diff
changeset
|
578 |
eb98e57d3969
Bring in mapBlockGetEntropy() as we will be using it in the search server.
Matti Hamalainen <ccr@tnsp.org>
parents:
1785
diff
changeset
|
579 th_free(list); |
eb98e57d3969
Bring in mapBlockGetEntropy() as we will be using it in the search server.
Matti Hamalainen <ccr@tnsp.org>
parents:
1785
diff
changeset
|
580 return num; |
eb98e57d3969
Bring in mapBlockGetEntropy() as we will be using it in the search server.
Matti Hamalainen <ccr@tnsp.org>
parents:
1785
diff
changeset
|
581 } |
eb98e57d3969
Bring in mapBlockGetEntropy() as we will be using it in the search server.
Matti Hamalainen <ccr@tnsp.org>
parents:
1785
diff
changeset
|
582 |
eb98e57d3969
Bring in mapBlockGetEntropy() as we will be using it in the search server.
Matti Hamalainen <ccr@tnsp.org>
parents:
1785
diff
changeset
|
583 |
1785
7ec862ed6514
Implement some of the necessary search helper functions related to map block parsing and so on.
Matti Hamalainen <ccr@tnsp.org>
parents:
1784
diff
changeset
|
584 double mapMatchBlock(const MapBlock *map, const MapBlock *match, int ox, int oy, int fillCh, BOOL hardDrop) |
7ec862ed6514
Implement some of the necessary search helper functions related to map block parsing and so on.
Matti Hamalainen <ccr@tnsp.org>
parents:
1784
diff
changeset
|
585 { |
7ec862ed6514
Implement some of the necessary search helper functions related to map block parsing and so on.
Matti Hamalainen <ccr@tnsp.org>
parents:
1784
diff
changeset
|
586 int n, k; |
7ec862ed6514
Implement some of the necessary search helper functions related to map block parsing and so on.
Matti Hamalainen <ccr@tnsp.org>
parents:
1784
diff
changeset
|
587 |
7ec862ed6514
Implement some of the necessary search helper functions related to map block parsing and so on.
Matti Hamalainen <ccr@tnsp.org>
parents:
1784
diff
changeset
|
588 n = k = 0; |
7ec862ed6514
Implement some of the necessary search helper functions related to map block parsing and so on.
Matti Hamalainen <ccr@tnsp.org>
parents:
1784
diff
changeset
|
589 for (int y = 0; y < match->height; y++) |
7ec862ed6514
Implement some of the necessary search helper functions related to map block parsing and so on.
Matti Hamalainen <ccr@tnsp.org>
parents:
1784
diff
changeset
|
590 { |
7ec862ed6514
Implement some of the necessary search helper functions related to map block parsing and so on.
Matti Hamalainen <ccr@tnsp.org>
parents:
1784
diff
changeset
|
591 unsigned char *dp = match->data + (y * match->scansize); |
7ec862ed6514
Implement some of the necessary search helper functions related to map block parsing and so on.
Matti Hamalainen <ccr@tnsp.org>
parents:
1784
diff
changeset
|
592 for (int x = 0; x < match->width; x++) |
7ec862ed6514
Implement some of the necessary search helper functions related to map block parsing and so on.
Matti Hamalainen <ccr@tnsp.org>
parents:
1784
diff
changeset
|
593 { |
7ec862ed6514
Implement some of the necessary search helper functions related to map block parsing and so on.
Matti Hamalainen <ccr@tnsp.org>
parents:
1784
diff
changeset
|
594 int c1, c2; |
7ec862ed6514
Implement some of the necessary search helper functions related to map block parsing and so on.
Matti Hamalainen <ccr@tnsp.org>
parents:
1784
diff
changeset
|
595 const int |
7ec862ed6514
Implement some of the necessary search helper functions related to map block parsing and so on.
Matti Hamalainen <ccr@tnsp.org>
parents:
1784
diff
changeset
|
596 dx = ox + x, |
7ec862ed6514
Implement some of the necessary search helper functions related to map block parsing and so on.
Matti Hamalainen <ccr@tnsp.org>
parents:
1784
diff
changeset
|
597 dy = oy + y; |
7ec862ed6514
Implement some of the necessary search helper functions related to map block parsing and so on.
Matti Hamalainen <ccr@tnsp.org>
parents:
1784
diff
changeset
|
598 |
7ec862ed6514
Implement some of the necessary search helper functions related to map block parsing and so on.
Matti Hamalainen <ccr@tnsp.org>
parents:
1784
diff
changeset
|
599 k++; |
7ec862ed6514
Implement some of the necessary search helper functions related to map block parsing and so on.
Matti Hamalainen <ccr@tnsp.org>
parents:
1784
diff
changeset
|
600 |
7ec862ed6514
Implement some of the necessary search helper functions related to map block parsing and so on.
Matti Hamalainen <ccr@tnsp.org>
parents:
1784
diff
changeset
|
601 if (dx >= 0 && dx < map->width && dy >= 0 && dy < map->height) |
7ec862ed6514
Implement some of the necessary search helper functions related to map block parsing and so on.
Matti Hamalainen <ccr@tnsp.org>
parents:
1784
diff
changeset
|
602 c2 = map->data[(dy * map->scansize) + dx]; |
7ec862ed6514
Implement some of the necessary search helper functions related to map block parsing and so on.
Matti Hamalainen <ccr@tnsp.org>
parents:
1784
diff
changeset
|
603 else |
7ec862ed6514
Implement some of the necessary search helper functions related to map block parsing and so on.
Matti Hamalainen <ccr@tnsp.org>
parents:
1784
diff
changeset
|
604 c2 = fillCh; |
7ec862ed6514
Implement some of the necessary search helper functions related to map block parsing and so on.
Matti Hamalainen <ccr@tnsp.org>
parents:
1784
diff
changeset
|
605 |
7ec862ed6514
Implement some of the necessary search helper functions related to map block parsing and so on.
Matti Hamalainen <ccr@tnsp.org>
parents:
1784
diff
changeset
|
606 c1 = dp[x]; |
7ec862ed6514
Implement some of the necessary search helper functions related to map block parsing and so on.
Matti Hamalainen <ccr@tnsp.org>
parents:
1784
diff
changeset
|
607 |
7ec862ed6514
Implement some of the necessary search helper functions related to map block parsing and so on.
Matti Hamalainen <ccr@tnsp.org>
parents:
1784
diff
changeset
|
608 if (c1 == 0 || c1 == c2) |
7ec862ed6514
Implement some of the necessary search helper functions related to map block parsing and so on.
Matti Hamalainen <ccr@tnsp.org>
parents:
1784
diff
changeset
|
609 n++; |
7ec862ed6514
Implement some of the necessary search helper functions related to map block parsing and so on.
Matti Hamalainen <ccr@tnsp.org>
parents:
1784
diff
changeset
|
610 else |
7ec862ed6514
Implement some of the necessary search helper functions related to map block parsing and so on.
Matti Hamalainen <ccr@tnsp.org>
parents:
1784
diff
changeset
|
611 if (hardDrop) |
7ec862ed6514
Implement some of the necessary search helper functions related to map block parsing and so on.
Matti Hamalainen <ccr@tnsp.org>
parents:
1784
diff
changeset
|
612 return -1; |
7ec862ed6514
Implement some of the necessary search helper functions related to map block parsing and so on.
Matti Hamalainen <ccr@tnsp.org>
parents:
1784
diff
changeset
|
613 } |
7ec862ed6514
Implement some of the necessary search helper functions related to map block parsing and so on.
Matti Hamalainen <ccr@tnsp.org>
parents:
1784
diff
changeset
|
614 } |
7ec862ed6514
Implement some of the necessary search helper functions related to map block parsing and so on.
Matti Hamalainen <ccr@tnsp.org>
parents:
1784
diff
changeset
|
615 |
7ec862ed6514
Implement some of the necessary search helper functions related to map block parsing and so on.
Matti Hamalainen <ccr@tnsp.org>
parents:
1784
diff
changeset
|
616 if (k > 0) |
7ec862ed6514
Implement some of the necessary search helper functions related to map block parsing and so on.
Matti Hamalainen <ccr@tnsp.org>
parents:
1784
diff
changeset
|
617 return ((double) n * 100.0f) / (double) k; |
7ec862ed6514
Implement some of the necessary search helper functions related to map block parsing and so on.
Matti Hamalainen <ccr@tnsp.org>
parents:
1784
diff
changeset
|
618 else |
7ec862ed6514
Implement some of the necessary search helper functions related to map block parsing and so on.
Matti Hamalainen <ccr@tnsp.org>
parents:
1784
diff
changeset
|
619 return 0.0f; |
7ec862ed6514
Implement some of the necessary search helper functions related to map block parsing and so on.
Matti Hamalainen <ccr@tnsp.org>
parents:
1784
diff
changeset
|
620 } |
1784
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
621 |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
622 |
1800
7c7f24e27a60
Allow specifying of map list to search in the query, and also max number of results.
Matti Hamalainen <ccr@tnsp.org>
parents:
1798
diff
changeset
|
623 void mapPerformSearch(struct lws *wsi, unsigned char *data, const size_t len, char **verr) |
1789
513c467f3a87
Implement basic search functionality. Has bugs and limitations to be rid of.
Matti Hamalainen <ccr@tnsp.org>
parents:
1786
diff
changeset
|
624 { |
513c467f3a87
Implement basic search functionality. Has bugs and limitations to be rid of.
Matti Hamalainen <ccr@tnsp.org>
parents:
1786
diff
changeset
|
625 int width, height, centerX, centerY; |
513c467f3a87
Implement basic search functionality. Has bugs and limitations to be rid of.
Matti Hamalainen <ccr@tnsp.org>
parents:
1786
diff
changeset
|
626 MapBlock *pattern = NULL; |
1800
7c7f24e27a60
Allow specifying of map list to search in the query, and also max number of results.
Matti Hamalainen <ccr@tnsp.org>
parents:
1798
diff
changeset
|
627 BOOL mapList[SET_MAX_MAPS]; |
1789
513c467f3a87
Implement basic search functionality. Has bugs and limitations to be rid of.
Matti Hamalainen <ccr@tnsp.org>
parents:
1786
diff
changeset
|
628 MAPMatch matches[SET_MAX_MATCHES]; |
1800
7c7f24e27a60
Allow specifying of map list to search in the query, and also max number of results.
Matti Hamalainen <ccr@tnsp.org>
parents:
1798
diff
changeset
|
629 int nmatches = 0, maxMatches, nmapList; |
1789
513c467f3a87
Implement basic search functionality. Has bugs and limitations to be rid of.
Matti Hamalainen <ccr@tnsp.org>
parents:
1786
diff
changeset
|
630 BOOL centerFound; |
1800
7c7f24e27a60
Allow specifying of map list to search in the query, and also max number of results.
Matti Hamalainen <ccr@tnsp.org>
parents:
1798
diff
changeset
|
631 size_t offs; |
7c7f24e27a60
Allow specifying of map list to search in the query, and also max number of results.
Matti Hamalainen <ccr@tnsp.org>
parents:
1798
diff
changeset
|
632 |
7c7f24e27a60
Allow specifying of map list to search in the query, and also max number of results.
Matti Hamalainen <ccr@tnsp.org>
parents:
1798
diff
changeset
|
633 // Get requested number of matches |
7c7f24e27a60
Allow specifying of map list to search in the query, and also max number of results.
Matti Hamalainen <ccr@tnsp.org>
parents:
1798
diff
changeset
|
634 for (offs = 0; offs < len && data[offs] != ':';) |
7c7f24e27a60
Allow specifying of map list to search in the query, and also max number of results.
Matti Hamalainen <ccr@tnsp.org>
parents:
1798
diff
changeset
|
635 offs++; |
7c7f24e27a60
Allow specifying of map list to search in the query, and also max number of results.
Matti Hamalainen <ccr@tnsp.org>
parents:
1798
diff
changeset
|
636 |
7c7f24e27a60
Allow specifying of map list to search in the query, and also max number of results.
Matti Hamalainen <ccr@tnsp.org>
parents:
1798
diff
changeset
|
637 if (data[offs] != ':' || offs >= len) |
7c7f24e27a60
Allow specifying of map list to search in the query, and also max number of results.
Matti Hamalainen <ccr@tnsp.org>
parents:
1798
diff
changeset
|
638 { |
7c7f24e27a60
Allow specifying of map list to search in the query, and also max number of results.
Matti Hamalainen <ccr@tnsp.org>
parents:
1798
diff
changeset
|
639 *verr = "Invalid search query."; |
7c7f24e27a60
Allow specifying of map list to search in the query, and also max number of results.
Matti Hamalainen <ccr@tnsp.org>
parents:
1798
diff
changeset
|
640 goto out; |
7c7f24e27a60
Allow specifying of map list to search in the query, and also max number of results.
Matti Hamalainen <ccr@tnsp.org>
parents:
1798
diff
changeset
|
641 } |
7c7f24e27a60
Allow specifying of map list to search in the query, and also max number of results.
Matti Hamalainen <ccr@tnsp.org>
parents:
1798
diff
changeset
|
642 |
7c7f24e27a60
Allow specifying of map list to search in the query, and also max number of results.
Matti Hamalainen <ccr@tnsp.org>
parents:
1798
diff
changeset
|
643 data[offs++] = 0; |
7c7f24e27a60
Allow specifying of map list to search in the query, and also max number of results.
Matti Hamalainen <ccr@tnsp.org>
parents:
1798
diff
changeset
|
644 |
7c7f24e27a60
Allow specifying of map list to search in the query, and also max number of results.
Matti Hamalainen <ccr@tnsp.org>
parents:
1798
diff
changeset
|
645 maxMatches = atoi((char *) data); |
1809
364e5ae52398
Clamp max number of matches differently.
Matti Hamalainen <ccr@tnsp.org>
parents:
1808
diff
changeset
|
646 THMSG(0, "Requested %d matches.\n", maxMatches); |
364e5ae52398
Clamp max number of matches differently.
Matti Hamalainen <ccr@tnsp.org>
parents:
1808
diff
changeset
|
647 |
364e5ae52398
Clamp max number of matches differently.
Matti Hamalainen <ccr@tnsp.org>
parents:
1808
diff
changeset
|
648 if (maxMatches < 1 || maxMatches > SET_MAX_MATCHES) |
1800
7c7f24e27a60
Allow specifying of map list to search in the query, and also max number of results.
Matti Hamalainen <ccr@tnsp.org>
parents:
1798
diff
changeset
|
649 maxMatches = SET_MAX_MATCHES; |
7c7f24e27a60
Allow specifying of map list to search in the query, and also max number of results.
Matti Hamalainen <ccr@tnsp.org>
parents:
1798
diff
changeset
|
650 |
7c7f24e27a60
Allow specifying of map list to search in the query, and also max number of results.
Matti Hamalainen <ccr@tnsp.org>
parents:
1798
diff
changeset
|
651 // Get active map list |
7c7f24e27a60
Allow specifying of map list to search in the query, and also max number of results.
Matti Hamalainen <ccr@tnsp.org>
parents:
1798
diff
changeset
|
652 nmapList = 0; |
7c7f24e27a60
Allow specifying of map list to search in the query, and also max number of results.
Matti Hamalainen <ccr@tnsp.org>
parents:
1798
diff
changeset
|
653 memset(&mapList, 0, sizeof(mapList)); |
7c7f24e27a60
Allow specifying of map list to search in the query, and also max number of results.
Matti Hamalainen <ccr@tnsp.org>
parents:
1798
diff
changeset
|
654 while (offs < len) |
7c7f24e27a60
Allow specifying of map list to search in the query, and also max number of results.
Matti Hamalainen <ccr@tnsp.org>
parents:
1798
diff
changeset
|
655 { |
7c7f24e27a60
Allow specifying of map list to search in the query, and also max number of results.
Matti Hamalainen <ccr@tnsp.org>
parents:
1798
diff
changeset
|
656 size_t offs2; |
7c7f24e27a60
Allow specifying of map list to search in the query, and also max number of results.
Matti Hamalainen <ccr@tnsp.org>
parents:
1798
diff
changeset
|
657 BOOL found = FALSE; |
7c7f24e27a60
Allow specifying of map list to search in the query, and also max number of results.
Matti Hamalainen <ccr@tnsp.org>
parents:
1798
diff
changeset
|
658 |
7c7f24e27a60
Allow specifying of map list to search in the query, and also max number of results.
Matti Hamalainen <ccr@tnsp.org>
parents:
1798
diff
changeset
|
659 // Find next separator or end \n |
7c7f24e27a60
Allow specifying of map list to search in the query, and also max number of results.
Matti Hamalainen <ccr@tnsp.org>
parents:
1798
diff
changeset
|
660 for (offs2 = offs; offs2 < len && data[offs2] != ':' && data[offs2] != '\n';) |
7c7f24e27a60
Allow specifying of map list to search in the query, and also max number of results.
Matti Hamalainen <ccr@tnsp.org>
parents:
1798
diff
changeset
|
661 offs2++; |
7c7f24e27a60
Allow specifying of map list to search in the query, and also max number of results.
Matti Hamalainen <ccr@tnsp.org>
parents:
1798
diff
changeset
|
662 |
7c7f24e27a60
Allow specifying of map list to search in the query, and also max number of results.
Matti Hamalainen <ccr@tnsp.org>
parents:
1798
diff
changeset
|
663 // Check against map list |
7c7f24e27a60
Allow specifying of map list to search in the query, and also max number of results.
Matti Hamalainen <ccr@tnsp.org>
parents:
1798
diff
changeset
|
664 if (offs2 > offs) |
7c7f24e27a60
Allow specifying of map list to search in the query, and also max number of results.
Matti Hamalainen <ccr@tnsp.org>
parents:
1798
diff
changeset
|
665 for (int nmap = 0; nmap < optNMaps && !found; nmap++) |
7c7f24e27a60
Allow specifying of map list to search in the query, and also max number of results.
Matti Hamalainen <ccr@tnsp.org>
parents:
1798
diff
changeset
|
666 { |
7c7f24e27a60
Allow specifying of map list to search in the query, and also max number of results.
Matti Hamalainen <ccr@tnsp.org>
parents:
1798
diff
changeset
|
667 const char *name = optMaps[nmap].locFile.continent; |
7c7f24e27a60
Allow specifying of map list to search in the query, and also max number of results.
Matti Hamalainen <ccr@tnsp.org>
parents:
1798
diff
changeset
|
668 const size_t slen = strlen(name); |
7c7f24e27a60
Allow specifying of map list to search in the query, and also max number of results.
Matti Hamalainen <ccr@tnsp.org>
parents:
1798
diff
changeset
|
669 |
7c7f24e27a60
Allow specifying of map list to search in the query, and also max number of results.
Matti Hamalainen <ccr@tnsp.org>
parents:
1798
diff
changeset
|
670 if (offs2 >= offs + slen && memcmp(data + offs, name, slen) == 0) |
7c7f24e27a60
Allow specifying of map list to search in the query, and also max number of results.
Matti Hamalainen <ccr@tnsp.org>
parents:
1798
diff
changeset
|
671 { |
7c7f24e27a60
Allow specifying of map list to search in the query, and also max number of results.
Matti Hamalainen <ccr@tnsp.org>
parents:
1798
diff
changeset
|
672 mapList[nmap] = TRUE; |
7c7f24e27a60
Allow specifying of map list to search in the query, and also max number of results.
Matti Hamalainen <ccr@tnsp.org>
parents:
1798
diff
changeset
|
673 nmapList++; |
7c7f24e27a60
Allow specifying of map list to search in the query, and also max number of results.
Matti Hamalainen <ccr@tnsp.org>
parents:
1798
diff
changeset
|
674 found = TRUE; |
7c7f24e27a60
Allow specifying of map list to search in the query, and also max number of results.
Matti Hamalainen <ccr@tnsp.org>
parents:
1798
diff
changeset
|
675 } |
7c7f24e27a60
Allow specifying of map list to search in the query, and also max number of results.
Matti Hamalainen <ccr@tnsp.org>
parents:
1798
diff
changeset
|
676 } |
7c7f24e27a60
Allow specifying of map list to search in the query, and also max number of results.
Matti Hamalainen <ccr@tnsp.org>
parents:
1798
diff
changeset
|
677 |
7c7f24e27a60
Allow specifying of map list to search in the query, and also max number of results.
Matti Hamalainen <ccr@tnsp.org>
parents:
1798
diff
changeset
|
678 if (!found) |
7c7f24e27a60
Allow specifying of map list to search in the query, and also max number of results.
Matti Hamalainen <ccr@tnsp.org>
parents:
1798
diff
changeset
|
679 { |
7c7f24e27a60
Allow specifying of map list to search in the query, and also max number of results.
Matti Hamalainen <ccr@tnsp.org>
parents:
1798
diff
changeset
|
680 *verr = "Unknown map spec."; |
7c7f24e27a60
Allow specifying of map list to search in the query, and also max number of results.
Matti Hamalainen <ccr@tnsp.org>
parents:
1798
diff
changeset
|
681 goto out; |
7c7f24e27a60
Allow specifying of map list to search in the query, and also max number of results.
Matti Hamalainen <ccr@tnsp.org>
parents:
1798
diff
changeset
|
682 } |
7c7f24e27a60
Allow specifying of map list to search in the query, and also max number of results.
Matti Hamalainen <ccr@tnsp.org>
parents:
1798
diff
changeset
|
683 |
7c7f24e27a60
Allow specifying of map list to search in the query, and also max number of results.
Matti Hamalainen <ccr@tnsp.org>
parents:
1798
diff
changeset
|
684 // Check for separator or end |
7c7f24e27a60
Allow specifying of map list to search in the query, and also max number of results.
Matti Hamalainen <ccr@tnsp.org>
parents:
1798
diff
changeset
|
685 if (data[offs2] != ':') |
7c7f24e27a60
Allow specifying of map list to search in the query, and also max number of results.
Matti Hamalainen <ccr@tnsp.org>
parents:
1798
diff
changeset
|
686 { |
7c7f24e27a60
Allow specifying of map list to search in the query, and also max number of results.
Matti Hamalainen <ccr@tnsp.org>
parents:
1798
diff
changeset
|
687 offs = offs2; |
7c7f24e27a60
Allow specifying of map list to search in the query, and also max number of results.
Matti Hamalainen <ccr@tnsp.org>
parents:
1798
diff
changeset
|
688 break; |
7c7f24e27a60
Allow specifying of map list to search in the query, and also max number of results.
Matti Hamalainen <ccr@tnsp.org>
parents:
1798
diff
changeset
|
689 } |
7c7f24e27a60
Allow specifying of map list to search in the query, and also max number of results.
Matti Hamalainen <ccr@tnsp.org>
parents:
1798
diff
changeset
|
690 else |
7c7f24e27a60
Allow specifying of map list to search in the query, and also max number of results.
Matti Hamalainen <ccr@tnsp.org>
parents:
1798
diff
changeset
|
691 offs = offs2 + 1; |
7c7f24e27a60
Allow specifying of map list to search in the query, and also max number of results.
Matti Hamalainen <ccr@tnsp.org>
parents:
1798
diff
changeset
|
692 } |
7c7f24e27a60
Allow specifying of map list to search in the query, and also max number of results.
Matti Hamalainen <ccr@tnsp.org>
parents:
1798
diff
changeset
|
693 |
7c7f24e27a60
Allow specifying of map list to search in the query, and also max number of results.
Matti Hamalainen <ccr@tnsp.org>
parents:
1798
diff
changeset
|
694 // Check for remaining data |
7c7f24e27a60
Allow specifying of map list to search in the query, and also max number of results.
Matti Hamalainen <ccr@tnsp.org>
parents:
1798
diff
changeset
|
695 if (offs + 1 >= len || data[offs] != '\n') |
7c7f24e27a60
Allow specifying of map list to search in the query, and also max number of results.
Matti Hamalainen <ccr@tnsp.org>
parents:
1798
diff
changeset
|
696 { |
7c7f24e27a60
Allow specifying of map list to search in the query, and also max number of results.
Matti Hamalainen <ccr@tnsp.org>
parents:
1798
diff
changeset
|
697 *verr = "No map pattern data!"; |
7c7f24e27a60
Allow specifying of map list to search in the query, and also max number of results.
Matti Hamalainen <ccr@tnsp.org>
parents:
1798
diff
changeset
|
698 goto out; |
7c7f24e27a60
Allow specifying of map list to search in the query, and also max number of results.
Matti Hamalainen <ccr@tnsp.org>
parents:
1798
diff
changeset
|
699 } |
7c7f24e27a60
Allow specifying of map list to search in the query, and also max number of results.
Matti Hamalainen <ccr@tnsp.org>
parents:
1798
diff
changeset
|
700 offs++; |
7c7f24e27a60
Allow specifying of map list to search in the query, and also max number of results.
Matti Hamalainen <ccr@tnsp.org>
parents:
1798
diff
changeset
|
701 |
1789
513c467f3a87
Implement basic search functionality. Has bugs and limitations to be rid of.
Matti Hamalainen <ccr@tnsp.org>
parents:
1786
diff
changeset
|
702 // Parse pattern block dimensions |
1800
7c7f24e27a60
Allow specifying of map list to search in the query, and also max number of results.
Matti Hamalainen <ccr@tnsp.org>
parents:
1798
diff
changeset
|
703 mapBlockGetDimensions(data + offs, len - offs, &width, &height); |
1789
513c467f3a87
Implement basic search functionality. Has bugs and limitations to be rid of.
Matti Hamalainen <ccr@tnsp.org>
parents:
1786
diff
changeset
|
704 if (width <= 0 || height <= 0) |
513c467f3a87
Implement basic search functionality. Has bugs and limitations to be rid of.
Matti Hamalainen <ccr@tnsp.org>
parents:
1786
diff
changeset
|
705 { |
513c467f3a87
Implement basic search functionality. Has bugs and limitations to be rid of.
Matti Hamalainen <ccr@tnsp.org>
parents:
1786
diff
changeset
|
706 *verr = "Could not parse map block dimensions."; |
513c467f3a87
Implement basic search functionality. Has bugs and limitations to be rid of.
Matti Hamalainen <ccr@tnsp.org>
parents:
1786
diff
changeset
|
707 goto out; |
513c467f3a87
Implement basic search functionality. Has bugs and limitations to be rid of.
Matti Hamalainen <ccr@tnsp.org>
parents:
1786
diff
changeset
|
708 } |
513c467f3a87
Implement basic search functionality. Has bugs and limitations to be rid of.
Matti Hamalainen <ccr@tnsp.org>
parents:
1786
diff
changeset
|
709 |
513c467f3a87
Implement basic search functionality. Has bugs and limitations to be rid of.
Matti Hamalainen <ccr@tnsp.org>
parents:
1786
diff
changeset
|
710 if (width * height < 3) |
513c467f3a87
Implement basic search functionality. Has bugs and limitations to be rid of.
Matti Hamalainen <ccr@tnsp.org>
parents:
1786
diff
changeset
|
711 { |
513c467f3a87
Implement basic search functionality. Has bugs and limitations to be rid of.
Matti Hamalainen <ccr@tnsp.org>
parents:
1786
diff
changeset
|
712 *verr = "Search block pattern too small."; |
513c467f3a87
Implement basic search functionality. Has bugs and limitations to be rid of.
Matti Hamalainen <ccr@tnsp.org>
parents:
1786
diff
changeset
|
713 goto out; |
513c467f3a87
Implement basic search functionality. Has bugs and limitations to be rid of.
Matti Hamalainen <ccr@tnsp.org>
parents:
1786
diff
changeset
|
714 } |
513c467f3a87
Implement basic search functionality. Has bugs and limitations to be rid of.
Matti Hamalainen <ccr@tnsp.org>
parents:
1786
diff
changeset
|
715 |
513c467f3a87
Implement basic search functionality. Has bugs and limitations to be rid of.
Matti Hamalainen <ccr@tnsp.org>
parents:
1786
diff
changeset
|
716 if ((pattern = mapBlockAlloc(width, height)) == NULL) |
513c467f3a87
Implement basic search functionality. Has bugs and limitations to be rid of.
Matti Hamalainen <ccr@tnsp.org>
parents:
1786
diff
changeset
|
717 goto out; |
513c467f3a87
Implement basic search functionality. Has bugs and limitations to be rid of.
Matti Hamalainen <ccr@tnsp.org>
parents:
1786
diff
changeset
|
718 |
1800
7c7f24e27a60
Allow specifying of map list to search in the query, and also max number of results.
Matti Hamalainen <ccr@tnsp.org>
parents:
1798
diff
changeset
|
719 if (!mapBlockParse(data + offs, len - offs, pattern)) |
1789
513c467f3a87
Implement basic search functionality. Has bugs and limitations to be rid of.
Matti Hamalainen <ccr@tnsp.org>
parents:
1786
diff
changeset
|
720 { |
513c467f3a87
Implement basic search functionality. Has bugs and limitations to be rid of.
Matti Hamalainen <ccr@tnsp.org>
parents:
1786
diff
changeset
|
721 *verr = "Error parsing map block data."; |
513c467f3a87
Implement basic search functionality. Has bugs and limitations to be rid of.
Matti Hamalainen <ccr@tnsp.org>
parents:
1786
diff
changeset
|
722 goto out; |
513c467f3a87
Implement basic search functionality. Has bugs and limitations to be rid of.
Matti Hamalainen <ccr@tnsp.org>
parents:
1786
diff
changeset
|
723 } |
513c467f3a87
Implement basic search functionality. Has bugs and limitations to be rid of.
Matti Hamalainen <ccr@tnsp.org>
parents:
1786
diff
changeset
|
724 |
513c467f3a87
Implement basic search functionality. Has bugs and limitations to be rid of.
Matti Hamalainen <ccr@tnsp.org>
parents:
1786
diff
changeset
|
725 // Entropy check |
513c467f3a87
Implement basic search functionality. Has bugs and limitations to be rid of.
Matti Hamalainen <ccr@tnsp.org>
parents:
1786
diff
changeset
|
726 int entropy = mapBlockGetEntropy(pattern, optCleanChars, strlen(optCleanChars)); |
513c467f3a87
Implement basic search functionality. Has bugs and limitations to be rid of.
Matti Hamalainen <ccr@tnsp.org>
parents:
1786
diff
changeset
|
727 |
513c467f3a87
Implement basic search functionality. Has bugs and limitations to be rid of.
Matti Hamalainen <ccr@tnsp.org>
parents:
1786
diff
changeset
|
728 if ((entropy < 2 && width < 10 && height < 10) || |
513c467f3a87
Implement basic search functionality. Has bugs and limitations to be rid of.
Matti Hamalainen <ccr@tnsp.org>
parents:
1786
diff
changeset
|
729 (entropy < 3 && width * height < 6)) |
513c467f3a87
Implement basic search functionality. Has bugs and limitations to be rid of.
Matti Hamalainen <ccr@tnsp.org>
parents:
1786
diff
changeset
|
730 { |
513c467f3a87
Implement basic search functionality. Has bugs and limitations to be rid of.
Matti Hamalainen <ccr@tnsp.org>
parents:
1786
diff
changeset
|
731 *verr = "Search block entropy insufficient."; |
513c467f3a87
Implement basic search functionality. Has bugs and limitations to be rid of.
Matti Hamalainen <ccr@tnsp.org>
parents:
1786
diff
changeset
|
732 goto out; |
513c467f3a87
Implement basic search functionality. Has bugs and limitations to be rid of.
Matti Hamalainen <ccr@tnsp.org>
parents:
1786
diff
changeset
|
733 } |
513c467f3a87
Implement basic search functionality. Has bugs and limitations to be rid of.
Matti Hamalainen <ccr@tnsp.org>
parents:
1786
diff
changeset
|
734 |
513c467f3a87
Implement basic search functionality. Has bugs and limitations to be rid of.
Matti Hamalainen <ccr@tnsp.org>
parents:
1786
diff
changeset
|
735 // Find pattern center marker, if any |
1810
72850f9a91dc
Oops, forgot this change from the strchr() related commit.
Matti Hamalainen <ccr@tnsp.org>
parents:
1809
diff
changeset
|
736 centerFound = mapBlockFindCenter(pattern, (unsigned char*) "*@", 2, ¢erX, ¢erY, 20); |
1789
513c467f3a87
Implement basic search functionality. Has bugs and limitations to be rid of.
Matti Hamalainen <ccr@tnsp.org>
parents:
1786
diff
changeset
|
737 |
513c467f3a87
Implement basic search functionality. Has bugs and limitations to be rid of.
Matti Hamalainen <ccr@tnsp.org>
parents:
1786
diff
changeset
|
738 // Clean the pattern from characters we do not want to match |
513c467f3a87
Implement basic search functionality. Has bugs and limitations to be rid of.
Matti Hamalainen <ccr@tnsp.org>
parents:
1786
diff
changeset
|
739 mapBlockClean(pattern, optCleanChars); |
513c467f3a87
Implement basic search functionality. Has bugs and limitations to be rid of.
Matti Hamalainen <ccr@tnsp.org>
parents:
1786
diff
changeset
|
740 |
1796 | 741 // |
742 // Search the maps .. enabled or if none specified, all of them | |
743 // | |
1789
513c467f3a87
Implement basic search functionality. Has bugs and limitations to be rid of.
Matti Hamalainen <ccr@tnsp.org>
parents:
1786
diff
changeset
|
744 for (int nmap = 0; nmap < optNMaps; nmap++) |
1800
7c7f24e27a60
Allow specifying of map list to search in the query, and also max number of results.
Matti Hamalainen <ccr@tnsp.org>
parents:
1798
diff
changeset
|
745 if (mapList[nmap] || nmapList == 0) |
1789
513c467f3a87
Implement basic search functionality. Has bugs and limitations to be rid of.
Matti Hamalainen <ccr@tnsp.org>
parents:
1786
diff
changeset
|
746 { |
513c467f3a87
Implement basic search functionality. Has bugs and limitations to be rid of.
Matti Hamalainen <ccr@tnsp.org>
parents:
1786
diff
changeset
|
747 MAPInfoCtx *info = &optMaps[nmap]; |
513c467f3a87
Implement basic search functionality. Has bugs and limitations to be rid of.
Matti Hamalainen <ccr@tnsp.org>
parents:
1786
diff
changeset
|
748 |
513c467f3a87
Implement basic search functionality. Has bugs and limitations to be rid of.
Matti Hamalainen <ccr@tnsp.org>
parents:
1786
diff
changeset
|
749 for (int oy = 0; oy < info->map->height - height - 1; oy++) |
513c467f3a87
Implement basic search functionality. Has bugs and limitations to be rid of.
Matti Hamalainen <ccr@tnsp.org>
parents:
1786
diff
changeset
|
750 for (int ox = 0; ox < info->map->width - width - 1; ox++) |
513c467f3a87
Implement basic search functionality. Has bugs and limitations to be rid of.
Matti Hamalainen <ccr@tnsp.org>
parents:
1786
diff
changeset
|
751 { |
1796 | 752 // Check for match |
1789
513c467f3a87
Implement basic search functionality. Has bugs and limitations to be rid of.
Matti Hamalainen <ccr@tnsp.org>
parents:
1786
diff
changeset
|
753 double accuracy = mapMatchBlock(info->map, pattern, ox, oy, 0, TRUE); |
513c467f3a87
Implement basic search functionality. Has bugs and limitations to be rid of.
Matti Hamalainen <ccr@tnsp.org>
parents:
1786
diff
changeset
|
754 if (accuracy > 99.5f) |
513c467f3a87
Implement basic search functionality. Has bugs and limitations to be rid of.
Matti Hamalainen <ccr@tnsp.org>
parents:
1786
diff
changeset
|
755 { |
1796 | 756 // Okay, add the match to our list |
1789
513c467f3a87
Implement basic search functionality. Has bugs and limitations to be rid of.
Matti Hamalainen <ccr@tnsp.org>
parents:
1786
diff
changeset
|
757 MAPMatch *match = &matches[nmatches++]; |
513c467f3a87
Implement basic search functionality. Has bugs and limitations to be rid of.
Matti Hamalainen <ccr@tnsp.org>
parents:
1786
diff
changeset
|
758 |
513c467f3a87
Implement basic search functionality. Has bugs and limitations to be rid of.
Matti Hamalainen <ccr@tnsp.org>
parents:
1786
diff
changeset
|
759 match->map = info->locFile.continent; |
513c467f3a87
Implement basic search functionality. Has bugs and limitations to be rid of.
Matti Hamalainen <ccr@tnsp.org>
parents:
1786
diff
changeset
|
760 match->mx = ox + centerX; |
513c467f3a87
Implement basic search functionality. Has bugs and limitations to be rid of.
Matti Hamalainen <ccr@tnsp.org>
parents:
1786
diff
changeset
|
761 match->my = oy + centerY; |
513c467f3a87
Implement basic search functionality. Has bugs and limitations to be rid of.
Matti Hamalainen <ccr@tnsp.org>
parents:
1786
diff
changeset
|
762 match->wx = optWorldXC + info->locFile.x + ox + centerX; |
513c467f3a87
Implement basic search functionality. Has bugs and limitations to be rid of.
Matti Hamalainen <ccr@tnsp.org>
parents:
1786
diff
changeset
|
763 match->wy = optWorldYC + info->locFile.y + oy + centerY; |
513c467f3a87
Implement basic search functionality. Has bugs and limitations to be rid of.
Matti Hamalainen <ccr@tnsp.org>
parents:
1786
diff
changeset
|
764 match->accuracy = accuracy; |
513c467f3a87
Implement basic search functionality. Has bugs and limitations to be rid of.
Matti Hamalainen <ccr@tnsp.org>
parents:
1786
diff
changeset
|
765 match->centered = centerFound; |
513c467f3a87
Implement basic search functionality. Has bugs and limitations to be rid of.
Matti Hamalainen <ccr@tnsp.org>
parents:
1786
diff
changeset
|
766 |
1812
cfb623a04f77
No need to doublecheck for SET_MAX_MATCHES.
Matti Hamalainen <ccr@tnsp.org>
parents:
1811
diff
changeset
|
767 // Check for max matches |
cfb623a04f77
No need to doublecheck for SET_MAX_MATCHES.
Matti Hamalainen <ccr@tnsp.org>
parents:
1811
diff
changeset
|
768 if (nmatches >= maxMatches) |
1789
513c467f3a87
Implement basic search functionality. Has bugs and limitations to be rid of.
Matti Hamalainen <ccr@tnsp.org>
parents:
1786
diff
changeset
|
769 goto out; |
513c467f3a87
Implement basic search functionality. Has bugs and limitations to be rid of.
Matti Hamalainen <ccr@tnsp.org>
parents:
1786
diff
changeset
|
770 } |
513c467f3a87
Implement basic search functionality. Has bugs and limitations to be rid of.
Matti Hamalainen <ccr@tnsp.org>
parents:
1786
diff
changeset
|
771 } |
513c467f3a87
Implement basic search functionality. Has bugs and limitations to be rid of.
Matti Hamalainen <ccr@tnsp.org>
parents:
1786
diff
changeset
|
772 } |
513c467f3a87
Implement basic search functionality. Has bugs and limitations to be rid of.
Matti Hamalainen <ccr@tnsp.org>
parents:
1786
diff
changeset
|
773 |
513c467f3a87
Implement basic search functionality. Has bugs and limitations to be rid of.
Matti Hamalainen <ccr@tnsp.org>
parents:
1786
diff
changeset
|
774 out: |
513c467f3a87
Implement basic search functionality. Has bugs and limitations to be rid of.
Matti Hamalainen <ccr@tnsp.org>
parents:
1786
diff
changeset
|
775 mapBlockFree(pattern); |
513c467f3a87
Implement basic search functionality. Has bugs and limitations to be rid of.
Matti Hamalainen <ccr@tnsp.org>
parents:
1786
diff
changeset
|
776 |
1801
03db1dc33af9
Handle "no matches" differently, also fix a memory leak.
Matti Hamalainen <ccr@tnsp.org>
parents:
1800
diff
changeset
|
777 // If an error occured, bail out now |
1789
513c467f3a87
Implement basic search functionality. Has bugs and limitations to be rid of.
Matti Hamalainen <ccr@tnsp.org>
parents:
1786
diff
changeset
|
778 if (*verr != NULL) |
513c467f3a87
Implement basic search functionality. Has bugs and limitations to be rid of.
Matti Hamalainen <ccr@tnsp.org>
parents:
1786
diff
changeset
|
779 return; |
513c467f3a87
Implement basic search functionality. Has bugs and limitations to be rid of.
Matti Hamalainen <ccr@tnsp.org>
parents:
1786
diff
changeset
|
780 |
1801
03db1dc33af9
Handle "no matches" differently, also fix a memory leak.
Matti Hamalainen <ccr@tnsp.org>
parents:
1800
diff
changeset
|
781 // We got some matches, output them as a JSON array |
03db1dc33af9
Handle "no matches" differently, also fix a memory leak.
Matti Hamalainen <ccr@tnsp.org>
parents:
1800
diff
changeset
|
782 char *buf = NULL; |
03db1dc33af9
Handle "no matches" differently, also fix a memory leak.
Matti Hamalainen <ccr@tnsp.org>
parents:
1800
diff
changeset
|
783 size_t bufLen = 0, bufSize = 0; |
1789
513c467f3a87
Implement basic search functionality. Has bugs and limitations to be rid of.
Matti Hamalainen <ccr@tnsp.org>
parents:
1786
diff
changeset
|
784 |
1801
03db1dc33af9
Handle "no matches" differently, also fix a memory leak.
Matti Hamalainen <ccr@tnsp.org>
parents:
1800
diff
changeset
|
785 th_strbuf_puts(&buf, &bufSize, &bufLen, "RESULT:["); |
1789
513c467f3a87
Implement basic search functionality. Has bugs and limitations to be rid of.
Matti Hamalainen <ccr@tnsp.org>
parents:
1786
diff
changeset
|
786 |
1801
03db1dc33af9
Handle "no matches" differently, also fix a memory leak.
Matti Hamalainen <ccr@tnsp.org>
parents:
1800
diff
changeset
|
787 for (int n = 0; n < nmatches; n++) |
03db1dc33af9
Handle "no matches" differently, also fix a memory leak.
Matti Hamalainen <ccr@tnsp.org>
parents:
1800
diff
changeset
|
788 { |
03db1dc33af9
Handle "no matches" differently, also fix a memory leak.
Matti Hamalainen <ccr@tnsp.org>
parents:
1800
diff
changeset
|
789 MAPMatch *match = &matches[n]; |
03db1dc33af9
Handle "no matches" differently, also fix a memory leak.
Matti Hamalainen <ccr@tnsp.org>
parents:
1800
diff
changeset
|
790 char *vstr = th_strdup_printf( |
03db1dc33af9
Handle "no matches" differently, also fix a memory leak.
Matti Hamalainen <ccr@tnsp.org>
parents:
1800
diff
changeset
|
791 "[%1.2f,%d,\"%s\",%d,%d,%d,%d]%s", |
03db1dc33af9
Handle "no matches" differently, also fix a memory leak.
Matti Hamalainen <ccr@tnsp.org>
parents:
1800
diff
changeset
|
792 match->accuracy, |
03db1dc33af9
Handle "no matches" differently, also fix a memory leak.
Matti Hamalainen <ccr@tnsp.org>
parents:
1800
diff
changeset
|
793 match->centered, |
03db1dc33af9
Handle "no matches" differently, also fix a memory leak.
Matti Hamalainen <ccr@tnsp.org>
parents:
1800
diff
changeset
|
794 match->map, |
03db1dc33af9
Handle "no matches" differently, also fix a memory leak.
Matti Hamalainen <ccr@tnsp.org>
parents:
1800
diff
changeset
|
795 match->mx, match->my, |
03db1dc33af9
Handle "no matches" differently, also fix a memory leak.
Matti Hamalainen <ccr@tnsp.org>
parents:
1800
diff
changeset
|
796 match->wx, match->wy, |
03db1dc33af9
Handle "no matches" differently, also fix a memory leak.
Matti Hamalainen <ccr@tnsp.org>
parents:
1800
diff
changeset
|
797 (n < nmatches - 1) ? "," : ""); |
1789
513c467f3a87
Implement basic search functionality. Has bugs and limitations to be rid of.
Matti Hamalainen <ccr@tnsp.org>
parents:
1786
diff
changeset
|
798 |
1801
03db1dc33af9
Handle "no matches" differently, also fix a memory leak.
Matti Hamalainen <ccr@tnsp.org>
parents:
1800
diff
changeset
|
799 th_strbuf_puts(&buf, &bufSize, &bufLen, vstr); |
03db1dc33af9
Handle "no matches" differently, also fix a memory leak.
Matti Hamalainen <ccr@tnsp.org>
parents:
1800
diff
changeset
|
800 th_free(vstr); |
03db1dc33af9
Handle "no matches" differently, also fix a memory leak.
Matti Hamalainen <ccr@tnsp.org>
parents:
1800
diff
changeset
|
801 } |
1789
513c467f3a87
Implement basic search functionality. Has bugs and limitations to be rid of.
Matti Hamalainen <ccr@tnsp.org>
parents:
1786
diff
changeset
|
802 |
1801
03db1dc33af9
Handle "no matches" differently, also fix a memory leak.
Matti Hamalainen <ccr@tnsp.org>
parents:
1800
diff
changeset
|
803 th_strbuf_puts(&buf, &bufSize, &bufLen, "]"); |
03db1dc33af9
Handle "no matches" differently, also fix a memory leak.
Matti Hamalainen <ccr@tnsp.org>
parents:
1800
diff
changeset
|
804 lws_write(wsi, (unsigned char *) buf, bufLen, LWS_WRITE_TEXT); |
03db1dc33af9
Handle "no matches" differently, also fix a memory leak.
Matti Hamalainen <ccr@tnsp.org>
parents:
1800
diff
changeset
|
805 th_free(buf); |
1789
513c467f3a87
Implement basic search functionality. Has bugs and limitations to be rid of.
Matti Hamalainen <ccr@tnsp.org>
parents:
1786
diff
changeset
|
806 } |
513c467f3a87
Implement basic search functionality. Has bugs and limitations to be rid of.
Matti Hamalainen <ccr@tnsp.org>
parents:
1786
diff
changeset
|
807 |
513c467f3a87
Implement basic search functionality. Has bugs and limitations to be rid of.
Matti Hamalainen <ccr@tnsp.org>
parents:
1786
diff
changeset
|
808 |
1784
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
809 int mapLWSCallback(struct lws *wsi, |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
810 enum lws_callback_reasons reason, |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
811 void *user, void *in, size_t len) |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
812 { |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
813 (void) user; |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
814 |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
815 switch (reason) |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
816 { |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
817 case LWS_CALLBACK_CLIENT_WRITEABLE: |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
818 THPRINT(0, "Connection established.\n"); |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
819 break; |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
820 |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
821 case LWS_CALLBACK_RECEIVE: |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
822 { |
1789
513c467f3a87
Implement basic search functionality. Has bugs and limitations to be rid of.
Matti Hamalainen <ccr@tnsp.org>
parents:
1786
diff
changeset
|
823 char *data = (char *) in; |
513c467f3a87
Implement basic search functionality. Has bugs and limitations to be rid of.
Matti Hamalainen <ccr@tnsp.org>
parents:
1786
diff
changeset
|
824 unsigned char *udata = (unsigned char *) in; |
513c467f3a87
Implement basic search functionality. Has bugs and limitations to be rid of.
Matti Hamalainen <ccr@tnsp.org>
parents:
1786
diff
changeset
|
825 char *verr = NULL; |
513c467f3a87
Implement basic search functionality. Has bugs and limitations to be rid of.
Matti Hamalainen <ccr@tnsp.org>
parents:
1786
diff
changeset
|
826 |
1796 | 827 // Check what the request is about? |
1800
7c7f24e27a60
Allow specifying of map list to search in the query, and also max number of results.
Matti Hamalainen <ccr@tnsp.org>
parents:
1798
diff
changeset
|
828 if (len >= 10 && strncmp(data, "MAPSEARCH:", 10) == 0) |
1789
513c467f3a87
Implement basic search functionality. Has bugs and limitations to be rid of.
Matti Hamalainen <ccr@tnsp.org>
parents:
1786
diff
changeset
|
829 { |
1796 | 830 // A map search query! |
1789
513c467f3a87
Implement basic search functionality. Has bugs and limitations to be rid of.
Matti Hamalainen <ccr@tnsp.org>
parents:
1786
diff
changeset
|
831 if (len <= 10 + 1) |
1797 | 832 verr = "Invalid search query."; |
1789
513c467f3a87
Implement basic search functionality. Has bugs and limitations to be rid of.
Matti Hamalainen <ccr@tnsp.org>
parents:
1786
diff
changeset
|
833 else |
513c467f3a87
Implement basic search functionality. Has bugs and limitations to be rid of.
Matti Hamalainen <ccr@tnsp.org>
parents:
1786
diff
changeset
|
834 mapPerformSearch(wsi, udata + 10, len - 10, &verr); |
513c467f3a87
Implement basic search functionality. Has bugs and limitations to be rid of.
Matti Hamalainen <ccr@tnsp.org>
parents:
1786
diff
changeset
|
835 } |
513c467f3a87
Implement basic search functionality. Has bugs and limitations to be rid of.
Matti Hamalainen <ccr@tnsp.org>
parents:
1786
diff
changeset
|
836 else |
1790
24e23feca10a
Add server functionality to provide list of maps available for searching,
Matti Hamalainen <ccr@tnsp.org>
parents:
1789
diff
changeset
|
837 if (len >= 7 && strncmp(data, "GETMAPS", 7) == 0) |
24e23feca10a
Add server functionality to provide list of maps available for searching,
Matti Hamalainen <ccr@tnsp.org>
parents:
1789
diff
changeset
|
838 { |
1796 | 839 // Client wants a list of available maps |
1790
24e23feca10a
Add server functionality to provide list of maps available for searching,
Matti Hamalainen <ccr@tnsp.org>
parents:
1789
diff
changeset
|
840 char *buf = NULL; |
24e23feca10a
Add server functionality to provide list of maps available for searching,
Matti Hamalainen <ccr@tnsp.org>
parents:
1789
diff
changeset
|
841 size_t bufLen = 0, bufSize = 0; |
24e23feca10a
Add server functionality to provide list of maps available for searching,
Matti Hamalainen <ccr@tnsp.org>
parents:
1789
diff
changeset
|
842 |
24e23feca10a
Add server functionality to provide list of maps available for searching,
Matti Hamalainen <ccr@tnsp.org>
parents:
1789
diff
changeset
|
843 th_strbuf_puts(&buf, &bufSize, &bufLen, "MAPS:["); |
24e23feca10a
Add server functionality to provide list of maps available for searching,
Matti Hamalainen <ccr@tnsp.org>
parents:
1789
diff
changeset
|
844 |
24e23feca10a
Add server functionality to provide list of maps available for searching,
Matti Hamalainen <ccr@tnsp.org>
parents:
1789
diff
changeset
|
845 for (int n = 0; n < optNMaps; n++) |
24e23feca10a
Add server functionality to provide list of maps available for searching,
Matti Hamalainen <ccr@tnsp.org>
parents:
1789
diff
changeset
|
846 { |
24e23feca10a
Add server functionality to provide list of maps available for searching,
Matti Hamalainen <ccr@tnsp.org>
parents:
1789
diff
changeset
|
847 MAPInfoCtx *info = &optMaps[n]; |
24e23feca10a
Add server functionality to provide list of maps available for searching,
Matti Hamalainen <ccr@tnsp.org>
parents:
1789
diff
changeset
|
848 char *vstr = th_strdup_printf( |
24e23feca10a
Add server functionality to provide list of maps available for searching,
Matti Hamalainen <ccr@tnsp.org>
parents:
1789
diff
changeset
|
849 "[\"%s\",%d,%d]%s", |
24e23feca10a
Add server functionality to provide list of maps available for searching,
Matti Hamalainen <ccr@tnsp.org>
parents:
1789
diff
changeset
|
850 info->locFile.continent, |
24e23feca10a
Add server functionality to provide list of maps available for searching,
Matti Hamalainen <ccr@tnsp.org>
parents:
1789
diff
changeset
|
851 info->locFile.x + optWorldXC, |
24e23feca10a
Add server functionality to provide list of maps available for searching,
Matti Hamalainen <ccr@tnsp.org>
parents:
1789
diff
changeset
|
852 info->locFile.y + optWorldYC, |
24e23feca10a
Add server functionality to provide list of maps available for searching,
Matti Hamalainen <ccr@tnsp.org>
parents:
1789
diff
changeset
|
853 (n < optNMaps - 1) ? "," : ""); |
24e23feca10a
Add server functionality to provide list of maps available for searching,
Matti Hamalainen <ccr@tnsp.org>
parents:
1789
diff
changeset
|
854 |
24e23feca10a
Add server functionality to provide list of maps available for searching,
Matti Hamalainen <ccr@tnsp.org>
parents:
1789
diff
changeset
|
855 th_strbuf_puts(&buf, &bufSize, &bufLen, vstr); |
24e23feca10a
Add server functionality to provide list of maps available for searching,
Matti Hamalainen <ccr@tnsp.org>
parents:
1789
diff
changeset
|
856 th_free(vstr); |
24e23feca10a
Add server functionality to provide list of maps available for searching,
Matti Hamalainen <ccr@tnsp.org>
parents:
1789
diff
changeset
|
857 } |
24e23feca10a
Add server functionality to provide list of maps available for searching,
Matti Hamalainen <ccr@tnsp.org>
parents:
1789
diff
changeset
|
858 |
24e23feca10a
Add server functionality to provide list of maps available for searching,
Matti Hamalainen <ccr@tnsp.org>
parents:
1789
diff
changeset
|
859 th_strbuf_puts(&buf, &bufSize, &bufLen, "]"); |
24e23feca10a
Add server functionality to provide list of maps available for searching,
Matti Hamalainen <ccr@tnsp.org>
parents:
1789
diff
changeset
|
860 lws_write(wsi, (unsigned char *) buf, bufLen, LWS_WRITE_TEXT); |
24e23feca10a
Add server functionality to provide list of maps available for searching,
Matti Hamalainen <ccr@tnsp.org>
parents:
1789
diff
changeset
|
861 } |
24e23feca10a
Add server functionality to provide list of maps available for searching,
Matti Hamalainen <ccr@tnsp.org>
parents:
1789
diff
changeset
|
862 else |
1789
513c467f3a87
Implement basic search functionality. Has bugs and limitations to be rid of.
Matti Hamalainen <ccr@tnsp.org>
parents:
1786
diff
changeset
|
863 { |
1796 | 864 // Unknown or invalid query |
1789
513c467f3a87
Implement basic search functionality. Has bugs and limitations to be rid of.
Matti Hamalainen <ccr@tnsp.org>
parents:
1786
diff
changeset
|
865 verr = "Invalid command/search query, not enough data."; |
513c467f3a87
Implement basic search functionality. Has bugs and limitations to be rid of.
Matti Hamalainen <ccr@tnsp.org>
parents:
1786
diff
changeset
|
866 } |
513c467f3a87
Implement basic search functionality. Has bugs and limitations to be rid of.
Matti Hamalainen <ccr@tnsp.org>
parents:
1786
diff
changeset
|
867 |
1796 | 868 // Check for errors .. |
1789
513c467f3a87
Implement basic search functionality. Has bugs and limitations to be rid of.
Matti Hamalainen <ccr@tnsp.org>
parents:
1786
diff
changeset
|
869 if (verr != NULL) |
513c467f3a87
Implement basic search functionality. Has bugs and limitations to be rid of.
Matti Hamalainen <ccr@tnsp.org>
parents:
1786
diff
changeset
|
870 { |
513c467f3a87
Implement basic search functionality. Has bugs and limitations to be rid of.
Matti Hamalainen <ccr@tnsp.org>
parents:
1786
diff
changeset
|
871 THERR("%s\n", verr); |
513c467f3a87
Implement basic search functionality. Has bugs and limitations to be rid of.
Matti Hamalainen <ccr@tnsp.org>
parents:
1786
diff
changeset
|
872 char *vstr = th_strdup_printf("ERROR:%s", verr); |
513c467f3a87
Implement basic search functionality. Has bugs and limitations to be rid of.
Matti Hamalainen <ccr@tnsp.org>
parents:
1786
diff
changeset
|
873 lws_write(wsi, (unsigned char *) vstr, strlen(vstr), LWS_WRITE_TEXT); |
513c467f3a87
Implement basic search functionality. Has bugs and limitations to be rid of.
Matti Hamalainen <ccr@tnsp.org>
parents:
1786
diff
changeset
|
874 th_free(vstr); |
513c467f3a87
Implement basic search functionality. Has bugs and limitations to be rid of.
Matti Hamalainen <ccr@tnsp.org>
parents:
1786
diff
changeset
|
875 } |
513c467f3a87
Implement basic search functionality. Has bugs and limitations to be rid of.
Matti Hamalainen <ccr@tnsp.org>
parents:
1786
diff
changeset
|
876 |
1796 | 877 // End communication |
1789
513c467f3a87
Implement basic search functionality. Has bugs and limitations to be rid of.
Matti Hamalainen <ccr@tnsp.org>
parents:
1786
diff
changeset
|
878 verr = "END"; |
513c467f3a87
Implement basic search functionality. Has bugs and limitations to be rid of.
Matti Hamalainen <ccr@tnsp.org>
parents:
1786
diff
changeset
|
879 lws_write(wsi, (unsigned char *) verr, strlen(verr), LWS_WRITE_TEXT); |
1784
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
880 lws_close_reason(wsi, LWS_CLOSE_STATUS_NOSTATUS, NULL, 0); |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
881 } |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
882 break; |
1796 | 883 |
1784
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
884 default: |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
885 break; |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
886 } |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
887 |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
888 return 0; |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
889 } |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
890 |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
891 |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
892 static const struct lws_extension mapLWSExtensions[] = |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
893 { |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
894 { |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
895 "permessage-deflate", |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
896 lws_extension_callback_pm_deflate, |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
897 "permessage-deflate" |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
898 }, |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
899 { |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
900 "deflate-frame", |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
901 lws_extension_callback_pm_deflate, |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
902 "deflate_frame" |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
903 }, |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
904 { NULL, NULL, NULL } |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
905 }; |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
906 |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
907 |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
908 static const struct lws_protocols mapLWSProtocols[] = |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
909 { |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
910 { "default", &mapLWSCallback, 0, 0, 0, NULL }, |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
911 { NULL, NULL, 0, 0, 0, NULL } |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
912 }; |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
913 |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
914 |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
915 int main(int argc, char *argv[]) |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
916 { |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
917 |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
918 // Initialize |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
919 th_init("MapSearch", "Map Search WebSockets server", "0.1", NULL, NULL); |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
920 th_verbosityLevel = 0; |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
921 |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
922 memset(&optMaps, 0, sizeof(optMaps)); |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
923 memset(&optListenTo, 0, sizeof(optListenTo)); |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
924 |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
925 // Parse command line arguments |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
926 BOOL argsOK = th_args_process(argc, argv, optList, optListN, argHandleOpt, argHandleFile, 0); |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
927 |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
928 if (!argsOK) |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
929 return -2; |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
930 |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
931 if (optNMaps == 0) |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
932 { |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
933 THERR("No maps specified.\n"); |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
934 goto exit; |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
935 } |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
936 |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
937 if (optNListenTo == 0) |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
938 { |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
939 THERR("No listeners specified.\n"); |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
940 goto exit; |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
941 } |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
942 |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
943 // Load maps |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
944 THMSG(1, "Trying to load %d map specs ..\n", optNMaps); |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
945 for (int n = 0; n < optNMaps; n++) |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
946 { |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
947 MAPInfoCtx *info = &optMaps[n]; |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
948 FILE *fh; |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
949 |
1797 | 950 THMSG(1, "Map ID '%s', data '%s', locations '%s' @ %d, %d\n", |
1784
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
951 info->locFile.continent, |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
952 info->mapFilename, |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
953 info->locFile.filename, |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
954 info->locFile.x, info->locFile.y); |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
955 |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
956 if ((info->map = mapBlockParseFile(info->mapFilename, FALSE)) == NULL) |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
957 { |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
958 THERR("Could not read map data file '%s'.\n", info->mapFilename); |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
959 goto exit; |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
960 } |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
961 |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
962 if ((fh = fopen(info->locFile.filename, "rb")) == NULL) |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
963 { |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
964 THERR("Could not open location file '%s' for reading.\n", |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
965 info->locFile.filename); |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
966 goto exit; |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
967 } |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
968 |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
969 if (!locParseLocStream(fh, &info->locFile, &(info->loc), info->locFile.x, info->locFile.y)) |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
970 { |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
971 fclose(fh); |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
972 goto exit; |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
973 } |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
974 |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
975 fclose(fh); |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
976 } |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
977 |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
978 // Initialize libwebsockets and create context |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
979 THMSG(1, "Creating libwebsockets context.\n"); |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
980 |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
981 MAPListenerCtx *ctx = optListenTo[0]; |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
982 struct lws_context_creation_info info; |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
983 memset(&info, 0, sizeof(info)); |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
984 |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
985 info.port = ctx->port; |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
986 info.iface = ctx->interface; |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
987 info.max_http_header_pool = 16; |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
988 info.options = |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
989 LWS_SERVER_OPTION_EXPLICIT_VHOSTS | |
1806 | 990 LWS_SERVER_OPTION_VALIDATE_UTF8 | |
991 LWS_SERVER_OPTION_DO_SSL_GLOBAL_INIT | | |
992 LWS_SERVER_OPTION_LIBUV; // do we need this? | |
1784
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
993 |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
994 info.protocols = mapLWSProtocols; |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
995 info.extensions = mapLWSExtensions; |
1814
daf7dcc635d6
Improve SSL/TLS support by adding vhost name to the SSL listener spec and set
Matti Hamalainen <ccr@tnsp.org>
parents:
1812
diff
changeset
|
996 info.ssl_cipher_list = optSSLCipherList; |
1784
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
997 info.timeout_secs = 5; |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
998 |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
999 if ((setLWSContext = lws_create_context(&info)) == NULL) |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1000 { |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1001 THERR("libwebsocket initialization failed.\n"); |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1002 goto exit; |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1003 } |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1004 |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1005 // Create listener LWS vhosts .. |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1006 for (int n = 0; n < optNListenTo; n++) |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1007 { |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1008 ctx = optListenTo[n]; |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1009 |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1010 if (ctx->useSSL) |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1011 { |
1814
daf7dcc635d6
Improve SSL/TLS support by adding vhost name to the SSL listener spec and set
Matti Hamalainen <ccr@tnsp.org>
parents:
1812
diff
changeset
|
1012 THMSG(1, "Listen to %s:%d (wss) [vhost='%s', cert='%s', key='%s', ca='%s']\n", |
1784
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1013 ctx->interface != NULL ? ctx->interface : "*", ctx->port, |
1814
daf7dcc635d6
Improve SSL/TLS support by adding vhost name to the SSL listener spec and set
Matti Hamalainen <ccr@tnsp.org>
parents:
1812
diff
changeset
|
1014 ctx->vhostname, |
1784
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1015 ctx->sslCertFile, ctx->sslKeyFile, ctx->sslCAFile); |
1814
daf7dcc635d6
Improve SSL/TLS support by adding vhost name to the SSL listener spec and set
Matti Hamalainen <ccr@tnsp.org>
parents:
1812
diff
changeset
|
1016 |
daf7dcc635d6
Improve SSL/TLS support by adding vhost name to the SSL listener spec and set
Matti Hamalainen <ccr@tnsp.org>
parents:
1812
diff
changeset
|
1017 info.vhost_name = ctx->vhostname; |
daf7dcc635d6
Improve SSL/TLS support by adding vhost name to the SSL listener spec and set
Matti Hamalainen <ccr@tnsp.org>
parents:
1812
diff
changeset
|
1018 info.ssl_cert_filepath = ctx->sslCertFile; |
daf7dcc635d6
Improve SSL/TLS support by adding vhost name to the SSL listener spec and set
Matti Hamalainen <ccr@tnsp.org>
parents:
1812
diff
changeset
|
1019 info.ssl_private_key_filepath = ctx->sslKeyFile; |
daf7dcc635d6
Improve SSL/TLS support by adding vhost name to the SSL listener spec and set
Matti Hamalainen <ccr@tnsp.org>
parents:
1812
diff
changeset
|
1020 info.ssl_ca_filepath = ctx->sslCAFile[0] ? ctx->sslCAFile : NULL; |
1784
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1021 } |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1022 else |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1023 { |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1024 THMSG(1, "Listen to %s:%d (ws)\n", |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1025 ctx->interface != NULL ? ctx->interface : "*", ctx->port); |
1814
daf7dcc635d6
Improve SSL/TLS support by adding vhost name to the SSL listener spec and set
Matti Hamalainen <ccr@tnsp.org>
parents:
1812
diff
changeset
|
1026 |
daf7dcc635d6
Improve SSL/TLS support by adding vhost name to the SSL listener spec and set
Matti Hamalainen <ccr@tnsp.org>
parents:
1812
diff
changeset
|
1027 info.vhost_name = NULL; |
daf7dcc635d6
Improve SSL/TLS support by adding vhost name to the SSL listener spec and set
Matti Hamalainen <ccr@tnsp.org>
parents:
1812
diff
changeset
|
1028 info.ssl_cert_filepath = NULL; |
daf7dcc635d6
Improve SSL/TLS support by adding vhost name to the SSL listener spec and set
Matti Hamalainen <ccr@tnsp.org>
parents:
1812
diff
changeset
|
1029 info.ssl_private_key_filepath = NULL; |
daf7dcc635d6
Improve SSL/TLS support by adding vhost name to the SSL listener spec and set
Matti Hamalainen <ccr@tnsp.org>
parents:
1812
diff
changeset
|
1030 info.ssl_ca_filepath = NULL; |
1784
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1031 } |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1032 |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1033 info.port = ctx->port; |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1034 info.iface = ctx->interface; |
1806 | 1035 |
1784
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1036 if ((ctx->vhost = lws_create_vhost(setLWSContext, &info)) == NULL) |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1037 { |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1038 THERR("LWS vhost creation failed!\n"); |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1039 goto exit; |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1040 } |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1041 } |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1042 |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1043 // Set up signal handlers |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1044 THMSG(1, "Setting up signal handlers.\n"); |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1045 lws_uv_sigint_cfg(setLWSContext, 1, mapSigHandler); |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1046 |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1047 THMSG(1, "Waiting for connections...\n"); |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1048 if (lws_uv_initloop(setLWSContext, NULL, 0)) |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1049 { |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1050 THERR("lws_uv_initloop() failed.\n"); |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1051 goto exit; |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1052 } |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1053 |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1054 // Start running .. |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1055 lws_libuv_run(setLWSContext, 0); |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1056 |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1057 exit: |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1058 // Shutdown sequence |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1059 THMSG(1, "Server shutting down.\n"); |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1060 |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1061 if (setLWSContext != NULL) |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1062 lws_context_destroy(setLWSContext); |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1063 |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1064 for (int n = 0; n < optNListenTo; n++) |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1065 mapFreeListenCtx(optListenTo[n]); |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1066 |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1067 for (int n = 0; n < optNMaps; n++) |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1068 { |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1069 MAPInfoCtx *info = &optMaps[n]; |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1070 |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1071 th_free(info->mapFilename); |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1072 th_free(info->locFile.filename); |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1073 th_free(info->locFile.continent); |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1074 |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1075 mapBlockFree(info->map); |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1076 locFreeMapLocations(&info->loc); |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1077 } |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1078 |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1079 return 0; |
9ee269ae165d
Initial import of map search WebSockets server code. Does not actually do
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1080 } |