Where is the configuration file (init.d) in g-wan. Also how do I get rid of the '?' In the url to run php or c script ( I think you need to change this in the configure)?
-
**/etc/init.d** files are shell scripts that respond to start, stop, restart, and reload commands to manage a particular service. G-WAN provides an example of such a script: http://www.gwan.ch/faq#service – Gil Jun 19 '15 at 07:27
2 Answers
As Ken explained, there's no configuration file - but G-WAN scripts (servlets
, handlers
), including the init.c
and main.c
G-WAN startup scripts, can modify G-WAN by-default settings... even dynamically, during the life of the server, and sometimes on a per-request basis.
Here are the options that can be changed before G-WAN starts listening (they are documented in the PDF manual and on the G-WAN Web site):
US_SERVER_DATA // global server pointer for user-defined data
SERVER_SOFTWARE // "Server: G-WAN" HTTP response header
SCRIPT_TMO // time-out in ms running a script
KALIVE_TMO // time-out in ms for HTTP keep-alives
REQUEST_TMO // time-out in ms waiting for request
MIN_SEND_SPEED // send rate in bytes/sec (if < close)
MIN_READ_SPEED // read rate in bytes/sec (if < close)
MAX_ENTITY_SIZE // maximum POST entity size
QUERY_CHAR // replace '?' by - _ . ! ~ * ' ( )
USE_WWW_CACHE // enable static cache (default: off)
USE_CSP_CACHE // enable servlet cache (default: off)
CACHE_ALL_WWW // load all /www in cache (default: off)
USE_MINIFYING // enable JS/CSS/HTML minifying (default: off)
And here is how to change the default query character '?':
u8 *query_char = (u8*)get_env(argv, QUERY_CHAR);
if(query_char)
{
u8 old = *query_char;
*query_char = '!'; // "/!hello.c" instead of "/?hello.c"
printf("> changed query_char from '%c' to '%c' (%p)\n",
old, *query_char, query_char);
}
To completely remove the '?' (rather than replacing it) you will have to use a G-WAN connection handler, see this example just doing what you want on tab #2 'connection handlers'.
In many cases, dynamic settings are preferable to fixed options, like for adaptive timeouts (fixed timeouts leave a server vulnerable to timing attacks, like Slowloris
).

- 3,279
- 1
- 15
- 25
-
I don't want to change it. I want to remove it. Do there no directorship character – matt Jun 16 '15 at 12:52
-
Then write a G-WAN handler to add it for a specific list of dynamic URLs (that clients will use without specifying any '?'). That's what other servers do with regex engines. – Gil Jun 16 '15 at 13:16
-
u8 *query_char = (u8*)get_env(argv, QUERY_CHAR); if(query_char) { u8 old = *query_char; *query_char = ''; // "/!hello.c" instead of "/?hello.c" printf("> changed query_char from '%c' to '%c' (%p)\n", old, *query_char, query_char); } – matt Jun 16 '15 at 13:22
-
Empty characters are a syntax error in C. And if it were not the case, G-WAN would then not process any dynamic request since that's the query character that defines one. – Gil Jun 16 '15 at 13:29
-
-
Added it to the solution above, the link is http://www.gwan.ch/developers#handler, check the 2nd tab called 'connection handler'. Can you accept the answer above now? – Gil Jun 17 '15 at 14:21
There is no configuration "file" per se. For example, port and IP address are configured as folder names (e.g., 172.16.42.2:8080/...) under the root gwan folder.
Servlets, whether written in php or C or whatever you choose, are in the .../csp folder under the IP:port path under the gwan folder. With G-WAN, by default, the path to a servlet begins with '?' followed by the servlet name AND extension (e.g., '.php'), and the first parameter is preceded by '&' like the 2nd - nth parameter is with most web servers.
You can change virtually ANYTHING you want about the URL, path, special characters, etc. in a handler, which you can also write in C/C++, etc. Handlers are in the .../handler folder under the IP:port path under the gwan folder. What you are asking about specifically is a form of URL-rewriting, and can be done in a handler via a simple string-replacement function (see the examples that come with G-WAN).
There are MANY examples of servlets in the .../csp folder, and several examples of handlers in the .../handler folder. Most likely you can choose among those and modify them to meet your needs.
FYI, typical naming convention used with G-WAN to disable something at a folder level is to precede it with '_' (e.g., _0.0.0.0:8080/...), and for an individual file to be disabled it is postfixed with '_' (e.g., hello.c_).
The G-WAN developers page has a Connection Handler URL-rewrite example that (I think) does what you want. The specific code to rewrite an incoming request URL (containing no "?") with a URL that references a specific G-WAN servlet (and contains the "?") looks like this:
// rewrite /blog requests into /?blog requests
xbuf_replfrto(read_xbuf, read_xbuf->ptr, read_xbuf->ptr + 16, "/blog", "/?blog");
See http://gwan.com/developers#tab2 for the complete example. You will need to create a similar Connection Handler (or just copy the example code and change to meet you needs), and then place that Handler code in the .../handlers path under the IP:port path under the gwan root folder.
Sorry I can't be more specific with a PHP example; I've done all my G-WAN work in C/C++ so far.

- 448
- 6
- 16
-
-
I'm not at my computer at the moment, but there is an example either online or in the gwan package for changing a URL from /blog to /?blog.c or something like that. Very close to what you want. Have you looked under FAQ or API or Developers on the gwan web site? – Kenigmatic Jun 15 '15 at 18:01
-
Thanks I will have a look. But if you get a chance I will appreciate it if you could give an examplanation/ example. Thanks. – matt Jun 15 '15 at 18:05
-
@Matt, I added a link to a URL-rewrite example that I think is what you are trying to do. It allows the client (e.g., browser) to request a URL that contains no "?", and rewrites the URL in place so that the request goes to a Servlet that has the "?" in the appropriate location (for G-WAN). – Kenigmatic Jun 16 '15 at 19:05
-
@matt, what exactly causes an error? Can you update your original question with the specific thing you are trying and the resulting error? – Kenigmatic Jun 21 '15 at 18:47