Connection *fake_conn(const char *file, int mode) { Connection *conn = calloc(sizeof(Connection), 1); assert(conn && "Failed to create connection."); int fd = open(file, mode); assert(fd != -1 && "Failed to open file."); conn->iob = IOBuf_create(10 * 1024, fd, IOBUF_FILE); assert(conn->iob && "Failed to create iobuffer."); conn->type = CONN_TYPE_HTTP; Register_connect(fd, conn); return conn; }
int Connection_accept(Connection *conn) { check(Register_connect(IOBuf_fd(conn->iob), (void*)conn) != -1, "Failed to register connection."); check(taskcreate(Connection_task, conn, CONNECTION_STACK) != -1, "Failed to create connection task."); check(taskcreate(Connection_deliver_task, conn, CONNECTION_STACK) != -1, "Failed to create connection task."); conn->deliverTaskStatus=DT_RUNNING; return 0; error: IOBuf_register_disconnect(conn->iob); return -1; }
char * all_tests() { mu_suite_start(); Register_init(); // some evil hackery to mock out a registration so that the payload functions work Connection *conn = calloc(sizeof(Connection), 1); conn->iob = NULL; conn->type = CONN_TYPE_HTTP; Register_connect(0, conn); mu_run_test(test_Request_create); mu_run_test(test_Multiple_Header_Request); mu_run_test(test_Request_payloads); mu_run_test(test_Request_speeds); return NULL; }
static inline int ident_and_register(Connection *conn, int reg_too) { int next = CLOSE; if(Request_is_xml(conn->req)) { if(biseq(Request_path(conn->req), &POLICY_XML_REQUEST)) { debug("XML POLICY CONNECTION"); conn->type = CONN_TYPE_SOCKET; taskname("XML"); next = SOCKET_REQ; } else { debug("XML MESSAGE"); conn->type = CONN_TYPE_MSG; taskname("MSG"); next = MSG_REQ; } } else if(Request_is_json(conn->req)) { debug("JSON SOCKET MESSAGE"); conn->type = CONN_TYPE_MSG; taskname("MSG"); next = MSG_REQ; } else if(Request_is_http(conn->req)) { debug("HTTP MESSAGE"); conn->type = CONN_TYPE_HTTP; taskname("HTTP"); next = HTTP_REQ; } else { error_response(conn, 500, "Invalid code branch, tell Zed."); } if(reg_too) Register_connect(IOBuf_fd(conn->iob), (void*)conn); return next; error: return CLOSE; }