コード例 #1
0
void process_client(void *arg)
{
	char a;
	t_rinoosocket *socket = arg;

	rinoo_log("server - client accepted");
	rinoo_log("server - receiving nothing, waiting timeout");
	XTEST(rinoo_socket_read(socket, &a, 1) <= 0);
	rinoo_socket_destroy(socket);
}
コード例 #2
0
ファイル: dns.c プロジェクト: kastnerkyle/librinoo
void dns_test(void *arg)
{
	t_ip ip;

	XTEST(rinoo_dns_ip_get(arg, "google.com", &ip) == 0);
	rinoo_log("IP: %s", inet_ntoa(ip.v4.sin_addr));
}
コード例 #3
0
ファイル: util.c プロジェクト: reginaldl/rinoosmtpc
/**
 * Resolv an hostname to an IP address.
 *
 * @param hostname Pointer to the hostname to convert.
 * @param ip Pointer to an ip structure where to store the result.
 *
 * @return 0 on success, or -1 if an error occurs.
 */
int rsc_getip(char *hostname, t_ip *ip)
{
	int res;
	struct addrinfo hints;
	struct addrinfo *infos;

	memset(&hints, 0, sizeof(struct addrinfo));
	hints.ai_family = AF_UNSPEC;
	hints.ai_socktype = SOCK_STREAM;
	hints.ai_flags = AI_PASSIVE;
	hints.ai_protocol = 0;
	hints.ai_canonname = NULL;
	hints.ai_addr = NULL;
	hints.ai_next = NULL;
	res = getaddrinfo(hostname, NULL, &hints, &infos);
	if (res != 0) {
		rinoo_log("%s", gai_strerror(res));
		return -1;
	}
	if (infos->ai_family == AF_INET) {
		ip->v4 = *((struct sockaddr_in *) infos->ai_addr);
	} else if (infos->ai_family == AF_INET6) {
		ip->v6 = *((struct sockaddr_in6 *) infos->ai_addr);
	} else {
		freeaddrinfo(infos);
		return -1;
	}
	freeaddrinfo(infos);
	return 0;
}
コード例 #4
0
ファイル: rinoo_fs_browse.c プロジェクト: dyu/librinoo
/**
 * Main function for this unit test.
 *
 *
 * @return 0 if test passed
 */
int main()
{
	t_fs_entry *entry = NULL;

	while (rinoo_fs_browse(".", &entry) == 0 && entry != NULL) {
		rinoo_log("%s", buffer_ptr(entry->path));
	}
	XPASS();
}
コード例 #5
0
ファイル: rsc.c プロジェクト: reginaldl/rinoosmtpc
int main(int argc, char **argv)
{
    sched = rinoo_sched();
    if (sched == NULL) {
        return -1;
    }
    config = rsc_config_create();
    if (config == NULL) {
        rinoo_log("could not create configuration");
        rinoo_sched_destroy(sched);
        return -1;
    }
    if (rsc_config_parse_options(argc, argv, config) != 0) {
        rsc_config_destroy(config);
        rinoo_sched_destroy(sched);
        return -1;
    }
    if (signal(SIGINT, sig_handler) == SIG_ERR) {
        rsc_config_destroy(config);
        rinoo_sched_destroy(sched);
        return -1;
    }
    if (config->gui) {
        if (rsc_ui_start(sched) != 0) {
            rinoo_log("could not start web server");
            rsc_config_destroy(config);
            rinoo_sched_destroy(sched);
            return -1;
        }
        thread_counter++;
    }
    if (rsc_start(sched) != 0) {
        rinoo_log("could not create threads");
        rsc_config_destroy(config);
        rinoo_sched_destroy(sched);
        return -1;
    }
    rinoo_sched_loop(sched);
    rinoo_sched_destroy(sched);
    rsc_stats();
    rsc_log(config, RSC_LOG_REPORT, "Report - Sent: %d Failed: %d Total: %d", config->stats.all.sent, config->stats.all.failed, config->stats.all.sent + config->stats.all.failed);
    rsc_config_destroy(config);
    return 0;
}
コード例 #6
0
void client_func(void *arg)
{
	char a;
	struct sockaddr_in6 addr = { 0 };
	t_rinoosocket *socket;
	t_rinoosched *sched = arg;

	socket = rinoo_socket(sched, &socket_class_tcp6);
	XTEST(socket != NULL);
	addr.sin6_port = htons(4242);
	addr.sin6_family = AF_INET6;
	addr.sin6_addr = in6addr_loopback;
	XTEST(rinoo_socket_connect(socket, (struct sockaddr *) &addr, sizeof(addr)) == 0);
	rinoo_log("client - connected");
	rinoo_socket_timeout(socket, 1000);
	XTEST(rinoo_socket_read(socket, &a, 1) == -1);
	rinoo_log("server  - timeout");
	perror("socket");
	rinoo_socket_destroy(socket);
}
コード例 #7
0
ファイル: rinoo_inotify.c プロジェクト: dyu/librinoo
void event_generator(void *sched)
{
	int i;
	int fd;
	char path[100];

	rinoo_task_wait(sched, 200);
	for (i = 0; i < NB_EVENT / 2; i++) {
		snprintf(path, sizeof(path), TEST_DIRECTORY ".inotify.XXXXXX");
		fd = mkstemp(path);
		close(fd);
		rinoo_log("Event generator: file created.");
		nb_create++;
		rinoo_task_wait(sched, 200);
		unlink(path);
		nb_rm++;
		rinoo_log("Event generator: file removed.");
		rinoo_task_wait(sched, 200);
	}
}
コード例 #8
0
ファイル: rinoo_inotify.c プロジェクト: dyu/librinoo
void check_file(void *sched)
{
	int i;
	t_inotify *inotify;
	t_inotify_event *event;

	inotify = rinoo_inotify(sched);
	rinoo_inotify_add_watch(inotify, "/tmp", INOTIFY_CREATE | INOTIFY_DELETE, true);
	for (i = 0; i < NB_EVENT && (event = rinoo_inotify_event(inotify)) != NULL; i++) {
		if (event->type & INOTIFY_CREATE) {
			rinoo_log("File created.");
			nb_create_event++;
		} else if (event->type & INOTIFY_DELETE) {
			rinoo_log("File deleted.");
			nb_rm_event++;
		}
	}
	XTEST(nb_create_event == nb_create);
	XTEST(nb_rm_event == nb_rm);
	rinoo_inotify_destroy(inotify);
}
コード例 #9
0
void process_client(void *arg)
{
	int i;
	char b;
	t_buffer *buffers[4];
	t_buffer buffer[4];
	t_rinoosocket *socket = arg;

	buffer_static(&buffer[0], big_buffer, BUFFER_SIZE);
	buffers[0] = &buffer[0];
	rinoo_log("server - client accepted");
	rinoo_log("server - sending %d bytes", BUFFER_SIZE);
	XTEST(rinoo_socket_writev(socket, buffers, 1) == BUFFER_SIZE);
	rinoo_log("server - receiving 'b'");
	XTEST(rinoo_socket_read(socket, &b, 1) == 1);
	XTEST(b == 'b');
	for (i = 0; i < 4; i++) {
		buffer_static(&buffer[i], big_buffer + (i * (BUFFER_SIZE / 4)), BUFFER_SIZE / 4);
		buffers[i] = &buffer[i];
	}
	rinoo_log("server - sending %d bytes", BUFFER_SIZE);
	XTEST(rinoo_socket_writev(socket, buffers, 4) == BUFFER_SIZE);
	rinoo_log("server - receiving 'b'");
	XTEST(rinoo_socket_read(socket, &b, 1) == 1);
	XTEST(b == 'b');
	rinoo_log("server - receiving nothing");
	XTEST(rinoo_socket_read(socket, &b, 1) == -1);
	rinoo_socket_destroy(socket);
}
コード例 #10
0
ファイル: rinoo_socket_readb.c プロジェクト: dyu/librinoo
void server_func(void *unused(arg))
{
	t_socket *server;
	t_socket *client;

	server = rinoo_tcp_server(rinoo_sched_self(), IP_ANY, 4242);
	XTEST(server != NULL);
	client = rinoo_tcp_accept(server, NULL, NULL);
	XTEST(client != NULL);
	rinoo_log("client accepted");
	rinoo_task_start(rinoo_sched_self(), process_client, client);
	rinoo_socket_destroy(server);
}
コード例 #11
0
ファイル: rinoo_socket_readb.c プロジェクト: dyu/librinoo
void process_client(void *socket)
{
	t_buffer *buffer;

	buffer = buffer_create(NULL);
	XTEST(buffer != NULL);
	while (rinoo_socket_readb(socket, buffer) > 0) {
		rinoo_log("receiving...");
	}
	XTEST(buffer_size(buffer) == TRANSFER_SIZE);
	XTEST(buffer_strncmp(buffer, str, TRANSFER_SIZE) == 0);
	buffer_destroy(buffer);
	free(str);
	rinoo_socket_destroy(socket);
}
コード例 #12
0
ファイル: http.c プロジェクト: dyu/librinoo
void http_server(void *sched)
{
	t_ip ip;
	uint16_t port;
	t_socket *server;
	t_socket *client;

	server = rinoo_tcp_server(sched, IP_ANY, 4242);
	XTEST(server != NULL);
	client = rinoo_tcp_accept(server, &ip, &port);
	XTEST(client != NULL);
	rinoo_log("server - accepting client (%s:%d)", inet_ntoa(*(struct in_addr *) &ip), port);
	rinoo_task_start(sched, http_server_process, client);
	rinoo_socket_destroy(server);
}
コード例 #13
0
void client_func(void *arg)
{
	int i;
	ssize_t res;
	ssize_t total;
	char tmp[8];
	struct sockaddr_in6 addr = { 0 };
	t_rinoosocket *socket;
	t_rinoosched *sched = arg;

	socket = rinoo_socket(sched, &socket_class_tcp6);
	XTEST(socket != NULL);
	addr.sin6_port = htons(4242);
	addr.sin6_family = AF_INET6;
	addr.sin6_addr = in6addr_loopback;
	XTEST(rinoo_socket_connect(socket, (struct sockaddr *) &addr, sizeof(addr)) == 0);
	rinoo_log("client - connected");
	rinoo_log("client - reading %d bytes", BUFFER_SIZE);
	for (i = 0; i < BUFFER_SIZE / 8; i++) {
		res = 0;
		total = 0;
		while (total < 8 && (res = rinoo_socket_read(socket, tmp + total, 8 - total)) > 0) {
			total += res;
		}
		if (res < 0) {
			rinoo_log("Error: %s", strerror(errno));
		}
		XTEST(res > 0);
		XTEST(memcmp(tmp, "xxxxxxxx", 8) == 0);
	}
	rinoo_log("client - sending 'b'");
	rinoo_log("client - reading %d bytes", BUFFER_SIZE);
	XTEST(rinoo_socket_write(socket, "b", 1) == 1);
	for (i = 0; i < BUFFER_SIZE / 8; i++) {
		res = 0;
		total = 0;
		while (total < 8 && (res = rinoo_socket_read(socket, tmp + total, 8 - total)) > 0) {
			total += res;
		}
		if (res < 0) {
			rinoo_log("Error: %s", strerror(errno));
		}
		XTEST(res > 0);
		XTEST(memcmp(tmp, "xxxxxxxx", 8) == 0);
	}
	rinoo_log("client - sending 'b'");
	XTEST(rinoo_socket_write(socket, "b", 1) == 1);
	rinoo_socket_destroy(socket);
}
コード例 #14
0
void *server_thread(void *unused(arg))
{
	char b;
	t_rinoosched *sched;
	t_rinoosocket *server;
	t_rinoosocket *client;
	struct sockaddr_in addr;

	sched = rinoo_sched();
	XTEST(sched != NULL);
	server = rinoo_socket(sched, &socket_class_tcp);
	XTEST(server != NULL);
	addr.sin_port = htons(4242);
	addr.sin_family = AF_INET;
	addr.sin_addr.s_addr = 0;
	XTEST(rinoo_socket_bind(server, (struct sockaddr *) &addr, sizeof(addr), 42) == 0);
	rinoo_log("server listening...");
	client = rinoo_socket_accept(server, (struct sockaddr *) &addr, (socklen_t *)(int[]){(sizeof(struct sockaddr))});
コード例 #15
0
void server_func(void *arg)
{
	t_rinoosocket *server;
	t_rinoosocket *client;
	struct sockaddr_in6 addr = { 0 };
	t_rinoosched *sched = arg;

	server = rinoo_socket(sched, &socket_class_tcp6);
	XTEST(server != NULL);
	addr.sin6_port = htons(4242);
	addr.sin6_family = AF_INET6;
	addr.sin6_addr = in6addr_any;
	XTEST(rinoo_socket_bind(server, (struct sockaddr *) &addr, sizeof(addr), 42) == 0);
	rinoo_log("server listening...");
	client = rinoo_socket_accept(server, NULL, NULL);
	XTEST(client != NULL);
	rinoo_task_start(sched, process_client, client);
	rinoo_socket_destroy(server);
}
コード例 #16
0
ファイル: rinoo_task_wait.c プロジェクト: dyu/librinoo
int check_time(struct timeval *prev, uint32_t ms)
{
	uint32_t diffms;
	struct timeval cur;
	struct timeval diff;

	if (gettimeofday(&cur, NULL) != 0) {
		return -1;
	}
	timersub(&cur, prev, &diff);
	diffms = diff.tv_sec * 1000;
	diffms += diff.tv_usec / 1000;
	rinoo_log("Time diff found: %u, expected: %u - %u", diffms, ms, LATENCY);
	if (diffms > ms) {
		diffms = diffms - ms;
	} else {
		diffms = ms - diffms;
	}
	if (diffms > LATENCY) {
		return -1;
	}
	*prev = cur;
	return 0;
}
コード例 #17
0
ファイル: rsc.c プロジェクト: reginaldl/rinoosmtpc
void rsc_start_client(void *client_sched)
{
    bool redo;
    uint32_t i;
    t_email email;
    t_session session = { 0 };

    redo = true;
    email = *config->email;
    session.email = &email;
    session.helo = config->session.helo;
    session.read = buffer_create(NULL);
    if (session.read == NULL) {
        goto send_error;
    }
    session.write = buffer_create(NULL);
    if (session.write == NULL) {
        goto send_error;
    }
    rinoo_email_session_set(&email, &session);
    while (redo) {
        session.socket = rinoo_tcp_client(client_sched, &config->connection.ip, config->connection.port, config->connection.timeout * 1000);
        if (session.socket == NULL) {
            rinoo_log("Error: %s", strerror(errno));
            config->stats.thread[rinoo_sched_self()->id].failed++;
            rsc_log(config, RSC_LOG_ERROR, "Couldn't create socket to %s:%d", config->connection.server, config->connection.port);
            goto send_error;
        }
        config->stats.thread[rinoo_sched_self()->id].sessions++;
        if (rinoo_smtp_start(&email) != 0) {
            goto send_error;
        }
        for (i = 0; i < config->session.nbmsg; i++) {
            if (rinoo_smtp_send(&email) != 0) {
                goto send_error;
            }
            config->stats.thread[rinoo_sched_self()->id].sent++;
        }
        if (rinoo_smtp_end(&email) != 0) {
            goto send_error;
        }
        rinoo_socket_destroy(session.socket);
        session.socket = NULL;
        config->stats.thread[rinoo_sched_self()->id].sessions--;
        if (config->mode == RSC_MODE_SECOND) {
            if (rinoo_task_wait(client_sched, 1000) != 0) {
                goto send_error;
            }
        } else if (config->mode != RSC_MODE_FLOOD) {
            redo = false;
        }
    }
send_error:
    if (session.read != NULL) {
        buffer_destroy(session.read);
    }
    if (session.write != NULL) {
        buffer_destroy(session.write);
    }
    if (session.socket != NULL) {
        config->stats.thread[rinoo_sched_self()->id].sessions--;
        config->stats.thread[rinoo_sched_self()->id].failed++;
        rinoo_socket_destroy(session.socket);
    }
    if (__atomic_fetch_sub(&thread_counter, 1, __ATOMIC_SEQ_CST) == 1) {
        sched->stop = true;
    }
}