int hw_init_with_config(configuration* configuration) { #ifdef DEBUG char route[] = "/stats"; hw_http_add_route(route, get_server_stats); #endif /* DEBUG */ config = configuration; return 0; }
int main() { char route[] = "/"; configuration config; config.http_listen_address = "0.0.0.0"; config.http_listen_port = 8000; /* hw_init_from_config("hello_world.conf"); */ hw_init_with_config(&config); hw_http_add_route(route, get_root); hw_http_open(); return 0; }
int hw_init_with_config(configuration* configuration) { int http_listen_address_length; #ifdef DEBUG char route[] = "/stats"; hw_http_add_route(route, get_server_stats); #endif /* DEBUG */ /* Copy the configuration */ http_listen_address_length = strlen(configuration->http_listen_address); config = malloc(sizeof(configuration)); config->http_listen_address = malloc(http_listen_address_length + 1); memcpy(config->http_listen_address, configuration->http_listen_address, http_listen_address_length + 1); config->http_listen_port = configuration->http_listen_port; return 0; }
int hw_init_with_config(configuration* c) { int http_listen_address_length; #ifdef DEBUG char route[] = "/stats"; hw_http_add_route(route, get_server_stats, NULL); #endif /* DEBUG */ /* Copy the configuration */ config = malloc(sizeof(configuration)); config->http_listen_address = dupstr(c->http_listen_address); config->http_listen_port = c->http_listen_port; http_v1_0 = create_string("HTTP/1.0 "); http_v1_1 = create_string("HTTP/1.1 "); server_name = create_string("Server: Haywire/master"); return 0; }
int main(int args, char** argsv) { char route[] = "/"; configuration config; config.http_listen_address = "0.0.0.0"; if (args > 1) { config.http_listen_port = atoi(argsv[1]); } else { config.http_listen_port = 8000; } /* hw_init_from_config("hello_world.conf"); */ hw_init_with_config(&config); hw_http_add_route(route, get_root, NULL); hw_http_open(0); return 0; }