#define _POSIX_C_SOURCE 200112L #include #include #include #include "log.h" static char *res = "1Entry 1 /entry1 localhost 3000\r\n\ 1Entry 2 /entry2 localhost 3000\r\n\ 1Entry 3 /entry3 localhost 3000\r\n\ ."; static char *res1 = "0SubEntry 1 /entry1 localhost 3000\r\n\ 0SubEntry 2 /entry2 localhost 3000\r\n\ 0SubEntry 3 /entry3 localhost 3000\r\n\ ."; static int sendall(int fd, const char *buf, size_t len) { size_t sent = 0; ssize_t n; while (sent < len) { n = send(fd, buf + sent, len - sent, 0); if (n == -1) { perror("send"); return -1; } sent += n; } return 0; } int handle_path(int fd, const char *path) { const char *data; if (strcmp(path, "") == 0 || strcmp(path, "/") == 0) { data = res; } else if (strcmp(path, "/entry1") == 0) { data = res1; } else { data = ""; } if (sendall(fd, data, strlen(data)) == -1) { logmsg(LOG_INFO, "failed to send data"); return -1; } return 0; }