Пример #1
0
int main(int ac, char *av[])
{
	printf("Usage: echo2 [host|localhost [port|12345 [tcp|1 [ssl|0 [loops|10 [quiet|0 [threads:0]]]]]]]\n");
	const char *host = ac>1?av[1]:"localhost";
	unsigned short port = (short)(ac>2?atoi(av[2]):12345);
	int tcp = (ac>3?atoi(av[3]):1);
	int ssl = (ac>4?atoi(av[4]):0);
	g_loops = (ac>5?atoi(av[5]):10);
	g_quiet = (ac>6?atoi(av[6]):0);
	int threads = (ac>7?atoi(av[7]):0);

	session *s = session_open(host, port, tcp, ssl);
	if (!s) return 1;

	handler *h = handler_create(threads);
	handler_add_client(h, &on_session, NULL, s);

	// Start the loop...

	if (session_writemsg(s, hello) <= 0)
	{
		printf("write: %s\n", strerror(errno));
		return 1;
	}

	handler_wait(h);
	printf("DONE\n");
	handler_destroy(h);
	return 0;
}
Пример #2
0
gboolean speech_manager_load(speech_manager_t* self, gchar* plugin_name) {
    gchar* path;
    speech_handler_t* handler;
    
    path = g_strconcat(self->plugin_dir, "lib", plugin_name, ".so", NULL);
    
    printf("speech::manager::load(): plugin: [%s]\n", plugin_name);
    printf("speech::manager::load(): path:   [%s]\n", path);
    if (!strlen(path)) {
        printf("Arquivo de plugin inválido\n");
        return FALSE;
    }
    
    handler = handler_create(path);
    printf("speech::manager::load(): handler: [%p]\n", handler);
    if (!handler) {
        printf("Falha ao criar handler do plugin de fala\n");
        return FALSE;
    }
    
    printf("Liberando memória da variável 'path' [%p]\n", path);
    g_free(path);
    
    handler->instance = (*(handler->create))(self->argc, self->argv);
    if (!handler->instance) {
        printf("Falha ao criar instância do plugin %s\n", plugin_name);
        handler_destroy(handler);
        return FALSE;
    }
    printf("Criada instância do plugin %s em [%p]\n", plugin_name,
        handler->instance);
        
    self->handler = handler;
    
    return TRUE;
}
Пример #3
0
int main(int ac, char *av[])
{
	const char *binding = NULL;
	unsigned short port = HTTP_DEFAULT_PORT, uncle_port = UNCLE_DEFAULT_PORT;
	int ssl = 0, threads = 0;
	const char *path1 = "./db";
	const char *path2 = NULL;
	int i;

	for (i = 1; i < ac; i++)
	{
		char tmpbuf[256];
		tmpbuf[0] = 0;
		unsigned tmp = 0;

		if (!strncmp(av[i], "--port=", 7))
		{
			sscanf(av[i], "%*[^=]=%u", &tmp);
			port = (short)tmp;
		}
		else if (!strncmp(av[i], "--uncle=", 8))
		{
			sscanf(av[i], "%*[^=]=%u", &tmp);
			uncle_port = (short)tmp;
		}
		else if (!strncmp(av[i], "--threads=", 10))
		{
			sscanf(av[i], "%*[^=]=%u", &tmp);
			threads = (short)tmp;
		}
		else if (!strncmp(av[i], "--ssl=", 6))
		{
			sscanf(av[i], "%*[^=]=%u", &tmp);
			ssl = (short)tmp;
		}
		else if (!strcmp(av[i], "--ssl"))
		{
			ssl = 1;
		}
		else if (!strncmp(av[i], "--tls=", 6))
		{
			sscanf(av[i], "%*[^=]=%u", &tmp);
			ssl = (short)tmp;
		}
		else if (!strcmp(av[i], "--tls"))
		{
			ssl = 1;
		}
		else if (!strncmp(av[i], "--debug=", 8))
		{
			sscanf(av[i], "%*[^=]=%u", &tmp);
			g_http_debug = (short)tmp;
		}
		else if (!strcmp(av[i], "--debug"))
		{
			g_http_debug = 1;
		}
		else if (!strncmp(av[i], "--path=", 7))
		{
			sscanf(av[i], "%*[^=]=%s", tmpbuf);
			tmpbuf[sizeof(tmpbuf)-1] = 0;
			path1 = strdup(tmpbuf);
		}
		else if (!strncmp(av[i], "--path1=", 8))
		{
			sscanf(av[i], "%*[^=]=%s", tmpbuf);
			tmpbuf[sizeof(tmpbuf)-1] = 0;
			path1 = strdup(tmpbuf);
		}
		else if (!strncmp(av[i], "--path2=", 8))
		{
			sscanf(av[i], "%*[^=]=%s", tmpbuf);
			tmpbuf[sizeof(tmpbuf)-1] = 0;
			path2 = strdup(tmpbuf);
		}
	}

	printf("Usage: lindad --port=%u --ssl=%d --debug=%d --threads=%d --path=%s --uncle=%u\n", port, ssl, g_http_debug, threads, path1, uncle_port);

	handler *h = handler_create(threads);
	if (!h) return 1;

	if (ssl)
		handler_set_tls(h, "server.pem");

	if (uncle_port != 0)
	{
		if (!handler_add_uncle(h, NULL, (short)uncle_port, SCOPE_DEFAULT))
			return 2;
	}

	linda *l = linda_open(path1, path2);
	if (!l) return 3;

	struct httpserver_reqs_ reqs[] =
	{
		{&linda_request, "linda", l},	// http://server/linda
		{&http_request, NULL, NULL},	// ... others ...
		{0}
	};

	httpserver *http = httpserver_create2(reqs);
	if (!http) return 4;

	if (!handler_add_server(h, &httpserver_handler, http, binding, port, 1, ssl, LINDA_SERVICE))
		return 5;

	handler_wait(h);
	handler_destroy(h);
	httpserver_destroy(http);
	linda_close(l);
	return 0;
}