Esempio n. 1
0
static PyObject *pyBindRuleset(PyObject *self, PyObject *args) {
    void *handle;
    char *host;
    unsigned int port;
    char *password = NULL;
    unsigned int result;
    if (PyArg_ParseTuple(args, "zlsl", &password, &port, &host, &handle)) {
        result = bindRuleset(handle, host, port, password);
    } else {
        PyErr_SetString(RulesError, "pyBindRuleset Invalid argument");
        return NULL;
    }

    if (result != RULES_OK) {
        if (result == ERR_OUT_OF_MEMORY) {
            PyErr_NoMemory();
        } else { 
            char *message;
            if (asprintf(&message, "Could not create connection, error code: %d", result)) {
                PyErr_NoMemory();
            } else {
                PyErr_SetString(RulesError, message);
                free(message);
            }
        }
        return NULL;
    }

    Py_RETURN_NONE;
}
Esempio n. 2
0
static VALUE rbBindRuleset(VALUE self, VALUE handle, VALUE host, VALUE port, VALUE password) {
    Check_Type(handle, T_FIXNUM);
    Check_Type(host, T_STRING);
    Check_Type(port, T_FIXNUM);
    
    unsigned int result;
    if (TYPE(password) == T_STRING) {
        result = bindRuleset((void *)FIX2LONG(handle), RSTRING_PTR(host), FIX2INT(port), RSTRING_PTR(password));
    } else if (TYPE(password) == T_NIL) {
        result = bindRuleset((void *)FIX2LONG(handle), RSTRING_PTR(host), FIX2INT(port), NULL);
    } else {
        rb_raise(rb_eTypeError, "Wrong argument type for password");   
    }

    if (result != RULES_OK) {
        if (result == ERR_OUT_OF_MEMORY) {
            rb_raise(rb_eNoMemError, "Out of memory");
        } else { 
            rb_raise(rb_eException, "Could not create connection, error code: %d", result);
        }
    }

    return Qnil;
}