/* format: addMember(name, type) */ IoObject* IoCInvokeStructure_addMember(IoCInvokeStructure* self, IoObject* locals, IoMessage* m) { CInvContext* context = IoCInvokeLibrary_getContext_(IoObject_getSlot_(self, IOSYMBOL("library"))); if(!(DATA(self)->structure)) { DATA(self)->structure = cinv_structure_create(context); } char* name = IoMessage_locals_cStringArgAt_(m, locals, 0); IoObject *typeobj = IoMessage_locals_valueArgAt_(m, locals, 1); if(ISCInvokeStructure(typeobj)) { /* adding a structure member! */ if(!cinv_structure_addmember_struct(context, DATA(self)->structure, name, DATA(typeobj)->structure)) { printf("error with adding struct member\n"); } } else { /* hopefully adding a DataType */ cinv_type_t type = IoCInvokeDataType_cinvType_t(typeobj); if(!cinv_structure_addmember_value(context, DATA(self)->structure, name, type)) { printf("error with adding value member\n"); } } // append it to the `memberTypes` Map IoObject *memberTypes = IoObject_getSlot_(self, IOSYMBOL("memberTypes")); IoMap_rawAtPut(memberTypes, IoMessage_locals_valueArgAt_(m, locals, 0), IoMessage_locals_valueArgAt_(m, locals, 1)); return self; }
IoObject *IoCFFIFunction_call(IoCFFIFunction *self, IoObject *locals, IoMessage *m) { IoCFFILibrary *library; const char *funName; void *funPointer, **funArgVals, *funRetVal; ffi_type **funArgTypes, *funRetType; ffi_cif *funInterface; int funArgCount, i; ffi_status status; IoObject *returnValAsObj, *funRetTypeObject, *o; List *funArgTypeObjects; library = IoObject_getSlot_(self, IOSYMBOL("library")); funInterface = &(DATA(self)->interface); funName = CSTRING(IoObject_getSlot_(self, IOSYMBOL("name"))); funPointer = IoCFFILibrary_rawGetFuctionPointer_(library, funName); funArgTypeObjects = IoList_rawList(IoObject_getSlot_(self, IOSYMBOL("argumentTypes"))); funRetTypeObject = IoObject_getSlot_(self, IOSYMBOL("returnType")); funArgCount = (int)List_size(funArgTypeObjects); funArgTypes = calloc(funArgCount, sizeof(ffi_type *)); for (i = 0; i < funArgCount; i++) { o = List_at_(funArgTypeObjects, i); funArgTypes[i] = IoCFFIDataType_ffiType(o); } funRetType = IoCFFIDataType_ffiType(funRetTypeObject); status = ffi_prep_cif(funInterface, FFI_DEFAULT_ABI, funArgCount, funRetType, funArgTypes); if (status != FFI_OK) { printf("\n\nUh oh. Something went wrong in IoCFFIFunction_call.\n\n"); free(funArgTypes); return IONIL(self); } funArgVals = calloc(funArgCount, sizeof(void *)); funRetVal = calloc(1, funRetType->size); IoState_pushCollectorPause(IOSTATE); { for (i = 0; i < funArgCount; i++) { o = IoMessage_locals_valueArgAt_(m, locals, i); funArgVals[i] = IoCFFIDataType_ValuePointerFromObject_(o); } ffi_call(funInterface, funPointer, funRetVal, funArgVals); returnValAsObj = IoCFFIDataType_objectFromData_(funRetTypeObject, funRetVal); } IoState_popCollectorPause(IOSTATE); free(funArgTypes); free(funArgVals); free(funRetVal); return returnValAsObj; }
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); }
IoObject *IoCInvokeStructureInstance_getValue(IoCInvokeStructureInstance *self, IoObject *locals, IoMessage *m) { CInvContext* context = getGlobalContext(); CInvStructure* structure = IoCInvokeStructure_getStructure_(IoObject_getSlot_(self, IOSYMBOL("structure"))); if(!DATA(self)->instance) { DATA(self)->instance = cinv_structure_create_instance(context, structure); // ... is that intelligent? } char* name = IoMessage_locals_cStringArgAt_(m, locals, 0); void* value = cinv_structure_instance_getvalue(context, structure, DATA(self)->instance, name); IoObject *memberType = IoMap_rawAt(IoObject_getSlot_( IoObject_getSlot_(self, IOSYMBOL("structure")), IOSYMBOL("memberTypes")), IOSYMBOL(name)); IoObject *io_value = IoCInvokeDataType_objectFromData_(memberType, value); return io_value; }
void IoCoroutine_rawRun(IoCoroutine *self) { Coro *coro = DATA(self)->cid; if (!coro) { coro = Coro_new(); DATA(self)->cid = coro; } { IoObject *stackSize = IoObject_getSlot_(self, IOSTATE->stackSizeSymbol); if(ISNUMBER(stackSize)) { Coro_setStackSize_(coro, CNUMBER(stackSize)); } } { IoCoroutine *current = IoState_currentCoroutine(IOSTATE); Coro *currentCoro = IoCoroutine_rawCoro(current); //IoState_stackRetain_(IOSTATE, self); Coro_startCoro_(currentCoro, coro, self, (CoroStartCallback *)IoCoroutine_coroStart); //IoState_setCurrentCoroutine_(IOSTATE, current); } }
IoCFFIArray *IoCFFIArray_atPut(IoCFFIArray *self, IoObject *locals, IoMessage *m) { int pos; IoObject *value, *arrayType, *d; char *ptr; pos = CNUMBER(IoMessage_locals_numberArgAt_(m, locals, 0)); value = IoMessage_locals_valueArgAt_(m, locals, 1); if ( pos >= DATA(self)->arraySize ) { IoState_error_(IOSTATE, m, "index out of bounds"); return IONIL(self); } arrayType = IoObject_getSlot_(self, IOSYMBOL("arrayType")); ptr = ((char *)DATA(self)->buffer) + (DATA(self)->itemSize * pos); d = IOCLONE(arrayType); IoCFFIDataType_rawSetValue(d, value); memcpy(ptr, (void *)IoCFFIDataType_ValuePointerFromObject_(self, d), DATA(self)->itemSize); if ( DATA(self)->keepValuesRefs ) { DATA(self)->keepValuesRefs[pos] = IOREF(d); } return self; }
IoObject* IoCInvokeStructure_finish(IoCInvokeStructure* self, IoObject* locals, IoMessage* m) { CInvContext* context = IoCInvokeLibrary_getContext_(IoObject_getSlot_(self, IOSYMBOL("library"))); if(!(DATA(self)->structure)) { DATA(self)->structure = cinv_structure_create(context); } cinv_structure_finish(context, DATA(self)->structure); return self; }
IoIPAddress *IoSecureServer_udpRecvIP(IoSecureServer *self, IoObject *locals, IoMessage *msg) { SSL_CTX *ctx = OCTX(self); IoSocket *sock = IoObject_getSlot_(self, IOSYMBOL("socket")); IoIPAddress *ioaddress = IoObject_getSlot_(sock, IOSYMBOL("ipAddress")); IPAddress *address = IoIPAddress_rawIPAddress(ioaddress); socklen_t addressSize = IPAddress_size(address); int fd = IoSocket_rawDescriptor(sock); int bytesPerRead = 1; char *buffer = calloc(1, sizeof(char)); int bytesRead = recvfrom(fd, buffer, bytesPerRead, MSG_PEEK, IPAddress_sockaddr(address), &addressSize); if (bytesRead > 0) { IPAddress_setSize_(address, addressSize); } free(buffer); return ioaddress; }
/*** Loudmouth callbacks ***/ void onXmppConnect(LmConnection *connection, int success, void* data) { IoObject *self = data; IoMessage *m; if(success == 1) { m = IoMessage_newWithName_label_(IOSTATE, IOSYMBOL("handleConnect"), IOSYMBOL("Loudmouth")); IoMessage_locals_performOn_(m, self, self); lm_connection_authenticate( connection, CSTRING(IoObject_getSlot_(self, IOSYMBOL("username"))), CSTRING(IoObject_getSlot_(self, IOSYMBOL("password"))), CSTRING(IoObject_getSlot_(self, IOSYMBOL("resource"))), onXmppAuth, data, NULL, NULL ); } else { m = IoMessage_newWithName_label_(IOSTATE, IOSYMBOL("handleConnectFailure"), IOSYMBOL("Loudmouth")); IoMessage_locals_performOn_(m, self, self); } }
IoCFFIArray *IoCFFIArray_at(IoCFFIArray *self, IoObject *locals, IoMessage *m) { int pos; char *ptr; //TODO check limits pos = CNUMBER(IoMessage_locals_numberArgAt_(m, locals, 0)); ptr = ((char *)DATA(self)->buffer) + (DATA(self)->itemSize * pos); return IoCFFIDataType_objectFromData_(IoObject_getSlot_(self, IOSYMBOL("arrayType")), (void *)ptr); }
IoObject *IoCFFIPointer_at(IoCFFIPointer *self, IoObject *locals, IoMessage *m) { int pos; IoObject *pointedToType; char *ptr; pos = CNUMBER(IoMessage_locals_numberArgAt_(m, locals, 0)); pointedToType = IoObject_getSlot_(self, IOSYMBOL("pointedToType")); ptr = ((char *)*(DATA(self)->valuePointer)) + (IoCFFIDataType_ffiType(pointedToType)->size * pos); return IoCFFIDataType_objectFromData_(pointedToType, (void *)ptr); }
IO_METHOD(IoDate, asString) { /*doc Date asString(optionalFormatString) Returns a string representation of the receiver using the receivers format. If the optionalFormatString argument is present, the receiver's format is set to it first. Formatting is according to ANSI C date formatting rules. <p> <pre> %a abbreviated weekday name (Sun, Mon, etc.) %A full weekday name (Sunday, Monday, etc.) %b abbreviated month name (Jan, Feb, etc.) %B full month name (January, February, etc.) %c full date and time string %d day of the month as two-digit decimal integer (01-31) %H hour as two-digit 24-hour clock decimal integer (00-23) %I hour as two-digit 12-hour clock decimal integer (01-12) %m month as a two-digit decimal integer (01-12) %M minute as a two-digit decimal integer (00-59) %p either "AM" or "PM" %S second as a two-digit decimal integer (00-59) %U number of week in the year as two-digit decimal integer (00-52) with Sunday considered as first day of the week %w weekday as one-digit decimal integer (0-6) with Sunday as 0 %W number of week in the year as two-digit decimal integer (00-52) with Monday considered as first day of the week %x full date string (no time); in the C locale, this is equivalent to "%m/%d/%y". %y year without century as two-digit decimal number (00-99) %Y year with century as four-digit decimal number %Z time zone name (e.g. EST); null string if no time zone can be obtained %% stands for '%' character in output string. </pre> */ char *format = "%Y-%m-%d %H:%M:%S %Z"; if (IoMessage_argCount(m) == 1) { format = CSTRING(IoMessage_locals_symbolArgAt_(m, locals, 0)); } else { IoObject *f = IoObject_getSlot_(self, IOSYMBOL("format")); if (ISSEQ(f)) { format = CSTRING(f); } } { UArray *ba = Date_asString(DATA(self), format); return IoState_symbolWithUArray_copy_(IOSTATE, ba, 0); } }
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); }
IoSecureServer *IoSecureServer_dispatchUDP(IoSecureServer *self, IoObject *locals, IoMessage *msg) { SSL_CTX *ctx = OCTX(self); IoSocket *sock = IoObject_getSlot_(self, IOSYMBOL("socket")); IoIPAddress *ioaddress = IoObject_getSlot_(sock, IOSYMBOL("ipAddress")); IPAddress *address = IoIPAddress_rawIPAddress(ioaddress); socklen_t addressSize = IPAddress_size(address); IoSecureSocket *ssock = IoMessage_locals_secureSocketArgAt_(msg, locals, 0); SSL *ssl = IoSecureSocket_SSL(ssock); int fd = IoSocket_rawDescriptor(sock); int bytesPerRead = IoNumber_asLong(IoObject_getSlot_(sock, IOSYMBOL("bytesPerRead"))); char *buffer = calloc(bytesPerRead, sizeof(char)); //debugPrintf("errno going in: %i\n", errno); int bytesRead = recvfrom(fd, buffer, bytesPerRead, 0, IPAddress_sockaddr(address), &addressSize); //debugPrintf("Read %i/%i : %i\n", bytesRead, bytesPerRead, errno); if(bytesRead > 0) { BIO_write(ssl->rbio, buffer, bytesRead); } free(buffer); return IOBOOL(self, bytesRead > 0); }
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)); }
IoSecureSocket *IoSecureServer_dtlsWrap(IoSecureServer *self, IoObject *locals, IoMessage *msg) { SSL_CTX *ctx = OCTX(self); IoSocket *sock = IoObject_getSlot_(self, IOSYMBOL("socket")); IoIPAddress *ioip = IoMessage_locals_addressArgAt_(msg, locals, 0); IPAddress *ip = IoIPAddress_rawIPAddress(ioip); struct sockaddr *addr = IPAddress_sockaddr(ip); IoNumber *port = IoObject_getSlot_(sock, IOSYMBOL("port")); int fd = IoSocket_rawDescriptor(sock); SSL *ssl = SSL_new(ctx); BIO *rbio = BIO_new(BIO_s_mem()); BIO_set_mem_eof_return(rbio, -1); BIO *wbio = BIO_new_dgram(fd, BIO_NOCLOSE); BIO_dgram_set_peer(wbio, addr); SSL_set_bio(ssl, rbio, wbio); SSL_set_accept_state(ssl); set_nonblocking(wbio); SSL_set_mode(ssl, SSL_MODE_ENABLE_PARTIAL_WRITE | SSL_MODE_ACCEPT_MOVING_WRITE_BUFFER); IoSecureSocket *ssock = IoSecureSocket_newWithSSL_IP_(IoObject_state(self), ssl, ioip); return ssock; }
void *IoCFFILibrary_rawGetFuctionPointer_(IoCFFILibrary *self, const char *name) { DynLib *library = DATA(self)->library; if (!library) { const char *name = CSTRING(IoObject_getSlot_(self, IOSYMBOL("name"))); library = DATA(self)->library = DynLib_new(); DynLib_setPath_(library, name); DynLib_open(library); } return DynLib_pointerForSymbolName_(library, name); }
IoCFFIArray *IoCFFIArray_at(IoCFFIArray *self, IoObject *locals, IoMessage *m) { int pos; char *ptr; pos = CNUMBER(IoMessage_locals_numberArgAt_(m, locals, 0)); if ( pos >= DATA(self)->arraySize ) { IoState_error_(IOSTATE, m, "index out of bounds"); return IONIL(self); } ptr = ((char *)DATA(self)->buffer) + (DATA(self)->itemSize * pos); return IoCFFIDataType_objectFromData_(IoObject_getSlot_(self, IOSYMBOL("arrayType")), (void *)ptr); }
LmHandlerResult onXmppMessage (LmMessageHandler *handler, LmConnection *connection, LmMessage *m, void* data) { IoObject *self = data; IoList_rawAppend_( (IoList *)IoObject_getSlot_(self, IOSYMBOL("_msgsBuffer")), IOSYMBOL(lm_message_node_to_string(m->node)) ); IoMessage *io_m = IoMessage_newWithName_label_(IOSTATE, IOSYMBOL("parseMessage"), IOSYMBOL("Loudmouth")); IoMessage_locals_performOn_(io_m, self, self); return LM_HANDLER_RESULT_REMOVE_MESSAGE; }
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; }
IoCFFIArray *IoCFFIArray_rawClone(IoCFFIArray *proto) { IoObject *self = IoObject_rawClonePrimitive(proto); IoObject_setDataPointer_(self, io_calloc(1, sizeof(IoCFFIArrayData))); memset(DATA(self), 0, sizeof(IoCFFIArrayData)); IoObject* arrayType = IoObject_getSlot_(proto, IOSYMBOL("arrayType")); if ( !ISNIL(arrayType) ) { DATA(self)->ffiType = DATA(proto)->ffiType; DATA(self)->itemSize = DATA(proto)->itemSize; DATA(self)->arraySize = DATA(proto)->arraySize; DATA(self)->buffer = io_calloc(DATA(self)->arraySize, DATA(self)->itemSize); DATA(self)->needToFreeBuffer = 1; } return self; }
IoObject *IoCInvokeStructureInstance_setValue(IoCInvokeStructureInstance *self, IoObject *locals, IoMessage *m) { CInvContext* context = getGlobalContext(); CInvStructure* structure = IoCInvokeStructure_getStructure_(IoObject_getSlot_(self, IOSYMBOL("structure"))); if(!DATA(self)->instance) { DATA(self)->instance = cinv_structure_create_instance(context, structure); } char* name = IoMessage_locals_cStringArgAt_(m, locals, 0); void* value = IoCInvokeDataType_ValuePointerFromObject_(IoMessage_locals_valueArgAt_(m, locals, 1)); if(!cinv_structure_instance_setvalue(context, structure, DATA(self)->instance, name, value)) { printf("Something went wrong with StructureInstance setValue\n"); }; return self; }
IoObject *IoEvDNSRequest_resolveIPv4(IoEvDNSRequest *self, IoObject *locals, IoMessage *m) { IoSeq *host = IoObject_seqGetSlot_(self, IOSYMBOL("host")); IoEvDNS *evDns = IoObject_getSlot_(self, IOSYMBOL("evDns")); IOASSERT(ISEVDNS(evDns), "evDns slot not set properly"); struct evdns_base *dnsBase = IoObject_dataPointer(evDns); struct evdns_request *req = evdns_base_resolve_ipv4(dnsBase, CSTRING(host), DNS_QUERY_NO_SEARCH, (EvDNSRequest_callback_type)EvDNSRequest_callback, (void *)self ); IoObject_setDataPointer_(self, req); return self; }
IoCFFIArray *IoCFFIArray_atPut(IoCFFIArray *self, IoObject *locals, IoMessage *m) { int pos; IoObject *value, *d; char *ptr; //TODO check limits and types pos = CNUMBER(IoMessage_locals_numberArgAt_(m, locals, 0)); value = IoMessage_locals_valueArgAt_(m, locals, 1); ptr = ((char *)DATA(self)->buffer) + (DATA(self)->itemSize * pos); d = IOCLONE(IoObject_getSlot_(self, IOSYMBOL("arrayType"))); IoCFFIDataType_rawSetValue(d, value); memcpy(ptr, (void *)IoCFFIDataType_ValuePointerFromObject_(NULL, d), DATA(self)->itemSize); return self; }
IoObject *IoCFFIPointer_atPut(IoCFFIPointer *self, IoObject *locals, IoMessage *m) { int pos; IoObject *value, *pointedToType, *d; char *ptr; //TODO comprobar overrun y coincidencia de tipos pos = CNUMBER(IoMessage_locals_numberArgAt_(m, locals, 0)); value = IoMessage_locals_valueArgAt_(m, locals, 1); pointedToType = IoObject_getSlot_(self, IOSYMBOL("pointedToType")); ptr = ((char *)*(DATA(self)->valuePointer)) + (IoCFFIDataType_ffiType(pointedToType)->size * pos); d = IOCLONE(pointedToType); IoCFFIDataType_rawSetValue(d, value); memcpy(ptr, (void *)IoCFFIDataType_ValuePointerFromObject_(NULL, d), IoCFFIDataType_ffiType(pointedToType)->size); return self; }
IoSecureSocket *IoSecureServer_tlsWrap(IoSecureServer *self, IoObject *locals, IoMessage *msg) { SSL_CTX *ctx = OCTX(self); IoSocket *sock = IoMessage_locals_socketArgAt_(msg, locals, 0); IoNumber *port = IoObject_getSlot_(sock, IOSYMBOL("port")); SSL *ssl = SSL_new(ctx); SSL_set_fd(ssl, IoSocket_rawDescriptor(sock)); set_nonblocking(SSL_get_rbio(ssl)); set_nonblocking(SSL_get_wbio(ssl)); SSL_set_accept_state(ssl); SSL_set_mode(ssl, SSL_MODE_ENABLE_PARTIAL_WRITE | SSL_MODE_ACCEPT_MOVING_WRITE_BUFFER); IoIPAddress *ioaddr = IoIPAddress_new(IoObject_state(self)); IPAddress *iaddr = IoIPAddress_rawIPAddress(ioaddr); IPAddress_setIp_(iaddr, "0.0.0.0"); IPAddress_setPort_(iaddr, IoNumber_asLong(port)); IoSecureSocket *ssock = IoSecureSocket_newWithSSL_IP_(IoObject_state(self), ssl, ioaddr); return ssock; }
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 *IoTokyoCabinetPrefixCursor_last(IoObject *self, IoObject *locals, IoMessage *m) { /*doc TokyoCabinetPrefixCursor last Move cursor to last record. Returns self */ IoSeq *prefix = IoObject_getSlot_(self, IOSYMBOL("prefix")); IOASSERT(ISSEQ(prefix), "prefix must be a sequence"); IOASSERT(TokyoCabinetPrefixCursor(self), "invalid TokyoCabinetPrefixCursor"); { UArray *p = UArray_clone(IoSeq_rawUArray(prefix)); UArray_appendCString_(p, " "); // space preceeds . tcbdbcurjump(TokyoCabinetPrefixCursor(self), (const void *)UArray_bytes(p), (int)UArray_size(p)); UArray_free(p); } return IOBOOL(self, IoTokyoCabinetPrefixCursor_keyBeginsWithPrefix_(self, prefix)); }
//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; }
IoCFFIPointer *IoCFFIPointer_ToType_(IoObject *type) { IoObject *pointer, *self; IoMap *pointers; IoSymbol *key; // this is a hack so macros relying on self will work self = type; pointers = IoObject_getSlot_(IoState_protoWithInitFunction_(IOSTATE, IoCFFIPointer_proto), IOSYMBOL("pointers")); key = IoState_on_doCString_withLabel_(IOSTATE, type, "uniqueHexId", "IoCFFIPointer_ToType_"); pointer = IoMap_rawAt(pointers, key); if (!pointer) { // create new pointer and add to cache pointer = IoCFFIPointer_new(IOSTATE); IoObject_setSlot_to_(pointer, IOSYMBOL("pointedToType"), type); IoMap_rawAtPut(pointers, key, pointer); } return pointer; }