Ejemplo n.º 1
0
IoObject* IoMySQL_connect(IoObject* self, IoObject* locals, IoMessage* m) {
    IoObject *host = NULL, *user = NULL, *password = NULL, *database = NULL, *port = NULL, *socket = NULL, *ssl = NULL;

    /*doc MySQL connect(host, user, password, database, port, unixSocket, useSSL)
    Connect to a MySQL database.
    */

    switch(IoMessage_argCount(m)) {
    case 7:
        ssl = IoMessage_locals_quickValueArgAt_(m, locals, 6);
    case 6:
        socket = IoMessage_locals_quickValueArgAt_(m, locals, 5);
    case 5:
        port = IoMessage_locals_quickValueArgAt_(m, locals, 4);
    case 4:
        database = IoMessage_locals_quickValueArgAt_(m, locals, 3);
    case 3:
        password = IoMessage_locals_quickValueArgAt_(m, locals, 2);
    case 2:
        user = IoMessage_locals_quickValueArgAt_(m, locals, 1);
    case 1:
        host = IoMessage_locals_quickValueArgAt_(m, locals, 0);
    }

    if(DATA(self)->connected)
    {
        mysql_close(&DATA(self)->connection);
        DATA(self)->connected = 0;
    }

    if(mysql_real_connect(
                &DATA(self)->connection,
                host && ISSEQ(host) ? IoSeq_asCString(host) : NULL,
                user && ISSEQ(user) ? IoSeq_asCString(user) : NULL,
                password && ISSEQ(password) ? IoSeq_asCString(password) : NULL,
                database && ISSEQ(database) ? IoSeq_asCString(database) : NULL,
                port && ISNUMBER(port) ? (unsigned) IoNumber_asInt(port) : 0,
                socket && ISSEQ(socket) ? IoSeq_asCString(socket) : NULL,
                ssl && ISFALSE(ssl) ? 0 : CLIENT_SSL
            )) {
        DATA(self)->connected = 1;

        IoObject_setSlot_to_(self, IOSYMBOL("host"), host ? host : IONIL(self));
        IoObject_setSlot_to_(self, IOSYMBOL("user"), user ? user : IONIL(self));
        IoObject_setSlot_to_(self, IOSYMBOL("password"), password ? password : IONIL(self));
        IoObject_setSlot_to_(self, IOSYMBOL("database"), database ? database : IONIL(self));
        IoObject_setSlot_to_(self, IOSYMBOL("port"), port ? port : IONIL(self));
        IoObject_setSlot_to_(self, IOSYMBOL("socket"), socket ? socket : IONIL(self));
        IoObject_setSlot_to_(self, IOSYMBOL("usingSSL"), ssl ? IOBOOL(self, ISTRUE(ssl)) : IOFALSE(self));
    }
    else
        IoState_error_(IOSTATE, m, "connection error(%d): %s", mysql_errno(&DATA(self)->connection), mysql_error(&DATA(self)->connection));

    return self;
}
Ejemplo n.º 2
0
IoObject *IoFnmatch_hasMatch(IoFnmatch *self, IoObject *locals, IoMessage *m)
{
	/*doc Fnmatch hasMatch
	Returns true if a match is found, false otherwise.
	*/

	char *pattern = IoSeq_asCString(DATA(self)->pattern);
	char *string = IoSeq_asCString(DATA(self)->string);
	//int e = fnmatch(pattern, string, DATA(self)->flags) == 0;
	//return IOBOOL(self, e);
	return IOBOOL(self, fnmatch(pattern, string, DATA(self)->flags) == 0);
}
Ejemplo n.º 3
0
IoSecureServer *IoSecureServer_setCRLFile(IoSecureServer *self, IoObject *locals, IoMessage *msg)
{
	SSL_CTX *ctx = OCTX(self);
	IoSeq *pathSeq = IoMessage_locals_seqArgAt_(msg, locals, 0);
	char *path = IoSeq_asCString(pathSeq);
	if(ctx == NULL)
	{
		IoState_error_(IOSTATE, msg, "SecureServer has no SSL_CTX");
		return IONIL(self);
	}
	X509_STORE *store = SSL_CTX_get_cert_store(ctx);
	X509_STORE_set_verify_cb_func(store, IoSecureSockets_Verify_CRL_Callback);
	X509_STORE_set_flags (store, X509_V_FLAG_CRL_CHECK | X509_V_FLAG_CRL_CHECK_ALL);
	X509_LOOKUP *lookup;
	if (!(lookup = X509_STORE_add_lookup (store, X509_LOOKUP_file ())))
	{
		ERR_print_errors_fp(stderr);
		IoState_error_(IOSTATE, msg, "Error creating X509_LOOKUP object.");
	  	return IONIL(self);
	}
	if (X509_load_crl_file(lookup, path, X509_FILETYPE_PEM) != 1)
	{
		ERR_print_errors_fp(stderr);
		IoState_error_(IOSTATE, msg, "Error loading CRL from file %s\n", path);
	  	return IONIL(self);
	}
	
	return self;
}
Ejemplo n.º 4
0
IoObject *IoIPAddress_setIp(IoIPAddress *self, IoObject *locals, IoMessage *m)
{
	IoSeq *ip = IoMessage_locals_seqArgAt_(m, locals, 0);
	char *ipString = IoSeq_asCString(ip);
	IPAddress_setIp_(IPADDRESS(self), ipString);
	return self;
}
Ejemplo n.º 5
0
double IoSeq_rawAsDoubleFromOctal(IoSeq *self)
{
	char *s = IoSeq_asCString(self);
	unsigned int i;

	sscanf(s, "%o", &i);
	return (double)i;
}
Ejemplo n.º 6
0
Archivo: IoFile.c Proyecto: achoy/io
IO_METHOD(IoFile, assertWrite)
{
	char *mode = IoSeq_asCString(DATA(self)->mode);

	if ((strcmp(mode, "r+")) && (strcmp(mode, "a+")) && (strcmp(mode, "w")))
	{
		IoState_error_(IOSTATE, m, "file '%s' not open for write", UTF8CSTRING(DATA(self)->path));
	}

	return self;
}
Ejemplo n.º 7
0
Archivo: IoFile.c Proyecto: achoy/io
IO_METHOD(IoFile, mode)
{
	/*doc File mode
	Returns the open mode of the file(either read, update or append).
	*/

	char *mode = IoSeq_asCString(DATA(self)->mode);

	if (!strcmp(mode, "r"))  { return IOSYMBOL("read"); }
	if (!strcmp(mode, "r+")) { return IOSYMBOL("update"); }
	if (!strcmp(mode, "a+")) { return IOSYMBOL("append"); }

	return IONIL(self);
}
Ejemplo n.º 8
0
Archivo: IoCurses.c Proyecto: Akiyah/io
IoObject *IoCurses_insert(IoCurses *self, IoObject *locals, IoMessage *m)
{
	/*doc Curses insert(aString)
	Inserts the string at the current position on the terminal, 
	pushing existing text to the right. Returns self.
	*/

	char *string = IoSeq_asCString(IoMessage_locals_seqArgAt_(m, locals, 0));

	if (insstr(string) == ERR)
	{
		IoCurses_showError(self, m, "Curses.insert", "Failed to insert string.");
	}
	return self;
}
Ejemplo n.º 9
0
Archivo: IoCurses.c Proyecto: Akiyah/io
IoObject *IoCurses_print(IoCurses *self, IoObject *locals, IoMessage *m)
{
	/*doc Curses print(aString)
	Prints the string to the current position on the terminal, 
	overwriting existing text on the terminal. Returns self.
	*/

	char *string = IoSeq_asCString(IoMessage_locals_seqArgAt_(m, locals, 0));

	if (addstr(string) == ERR)
	{
		/* IoCurses_showError(self, m, "Curses.print", "Failed to print string.");*/
	}
	return self;
}
Ejemplo n.º 10
0
IoSecureServer *IoSecureServer_setCAFile(IoSecureServer *self, IoObject *locals, IoMessage *msg)
{
	SSL_CTX *ctx = OCTX(self);
	IoSeq *pathSeq = IoMessage_locals_seqArgAt_(msg, locals, 0);
	char *path = IoSeq_asCString(pathSeq);
	if(ctx == NULL)
	{
		IoState_error_(IOSTATE, msg, "SecureServer has no SSL_CTX");
		return IONIL(self);
	}
	if(SSL_CTX_load_verify_locations(ctx, path, NULL) != 1)
	{
		ERR_print_errors_fp(stderr);
		IoState_error_(IOSTATE, msg, "Error loading CA certificate from file %s\n", path);
		return IONIL(self);
	}
	return self;
}
Ejemplo n.º 11
0
IoSecureServer *IoSecureServer_setKeyFile(IoSecureServer *self, IoObject *locals, IoMessage *msg)
{
	SSL_CTX *ctx = OCTX(self);
	IoSeq *pathSeq = IoMessage_locals_seqArgAt_(msg, locals, 0);
	char *path = IoSeq_asCString(pathSeq);
	if(ctx == NULL)
	{
		IoState_error_(IOSTATE, msg, "SecureServer has no SSL_CTX");
		return IONIL(self);
	}
	if(SSL_CTX_use_PrivateKey_file(ctx, path, SSL_FILETYPE_PEM) != 1)
	{	
		ERR_print_errors_fp(stderr);
		IoState_error_(IOSTATE, msg, "Error loading private key from file %s\n", path);
		return IONIL(self);
	}
	return self;
}
Ejemplo n.º 12
0
IoSecureClient *IoSecureClient_setCertFile(IoSecureClient *self, IoObject *locals, IoMessage *msg)
{
	SSL_CTX *ctx = OCTX(self);
	IoSeq *pathSeq = IoMessage_locals_seqArgAt_(msg, locals, 0);
	char *path = IoSeq_asCString(pathSeq);
	if(ctx == NULL)
	{
		IoState_error_(IOSTATE, msg, "SecureClient has no SSL_CTX");
		return IONIL(self);
	}
	if(SSL_CTX_use_certificate_chain_file(ctx, path) != 1)
	{
		ERR_print_errors_fp(stderr);
		IoState_error_(IOSTATE, msg, "Error loading certificate from file %s\n", path);
		return IONIL(self);
	}
	return self;
}