Exemplo n.º 1
0
static inline int Server_accept(int listen_fd)
{
    int cfd = -1;
    int rport = -1;
    char remote[IPADDR_SIZE];
    int rc = 0;
    Connection *conn = NULL;

    cfd = netaccept(listen_fd, remote, &rport);
    check(cfd >= 0, "Failed to accept on listening socket.");

    Server *srv = Server_queue_latest();
    check(srv != NULL, "Failed to get a server from the configured queue.");

    conn = Connection_create(srv, cfd, rport, remote);
    check(conn != NULL, "Failed to create connection after accept.");

    rc = Connection_accept(conn);
    check(rc == 0, "Failed to register connection, overloaded.");

    return 0;

error:

    if(conn != NULL) Connection_destroy(conn);
    return -1;
}
Exemplo n.º 2
0
Arquivo: tds.c Projeto: kohenchia/ctds
/**
   https://www.python.org/dev/peps/pep-0249/#connect
*/
static PyObject* tds_connect(PyObject* self, PyObject* args, PyObject* kwargs)
{
    static char* s_kwlist[] =
    {
        "server",
        "port",
        "instance",
        "user",
        "password",
        "database",
        "appname",
        "login_timeout",
        "timeout",
        "tds_version",
        "autocommit",
        "ansi_defaults",
        "enable_bcp",
        NULL
    };

    char* server = NULL;
    uint16_t port = DEFAULT_PORT;
    char* instance = NULL;
    char* username = DEFAULT_USERNAME;
    char* password = DEFAULT_PASSWORD;
    char* database = NULL;
    char* appname = DEFAULT_APPNAME;
    unsigned int login_timeout = DEFAULT_LOGIN_TIMEOUT;
    unsigned int timeout = DEFAULT_TIMEOUT;
    char* tds_version = NULL;
    PyObject* autocommit = (DEFAULT_AUTOCOMMIT) ? Py_True : Py_False;
    PyObject* ansi_defaults = (DEFAULT_ANSI_DEFAULTS) ? Py_True : Py_False;
    PyObject* enable_bcp = (DEFAULT_ENABLE_BCP) ? Py_True : Py_False;
    if (!PyArg_ParseTupleAndKeywords(args, kwargs, "s|HzzzzzIIzO!O!O!", s_kwlist, &server,
                                     &port, &instance, &username, &password,
                                     &database, &appname, &login_timeout,
                                     &timeout, &tds_version, &PyBool_Type, &autocommit,
                                     &PyBool_Type, &ansi_defaults,
                                     &PyBool_Type, &enable_bcp))
    {
        return NULL;
    }

    return Connection_create(server, port, instance, username, password,
                             database, appname, login_timeout, timeout,
                             tds_version, (Py_True == autocommit),
                             (Py_True == ansi_defaults),
                             (Py_True == enable_bcp));

    UNUSED(self);
}
Exemplo n.º 3
0
char * all_tests() {
    mu_suite_start();
    Register_init();

    // some evil hackery to mock out a registration so that the payload functions work
    conn = Connection_create(NULL,0,1,"");
    /*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;
}
Exemplo n.º 4
0
char *test_Filter_run_chain(){

	Filter_init(); /*We need a fresh new Filter storage*/
	Connection *conn = Connection_create(NULL, 0, 80, "");

    int res_filter_a = Filter_load(NULL, bfromcstr("tests/filters/test_filter_a.so"), tns_new_dict());
    mu_assert(res_filter_a == 0, "Failed to load tests/filters/test_filter_a.so");

    int res_filter_b = Filter_load(NULL, bfromcstr("tests/filters/test_filter_b.so"), tns_new_dict());
    mu_assert(res_filter_b == 0, "Failed to load tests/filters/test_filter_b.so");

    Filter_run(CONNECT, conn);

    /* filter_a sums 2 on conn->rport, filter_b sums 8*/
    mu_assert(conn->rport == 90, "Not all filters was run, rport not correctly changed");

	return NULL;
}
Exemplo n.º 5
0
char *test_Filter_stop_filter_chain(){
	Filter_init(); /*We need a fresh new Filter storage*/
	Connection *conn = Connection_create(NULL, 0, 80, "");

    int res_filter_a = Filter_load(NULL, bfromcstr("tests/filters/test_filter_a.so"), tns_new_dict());
    mu_assert(res_filter_a == 0, "Failed to load tests/filters/test_filter_a.so");

    int res_filter_c = Filter_load(NULL, bfromcstr("tests/filters/test_filter_c.so"), tns_new_dict());
    mu_assert(res_filter_c == 0, "Failed to load tests/filters/test_filter_c.so");

    int res_filter_b = Filter_load(NULL, bfromcstr("tests/filters/test_filter_b.so"), tns_new_dict());
    mu_assert(res_filter_b == 0, "Failed to load tests/filters/test_filter_b.so");

    int next = Filter_run(CONNECT, conn);
    mu_assert(next == CLOSE, "Last filter not run correctly");

    /* Only filter_a and filter_c should run. */
    mu_assert(conn->rport == 87, "Not all filters should be run");

	return NULL;
}