IoObject *IoTokyoCabinetPrefixCursor_key(IoObject *self, IoObject *locals, IoMessage *m) { /*doc TokyoCabinetPrefixCursor key Returns current cursor key or nil. */ int size; char *ks; IoSeq *prefix = IoObject_getSlot_(self, IOSYMBOL("prefix")); IOASSERT(ISSEQ(prefix), "prefix must be a sequence"); IOASSERT(TokyoCabinetPrefixCursor(self), "invalid TokyoCabinetPrefixCursor"); ks = tcbdbcurkey(TokyoCabinetPrefixCursor(self), &size); if (ks) { UArray *k = UArray_newWithData_type_size_copy_(ks, CTYPE_uint8_t, size, 1); if (UArray_beginsWith_(k, IoSeq_rawUArray(prefix))) { //printf("prefix '%s'\n", UArray_bytes(IoSeq_rawUArray(prefix))); //printf("before clip '%s'\n", UArray_bytes(k)); UArray_clipBeforeEndOf_(k, IoSeq_rawUArray(prefix)); UArray_removeFirst(k); // remove separator //printf("after clip '%s'\n", UArray_bytes(k)); return IoSeq_newWithUArray_copy_(IOSTATE, k, 0); } UArray_free(k); } return IONIL(self); }
IO_METHOD(IoDate, setDay) { /*doc Date setDay(aNumber) Sets the day of the receiver. Returns self. */ int v = IoMessage_locals_intArgAt_(m, locals, 0); int month = Date_month(DATA(self)) + 1; IOASSERT(v >= 1 && v <= 31, "day must be within range 1-31"); if (month == 2) { if (Date_isLeapYear(DATA(self))) { IOASSERT(v >= 1 && v <= 29, "day must be within range 1-29"); } else { IOASSERT(v >= 1 && v <= 28, "day must be within range 1-28"); } } else if (month == 11) { IOASSERT(v >= 1 && v <= 30, "day must be within range 1-30"); } else if (month == 12) { IOASSERT(v >= 1 && v <= 31, "day must be within range 1-31"); } Date_setDay_(DATA(self), v); IoObject_isDirty_(self, 1); return self; }
/*doc Memcached getMulti(keys) Asks memcached to retrieve data corresponding to the list of keys. Returns a Map with the results. If some of the keys appearing in a retrieval request are not sent back by the server in the item list this means that the server does not hold items with such keys */ IoObject *IoMemcached_getMulti(IoMemcached *self, IoObject *locals, IoMessage *m) { IoList *keys_list = IoMessage_locals_listArgAt_(m, locals, 0); size_t keys_list_size = IoList_rawSize(keys_list); IoObject *results_map = IoMap_new(IOSTATE); if(keys_list_size == 0) return results_map; int i; for(i = 0; i < keys_list_size; i++) { IoSeq *key = IoList_rawAt_(keys_list, i); IOASSERT(ISSEQ(key), "key must be a Sequence"); IOASSERT(IOSEQ_LENGTH(key) > 0, "key cannot be an empty Sequence"); IOASSERT(IOSEQ_LENGTH(key) < MEMCACHED_MAX_KEY, "key is too long"); } const char **ckeys = (const char **) malloc(sizeof(const char *) * keys_list_size); size_t *ckey_lengths = (size_t *) malloc(sizeof(size_t) * keys_list_size); for(i = 0; i < keys_list_size; i++) { ckeys[i] = CSTRING(IoList_rawAt_(keys_list, i)); ckey_lengths[i] = strlen(ckeys[i]); } memcached_return_t rc = memcached_mget(DATA(self)->mc, ckeys, ckey_lengths, keys_list_size); free(ckeys); free(ckey_lengths); char returned_key[MEMCACHED_MAX_KEY], *returned_value; size_t returned_key_length, returned_value_length; uint32_t flags; returned_value = memcached_fetch(DATA(self)->mc, returned_key, &returned_key_length, &returned_value_length, &flags, &rc ); while(returned_value != NULL) { IoMap_rawAtPut(results_map, IoSeq_newSymbolWithData_length_(IOSTATE, returned_key, returned_key_length), IoMemcached_deserialize(self, returned_value, returned_value_length, flags) ); free(returned_value); returned_value = memcached_fetch(DATA(self)->mc, returned_key, &returned_key_length, &returned_value_length, &flags, &rc ); } return results_map; }
IoObject *IoTokyoCabinetPrefixCursor_remove(IoObject *self, IoObject *locals, IoMessage *m) { /*doc TokyoCabinetPrefixCursor remove Removes the current cursor postion. Returns self. */ IOASSERT(TokyoCabinetPrefixCursor(self), "invalid TokyoCabinetPrefixCursor"); IOASSERT(tcbdbcurout(TokyoCabinetPrefixCursor(self)), tcbdberrmsg(tcbdbecode(TokyoCabinet(self)))); return self; }
IoObject *IoTokyoCabinetPrefixCursor_next(IoObject *self, IoObject *locals, IoMessage *m) { /*doc TokyoCabinetPrefixCursor next Move cursor to next record. Returns true if there is another key, or false if there is no next record. */ IoSeq *prefix = IoObject_getSlot_(self, IOSYMBOL("prefix")); IOASSERT(ISSEQ(prefix), "prefix must be a sequence"); IOASSERT(TokyoCabinetPrefixCursor(self), "invalid TokyoCabinetPrefixCursor"); tcbdbcurnext(TokyoCabinetPrefixCursor(self)); return IOBOOL(self, IoTokyoCabinetPrefixCursor_keyBeginsWithPrefix_(self, prefix)); }
IoObject *IoTokyoCabinetPrefixCursor_put(IoObject *self, IoObject *locals, IoMessage *m) { /*doc TokyoCabinetPrefixCursor put(value) Sets the value at the current cursor postion. Returns self. */ IoSeq *value = IoMessage_locals_seqArgAt_(m, locals, 0); IOASSERT(TokyoCabinetPrefixCursor(self), "invalid TokyoCabinetPrefixCursor"); IOASSERT(tcbdbcurput(TokyoCabinetPrefixCursor(self), (const char *)IoSeq_rawBytes(value), IoSeq_rawSizeInBytes(value), BDBCPCURRENT), tcbdberrmsg(tcbdbecode(TokyoCabinet(self)))); return self; }
IoObject *IoEvConnection_connect(IoEvConnection *self, IoObject *locals, IoMessage *m) { IoEventManager *em = IoObject_getSlot_(self, IOSYMBOL("eventManager")); IoSeq *address = IoObject_seqGetSlot_(self, IOSYMBOL("address")); int port = IoObject_doubleGetSlot_(self, IOSYMBOL("port")); IOASSERT(CONN(self) == 0x0, "already have connection"); IOASSERT(ISEEVENTMANAGER(em), "eventManager slot not set properly"); //printf("IoEventManager_rawBase(em) = %p\n", (void *)IoEventManager_rawBase(em)); IoObject_setDataPointer_(self, evhttp_connection_new(CSTRING(address), port)); evhttp_connection_set_base(CONN(self), IoEventManager_rawBase(em)); evhttp_connection_set_closecb(CONN(self), IoEvConnection_ConnectionCloseCallback, self); return self; }
IoObject *IoTheoraDecodeContext_ycbcr(IoTheoraDecodeContext *self, IoObject *locals, IoMessage *m) { /*doc TheoraDecodecontext ycbcr Returns an object containing the YUV data from the decoded frame. */ th_ycbcr_buffer buffer; int ret = th_decode_ycbcr_out(DATA(self)->ctx, buffer); IOASSERT(ret == 0, "th_decode_ycbcr_out failed"); IoObject* yuv0 = IoObject_new(IOSTATE); IoObject* yuv1 = IoObject_new(IOSTATE); IoObject* yuv2 = IoObject_new(IOSTATE); IoObject_setSlot_to_(yuv0, IOSYMBOL("width"), IONUMBER(buffer[0].width)); IoObject_setSlot_to_(yuv0, IOSYMBOL("height"), IONUMBER(buffer[0].height)); IoObject_setSlot_to_(yuv0, IOSYMBOL("stride"), IONUMBER(buffer[0].stride)); IoObject_setSlot_to_(yuv0, IOSYMBOL("data"), IOSEQ(buffer[0].data, buffer[0].stride * buffer[0].height)); IoObject_setSlot_to_(yuv1, IOSYMBOL("width"), IONUMBER(buffer[1].width)); IoObject_setSlot_to_(yuv1, IOSYMBOL("height"), IONUMBER(buffer[1].height)); IoObject_setSlot_to_(yuv1, IOSYMBOL("stride"), IONUMBER(buffer[1].stride)); IoObject_setSlot_to_(yuv1, IOSYMBOL("data"), IOSEQ(buffer[1].data, buffer[1].stride * buffer[1].height)); IoObject_setSlot_to_(yuv2, IOSYMBOL("width"), IONUMBER(buffer[2].width)); IoObject_setSlot_to_(yuv2, IOSYMBOL("height"), IONUMBER(buffer[2].height)); IoObject_setSlot_to_(yuv2, IOSYMBOL("stride"), IONUMBER(buffer[2].stride)); IoObject_setSlot_to_(yuv2, IOSYMBOL("data"), IOSEQ(buffer[2].data, buffer[2].stride * buffer[2].height)); IoList* result = IoList_new(IOSTATE); IoList_rawAppend_(result, yuv0); IoList_rawAppend_(result, yuv1); IoList_rawAppend_(result, yuv2); return result; }
IoObject *IoObject_performWithDebugger(IoCoroutine *self, IoObject *locals, IoMessage *m) { IoState *state = IOSTATE; IoObject *currentCoroutine = IoState_currentCoroutine(state); if (IoCoroutine_rawDebuggingOn(currentCoroutine)) { IoObject *debugger = state->debugger; // stack retain it? if (debugger) { IoObject_setSlot_to_(debugger, IOSYMBOL("messageCoroutine"), currentCoroutine); IoObject_setSlot_to_(debugger, IOSYMBOL("messageSelf"), self); IoObject_setSlot_to_(debugger, IOSYMBOL("messageLocals"), locals); IoObject_setSlot_to_(debugger, IOSYMBOL("message"), m); { IoObject *context; IoCoroutine *c = IoObject_rawGetSlot_context_(debugger, IOSYMBOL("debuggerCoroutine"), &context); IOASSERT(c, "Debugger needs a debuggerCoroutine slot"); IoCoroutine_rawResume(c); } } } return IoObject_perform(self, locals, m); }
Uint64Array *IoTagDB_tagArrayForTagNames_(IoTagDB *self, IoMessage *m, IoList *tagNames) { TagDB *tdb = DATA(self); Uint64Array *tags = Uint64Array_new(); int i; for (i = 0; i < IoList_rawSize(tagNames); i ++) { IoSeq *tagName = IoList_rawAt_(tagNames, i); symbolid_t keyid; IOASSERT(ISSEQ(tagName), "tag names must be Sequences"); keyid = TagDB_idForSymbol_size_(tdb, CSTRING(tagName), IoSeq_rawSize(tagName)); Uint64Array_append_(tags, keyid); /* { Datum *keyDatum = TagDB_symbolForId_(tdb, keyid); printf("%s -> %i && ", CSTRING(tagName), (int)keyid); printf("%i -> %s\n", (int)keyid, (char *)(keyDatum->data)); Datum_free(keyDatum); } */ } return tags; }
IoObject *IoTokyoCabinetCursor_last(IoObject *self, IoObject *locals, IoMessage *m) { /*doc TokyoCabinetCursor last Move cursor to last record. Returns self */ IOASSERT(TokyoCabinetCursor(self), "invalid TokyoCabinetCursor"); return IOBOOL(self, tcbdbcurlast(TokyoCabinetCursor(self))); }
IO_METHOD(IoSeq, insertSeqEvery) { /*doc MutableSequence IoSeq_insertSeqEvery(aSequence, aNumberOfItems) Inserts aSequence every aNumberOfItems. Returns self. */ IoSeq *otherSeq = IoMessage_locals_valueAsStringArgAt_(m, locals, 0); size_t itemCount = IoMessage_locals_sizetArgAt_(m, locals, 1); IO_ASSERT_NOT_SYMBOL(self); IOASSERT(itemCount > 0, "aNumberOfItems must be > 0"); IOASSERT(itemCount <= UArray_size(DATA(self)), "aNumberOfItems out of sequence bounds"); UArray_insert_every_(DATA(self), DATA(otherSeq), itemCount); return self; }
//doc Loudmouth registerAccount(server, username, password) Registers a new account at XMPP server. Returns <code>true</code> or <code>false</code>. IoObject *IoLoudmouth_registerAccount(IoLoudmouth *self, IoObject *locals, IoMessage *m) { char *server = IoMessage_locals_cStringArgAt_(m, locals, 0), *username = IoMessage_locals_cStringArgAt_(m, locals, 1), *password = IoMessage_locals_cStringArgAt_(m, locals, 2), *error_message = "Unknown error"; LmConnection *connection = lm_connection_new(server); LmMessage *xmpp_msg, *xmpp_reply; LmMessageNode *query, *node; int success = 0; if(!lm_connection_open_and_block(connection, NULL)) { error_message = "Could not open connection"; success = 0; } else { xmpp_msg = lm_message_new_with_sub_type(NULL, LM_MESSAGE_TYPE_IQ, LM_MESSAGE_SUB_TYPE_SET); query = lm_message_node_add_child(xmpp_msg->node, "query", NULL); lm_message_node_set_attributes(query, "xmlns", "jabber:iq:register", NULL); lm_message_node_add_child(query, "username", username); lm_message_node_add_child(query, "password", password); xmpp_reply = lm_connection_send_with_reply_and_block(connection, xmpp_msg, NULL); lm_connection_close(connection, NULL); lm_connection_unref(connection); if(!xmpp_reply) { success = 0; error_message = "No reply from server"; } else { switch(lm_message_get_sub_type(xmpp_reply)) { case LM_MESSAGE_SUB_TYPE_RESULT: success = 1; break; case LM_MESSAGE_SUB_TYPE_ERROR: default: success = 0; node = lm_message_node_find_child(xmpp_reply->node, "error"); error_message = (node == NULL) ? lm_message_node_get_value(node) : "Unknown error"; lm_message_node_unref(node); } } lm_message_unref(xmpp_reply); lm_message_unref(xmpp_msg); lm_message_node_unref(query); } free(server); free(username); free(password); IOASSERT(success, error_message); free(error_message); return IOBOOL(self, success); }
IoObject *IoSkipDBM_compact(IoObject *self, IoObject *locals, IoMessage *m) { /*doc SkipDBM compact Compacts the database. Returns self. */ IOASSERT(SkipDBM_isOpen(SKIPDBM(self)), "skipdbm not open"); SkipDBM_compact(SKIPDBM(self)); return self; }
IoObject *IoSkipDBCursor_previous(IoObject *self, IoObject *locals, IoMessage *m) { /*doc SkipDBCursor previous Move cursor to previous item. Returns self. */ IOASSERT(CURSOR(self), "SkipDBCursor invalid"); SkipDBCursor_previous(CURSOR(self)); return self; }
IoObject *IoSkipDB_size(IoObject *self, IoObject *locals, IoMessage *m) { /*doc SkipDB size Returns the number of keys in the receiver. */ IOASSERT(SKIPDB(self) && SkipDB_isOpen(SKIPDB(self)), "invalid skipdb"); return IONUMBER(SkipDB_count(SKIPDB(self))); }
IoObject *IoTokyoCabinetPrefixCursor_first(IoObject *self, IoObject *locals, IoMessage *m) { /*doc TokyoCabinetPrefixCursor first Move cursor to first record. Returns self */ IoSeq *prefix = IoObject_getSlot_(self, IOSYMBOL("prefix")); IOASSERT(ISSEQ(prefix), "prefix must be a sequence"); IOASSERT(TokyoCabinetPrefixCursor(self), "invalid TokyoCabinetPrefixCursor"); tcbdbcurjump(TokyoCabinetPrefixCursor(self), (const void *)IoSeq_rawBytes(prefix), (int)IoSeq_rawSizeInBytes(prefix)); if(!IoTokyoCabinetPrefixCursor_keyBeginsWithPrefix_(self, prefix)) { tcbdbcurnext(TokyoCabinetPrefixCursor(self)); } return IOBOOL(self, IoTokyoCabinetPrefixCursor_keyBeginsWithPrefix_(self, prefix)); }
IoObject *IoSkipDBM_commitnTransaction(IoObject *self, IoObject *locals, IoMessage *m) { /*doc SkipDBM commitTransaction Commit a transaction. Returns self. */ IOASSERT(SkipDBM_isOpen(SKIPDBM(self)), "skipdbm not open"); SkipDBM_commitTransaction(SKIPDBM(self)); return self; }
IoObject *IoLZODecoder_beginProcessing(IoLZODecoder *self, IoObject *locals, IoMessage *m) { /*doc LZODecoder beginProcessing Initializes the algorithm. */ IOASSERT(lzo_init() == LZO_E_OK, "Failed to init lzo"); DATA(self)->isDone = 0; return self; }
IoObject *IoTokyoCabinetCursor_next(IoObject *self, IoObject *locals, IoMessage *m) { /*doc TokyoCabinetCursor next Move cursor to next record. Returns true if there is another key, or false if there is no next record. */ IOASSERT(TokyoCabinetCursor(self), "invalid TokyoCabinetCursor"); return IOBOOL(self, tcbdbcurnext(TokyoCabinetCursor(self))); }
IoObject *IoSkipDBCursor_next(IoObject *self, IoObject *locals, IoMessage *m) { /*doc SkipDBCursor next Move cursor to next item. Returns self. */ IOASSERT(CURSOR(self), "SkipDBCursor invalid"); SkipDBCursor_next(CURSOR(self)); return self; }
IO_METHOD(IoDate, setMonth) { /*doc Date setMonth(aNumber) Sets the month(1-12) of the receiver. Returns self. */ int v = IoMessage_locals_intArgAt_(m, locals, 0); IOASSERT(v >= 1 && v <= 12, "month must be within range 1-12"); Date_setMonth_(DATA(self), v - 1); return self; }
IoObject *IoTokyoCabinetPrefixCursor_jump(IoObject *self, IoObject *locals, IoMessage *m) { /*doc TokyoCabinetPrefixCursor jump(key) Move cursor to record before key. Returns self */ IoSeq *key = IoMessage_locals_seqArgAt_(m, locals, 0); IOASSERT(TokyoCabinetPrefixCursor(self), "invalid TokyoCabinetPrefixCursor"); return IOBOOL(self, tcbdbcurjump(TokyoCabinetPrefixCursor(self), (const void *)IoSeq_rawBytes(key), (int)IoSeq_rawSizeInBytes(key))); }
IoObject *IoSkipDBCursor_goto(IoObject *self, IoObject *locals, IoMessage *m) { /*doc SkipDBCursor goto(aKey) Move cursor to the specified key or nearest preceeding key. Returns self */ IoSeq *key = IoMessage_locals_seqArgAt_(m, locals, 0); IOASSERT(CURSOR(self), "SkipDBCursor invalid"); SkipDBCursor_goto_(CURSOR(self), IoSeq_asDatum(key)); return self; }
IoObject *IoBlowfish_setIsEncrypting(IoBlowfish *self, IoObject *locals, IoMessage *m) { /*doc Blowfish setIsEncrypting(aBool) If aBool is true, encrypting mode is on, otherwise, decrypting mode is on. */ IoObject *v = IoMessage_locals_valueArgAt_(m, locals, 0); IOASSERT(ISTRUE(v) || ISFALSE(v), "requires boolean argument"); DATA(self)->isEncrypting = ISTRUE(v); return self; }
IoObject *IoSkipDB_removeAt(IoObject *self, IoObject *locals, IoMessage *m) { /*doc SkipDB atRemove(keySymbol) Removes the specified key. Returns self */ IoSeq *key = IoMessage_locals_seqArgAt_(m, locals, 0); IOASSERT(SKIPDB(self) && SkipDB_isOpen(SKIPDB(self)), "invalid skipdb"); SkipDB_removeAt_(SKIPDB(self), IoSeq_asDatum(key)); return self; }
//doc Loudmouth connect Connects to the server. Returns <code>self</code>. IoObject *IoLoudmouth_connect(IoLoudmouth *self, IoObject *locals, IoMessage *m) { // Q: Should we io_free() these? IoSeq* username = IoObject_getSlot_(self, IOSYMBOL("username")); IoSeq* password = IoObject_getSlot_(self, IOSYMBOL("password")); IoSeq* resource = IoObject_getSlot_(self, IOSYMBOL("resource")); IoSeq* host = IoObject_getSlot_(self, IOSYMBOL("host")); IoNumber* port = IoObject_getSlot_(self, IOSYMBOL("port")); IoObject* use_ssl = IoObject_getSlot_(self, IOSYMBOL("useSsl")); IOASSERT(ISSEQ(username), "Loudmouth: username should be a Sequence"); IOASSERT(ISSEQ(password), "Loudmouth: password should be a Sequence"); IOASSERT(ISSEQ(resource), "Loudmouth: resource should be a Sequence"); IOASSERT(ISSEQ(host), "Loudmouth: host should be a Sequence"); IOASSERT(ISNUMBER(port), "Loudmouth: port should be a Number"); if(LMCONN(self) == NULL) { LmConnection *connection = lm_connection_new_with_context(CSTRING(host), main_context); IoObject_setDataPointer_(self, connection); lm_connection_set_jid(connection, CSTRING(IoObject_getSlot_(self, IOSYMBOL("jid")))); lm_connection_set_port(connection, CNUMBER(port)); if(ISTRUE(use_ssl) && lm_ssl_is_supported()) { LmSSL *ssl = lm_ssl_new(NULL, onSslError, NULL, NULL); lm_connection_set_ssl(connection, ssl); lm_ssl_unref(ssl); } LmMessageHandler* handler = lm_message_handler_new(onXmppMessage, self, NULL); lm_connection_register_message_handler( connection, handler, LM_MESSAGE_TYPE_MESSAGE, LM_HANDLER_PRIORITY_NORMAL ); lm_message_handler_unref(handler); lm_connection_set_disconnect_function(connection, onXmppDisconnect, NULL, NULL); } lm_connection_open(LMCONN(self), onXmppConnect, self, NULL, NULL); return self; }
void IoEvDNS_rawInitIfNeeded(IoEvDNS *self) { if (!DNS(self)) { IoEventManager *em = IoObject_getSlot_(self, IOSYMBOL("eventManager")); IOASSERT(ISEEVENTMANAGER(em), "eventManager slot not set properly"); struct event_base *base = evhttp_new(IoEventManager_rawBase(em); int initialize_nameservers = 1; struct evdns_base *dnsBase = evdns_base_new(base, initialize_nameservers); IoObject_setDataPointer_(self, dnsBase); }
IoObject *IoSQLite3_setTimeoutSeconds(IoSQLite3 *self, IoObject *locals, IoMessage *m) { /*doc SQLite3 setTimeoutSeconds(aNumber) Sets the open timeout to aNumber. If aNumber is 0, an open call will never timeout. Returns self. */ IoNumber *num = IoMessage_locals_numberArgAt_(m, locals, 0); IOASSERT(IoNumber_asDouble(num) >= 0, "SQLite timeout must be a positive number"); DATA(self)->timeoutSeconds = IoNumber_asDouble(num); return self; }
IO_METHOD(IoDate, setSecond) { /*doc Date setSecond(aNumber) Sets the second of the receiver. Returns self. */ int v = IoMessage_locals_intArgAt_(m, locals, 0); IOASSERT(v >= 0 && v <= 59, "second must be within range 0-59"); Date_setSecond_(DATA(self), v); IoObject_isDirty_(self, 1); return self; }