#include #include #include #include #include #include #include "dpi.h" #include "io.h" int dpi_check_auth(int fd) { char buf[30]; unsigned key[4], local_key[4]; char keys[128]; char *home; ssize_t sz; int rc; rc = read_all(fd, (unsigned char *)buf, 28); if (rc < 0) return -1; buf[29] = '\0'; // first byte was read already rc = sscanf(buf, "cmd='auth' msg='%4x' '>", key); if (rc < 1) { errno = EPROTO; return -1; } home = getenv("HOME"); if (!home) home = "."; sz = read_file(keys, sizeof(keys), "%s/.dillo/dpid_comm_keys", home); if (sz < 0) { errno = ENOKEY; return -1; } rc = sscanf(keys, "%*d %4x", local_key); if (rc < 1) { errno = ENOKEY; return -1; } if (memcmp(key, local_key, 4)) { errno = EKEYREJECTED; return -1; } return 0; } int dpi_read_request(int fd, char *url_buf, size_t url_len) { char buf[21]; size_t len; int rc; size_t i; rc = read_all(fd, (unsigned char *)buf, sizeof(buf)); if (rc < 0 && errno == EPIPE && !strncmp(buf, "", 16)) { errno = ESHUTDOWN; return -1; } if (rc < 0) return -1; if (strncmp(buf, " len-3 || strncmp(url_buf + i, "' '>", 4)) { errno = EPROTO; return -1; } url_buf[i] = '\0'; return 0; } int dpi_send_status(int fd, const char *status) { return dprintf(fd, "", status); } int dpi_send_header(int fd, const char *content_type) { return dprintf(fd, "" "Content-Type: %s\n\n", content_type); } int dpi_reload(int fd) { return dprintf(fd, ""); }