Пример #1
0
IoObject *IoCertificate_asnTimeToDate(IoCertificate *self, ASN1_TIME *tm)
{
	char *v;
	int gmt=0;
	int i;
	int y=0,M=0,d=0,h=0,m=0,s=0;

	i=tm->length;
	v=(char *)tm->data;

	if (i < 10) return IONIL(self);
	if (v[i-1] == 'Z') gmt=1;
	for (i=0; i<10; i++)
		if ((v[i] > '9') || (v[i] < '0')) return IONIL(self);
	y= (v[0]-'0')*10+(v[1]-'0');
	if (y < 50) y+=100;
	M= (v[2]-'0')*10+(v[3]-'0');
	if ((M > 12) || (M < 1)) return IONIL(self);
	d= (v[4]-'0')*10+(v[5]-'0');
	h= (v[6]-'0')*10+(v[7]-'0');
	m=  (v[8]-'0')*10+(v[9]-'0');
	if (	(v[10] >= '0') && (v[10] <= '9') &&
		(v[11] >= '0') && (v[11] <= '9'))
		s=  (v[10]-'0')*10+(v[11]-'0');
	struct tm ctm;
	ctm.tm_sec = s;
	ctm.tm_min = m;
	ctm.tm_hour = h;
	ctm.tm_mday = d;
	ctm.tm_mon = M-1;
	ctm.tm_year = y;
	ctm.tm_gmtoff = 0;
		
	return IoDate_newWithTime_(IoObject_state(self), timegm(&ctm));
}
Пример #2
0
Файл: IoDBI.c Проект: BMeph/io
IoObject *IoDBI_with(IoDBI *self, IoObject *locals, IoMessage *m)
{
	//doc DBI with(driverName) Get a new connection with the given driver.
	
	IoObject *name = IoMessage_locals_valueArgAt_(m, locals, 0);
	if (!ISSYMBOL(name))
	{
		IoState_error_(IOSTATE, m, "argument 0 to method '%s' must be a Symbol, not a '%s'\n",
			CSTRING(IoMessage_name(m)), IoObject_name(name));
		return IONIL(self);
	}

	if (DATA(self)->didInit != 1)
	{
		IoDBI_init(self, locals, m);
	}

	dbi_conn c = dbi_conn_new(CSTRING(name));
	if (c == NULL)
	{
		IoState_error_(IOSTATE, m, "libdbi error during dbi_conn_new\n");
		return IONIL(self);
	}

	return IoDBIConn_new(IOSTATE, c);
}
Пример #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;
}
Пример #4
0
IoDynLib *IoDynLib_callPluginInitFunc(IoDynLib *self, IoObject *locals, IoMessage *m)
{
	/*doc DynLib callPluginInit(functionName)
	Call's the dll function of the specified name. 
	Returns the result as a Number or raises an exception on error.
	*/
	
	intptr_t rc = 0;
	intptr_t *params = NULL;
	void *f = DynLib_pointerForSymbolName_(DATA(self),
									CSTRING(IoMessage_locals_symbolArgAt_(m, locals, 0)));
	if (f == NULL)
	{
		IoState_error_(IOSTATE, m, "Error resolving call '%s'.",
					CSTRING(IoMessage_locals_symbolArgAt_(m, locals, 0)));
		return IONIL(self);
	}

	if (IoMessage_argCount(m) < 1)
	{
		IoState_error_(IOSTATE, m, "Error, you must give an init function name to check for.");
		return IONIL(self);
	}

	params = io_calloc(1, sizeof(intptr_t) * 2);

	params[0] = (intptr_t)IOSTATE;
	params[1] = (intptr_t)IOSTATE->lobby;
	rc = ((intptr_t (*)(intptr_t, intptr_t))f)(params[0], params[1]);
	io_free(params);

	return IONUMBER(rc);
}
Пример #5
0
static IoRegexMatch *IoRegexMatches_searchFrom_withOptions_(IoRegexMatches *self, IoMessage *m, int position, int options)
{
	Regex *regex = IoRegex_rawRegex(DATA(self)->regex);
	int *captures = 0;
	int *capture = 0;
	IoList *rangeList = 0;
	int i = 0;

	int captureCount = Regex_search_from_to_withOptions_captureArray_(
		regex,
		CSTRING(DATA(self)->string),
		position,
		DATA(self)->endPosition,
		options,
		DATA(self)->captureArray
	);

	if (Regex_error(regex))
		IoState_error_(IOSTATE, m, Regex_error(regex));

	if (captureCount == 0)
		return IONIL(self);

	/* The search function puts information about captured substrings in captureArray.
	There's a pair of integers for each capture. The first element of the pair is the
	start index of the substring, and the second element is the end index.
	The first pair represents the entire match. */
	captures = (int *)UArray_data(DATA(self)->captureArray);
	DATA(self)->position = captures[1];
	DATA(self)->currentMatchIsEmpty = (captures[0] == captures[1]);

	capture = captures;
	rangeList = IoList_new(IOSTATE);
	for (i = 0; i < captureCount; i++) {
		IoObject *element = 0;
		// unsure about this locals initialization ...
		IoObject *locals = NULL;
		IoMessage *message = IoMessage_new(IOSTATE);

		if (capture[0] == -1 && capture[1] == -1) {
			/* This capture was not matched. */
			element = IONIL(self);
		} else {
			element = IoRange_new(IOSTATE);
			IoMessage_setCachedArg_to_(message, 0, IONUMBER(capture[0]));
			IoMessage_setCachedArg_to_(message, 1, IONUMBER(capture[1]));
			IoRange_setRange(element, locals, message);
			IoRange_setFirst(element, IONUMBER(capture[0]));
			IoRange_setLast(element, IONUMBER(capture[1]));
		}

		IoList_rawAppend_(rangeList, element);
		capture += 2;
	}

	return IoRegexMatch_newWithRegex_subject_captureRanges_(IOSTATE, DATA(self)->regex, DATA(self)->string, rangeList);
}
Пример #6
0
IO_METHOD(IoNumber, asCharacter)
{
	/*doc Number asCharacter
	Returns a String containing a single character whose
	value is the value of the first byte of the receiver.
	Returns nil if the number has no valid UCS mapping.
	*/
	
	double d =DATA(self);
	long ld = d;
	
	if (d < 0 || d != ld)
	{
		return IONIL(self);
	}
	else
	{	
		uint32_t i = io_uint32InBigEndian((uint32_t)d);
		int bytes = countBytes(ld);
		IoSeq *s;
		
		if (bytes == 0) 
		{ 
			bytes = 1;
		}
		
		if (bytes == 3) 
		{ 
			bytes = 4;
		}
		
		if (bytes > 4) 
		{
			// no valid UCS encoding for this value
			return IONIL(self);
		}
		
		s = IoSeq_newWithData_length_(IOSTATE, (unsigned char *)&i, bytes);
		
		{
			UArray *u = IoSeq_rawUArray(s);
			int e = CENCODING_ASCII;
			
			switch (bytes)
			{
				case 1: e = CENCODING_ASCII; break;
				case 2: e = CENCODING_UCS2; break;
				case 4: e = CENCODING_UCS4; break;
			}
			
			UArray_setEncoding_(u, e);
		}
		
		return s;
	}
}
Пример #7
0
IoObject *IoAVCodec_decode(IoAVCodec *self, IoObject *locals, IoMessage *m)
{
	/*doc AVCodec decode
	Decodes the next chunk of input data. 
	Output (if any) is placed in the outputBuffers. 
	Returns self.
	*/
	
	AVFormatContext *formatContext = DATA(self)->formatContext;
	int audioStreamIndex = DATA(self)->audioStreamIndex;
	int videoStreamIndex = DATA(self)->videoStreamIndex;
	AVPacket *packet = DATA(self)->packet;
	int ret;


	if(DATA(self)->audioContext == NULL && DATA(self)->videoContext == NULL)
	{
		//printf("not open\n");
		return IONIL(self);
	}

	ret = av_read_frame(formatContext, packet);

	if (ret < 0)
	{
		//printf("av_read_frame ret = %i\n", ret);

		if(ret == AVERROR_IO)
		{
			DATA(self)->isAtEnd = 1;
		}

		return IONIL(self);
	}

	if (packet->stream_index == audioStreamIndex && DATA(self)->audioContext)
	{
		IoAVCodec_decodeAudioPacket(self,
			formatContext->streams[audioStreamIndex]->codec,
			packet->data, packet->size);
	}
	else if (packet->stream_index == videoStreamIndex && DATA(self)->videoContext)
	{
		IoAVCodec_decodeVideoPacket(self,
			formatContext->streams[videoStreamIndex]->codec,
			packet->data, packet->size);
	}
	else
	{
		av_free_packet(packet);
	}

	return self;
}
Пример #8
0
IO_METHOD(IoMessage, previous)
{
	/*doc Message previous
	Returns the previous message in the message chain or Nil if there is no previous message. 
	*/
	
#ifdef IOMESSAGE_HASPREV
	return DATA(self)->previous ? (IoObject *)DATA(self)->previous : IONIL(self);
#else
	return IONIL(self);
#endif
}
Пример #9
0
IoObject *IoCairoPathElement_pointAt(IoCairoPathElement *self, IoObject *locals, IoMessage *m)
{
	cairo_path_data_t *data = 0;
	int pointCount = 0;
	int i = 0;

	if (!DATA(self)) return IONIL(self);

	i = IoMessage_locals_intArgAt_(m, locals, 0);
	pointCount = IoCairoPathElement_pointCount(self);
	if (i < 0 || i >= pointCount) return IONIL(self);

	data = PATH_DATA(self) + i + 1;
	return IoSeq_newWithX_y_(IOSTATE, data->point.x, data->point.y);
}
Пример #10
0
IoObject *IoSocket_asyncUdpRead(IoSocket *self, IoObject *locals, IoMessage *m)
{
	/*doc Socket asyncUdpRead(ipAddress, aSeq, readSize) 
	Reads up to readSize number of bytes from ipAddress into aSeq if data is available. 
	Returns self immediately if successful. Returns an error object on Error. Returns nil if the socket is disconnected.
	*/
	
	IoObject *address = IoMessage_locals_addressArgAt_(m, locals, 0);
	UArray *buffer = IoSeq_rawUArray(IoMessage_locals_mutableSeqArgAt_(m, locals, 1));
	size_t readSize = IoMessage_locals_sizetArgAt_(m, locals, 2);
	
	if (Socket_udpRead(SOCKET(self), IoSocket_rawAddressFrom_(address), buffer, readSize))
	{
		return self;
	}
	else
	{
		if (Socket_asyncFailed())
		{
			return SOCKETERROR("Socket udp read failed");
		}
		else
		{
			return IONIL(self);
		}
	}
}
Пример #11
0
Файл: IoFile.c Проект: achoy/io
IO_METHOD(IoFile, contents)
{
	/*doc File contents
	Returns contents of the file as a mutable Sequence of bytes.
	*/

	UArray *ba = UArray_new();
	long result = -1;

	if (DATA(self)->stream == stdin)
	{
		result = UArray_readFromCStream_(ba, DATA(self)->stream);
	}
	else
	{
		result = UArray_readFromFilePath_(ba, IoSeq_rawUArray(DATA(self)->path));
	}

	if (result != -1)
	{
		return IoSeq_newWithUArray_copy_(IOSTATE, ba, 0);
	}
	else
	{
		UArray_free(ba);
		IoState_error_(IOSTATE, m, "unable to read file '%s'", UTF8CSTRING(DATA(self)->path));
	}

	return IONIL(self);
}
Пример #12
0
IoObject *IoSocket_asyncAccept(IoSocket *self, IoObject *locals, IoMessage *m)
{
	//doc Socket asyncAccept(addressObject) Immediately returns a socket for a connection if one is available or nil otherwise. Returns an Error object on error.

	IoObject *address = IoMessage_locals_addressArgAt_(m, locals, 0);
	Socket *socket = Socket_accept(SOCKET(self), IoSocket_rawAddressFrom_(address));

	if (socket)
	{
		IoObject *newSocket = IoSocket_newWithSocket_(IOSTATE, socket);
		newSocket = IoObject_initClone_(self, locals, m, newSocket);
		return IoSocket_rawSetupEvents(newSocket, locals, m);
	}
	else
	{
		if (Socket_asyncFailed())
		{
			return SOCKETERROR("Socket accept failed");
		}
		else
		{
			return IONIL(self);
		}
	}
}
Пример #13
0
IO_METHOD(IoSeq, asBinarySignedInteger)
{
	/*doc Sequence asBinarySignedInteger
	Returns a Number with the bytes of the receiver interpreted as a binary signed integer. Endian is same as machine.
	*/

	const void *bytes = UArray_bytes(DATA(self));
	size_t byteCount = UArray_size(DATA(self));

	if(byteCount == 1)
	{
		return IONUMBER(*((const int8_t *)bytes));
	} 
	else if(byteCount == 2)
	{
		return IONUMBER(*((const int16_t *)bytes));
	} 
	else if(byteCount == 4)
	{
		return IONUMBER(*((const int32_t *)bytes));
	} 
	else 
	{
		IoState_error_(IOSTATE, m, "Sequence is %i bytes but only conversion of 1, 2, or 4 bytes is supported", byteCount);
	}

	return IONIL(self);
}
Пример #14
0
IO_METHOD(IoDirectory, createSubdirectory)
{
    /*doc Directory createSubdirectory(name)
    Create a subdirectory with the specified name.
    */

    IoState *state = IOSTATE;
    IoSymbol *subfolderName = IoMessage_locals_symbolArgAt_(m, locals, 0);
    IoObject *currentItem = IoDirectory_justAt(self, subfolderName);

    if (ISDIRECTORY(currentItem))
    {
        return currentItem;
    }

    if (ISFILE(currentItem))
    {
        IoState_error_(IOSTATE, m, "Attempt to create directory %s on top of existing file",
                       CSTRING(subfolderName));
    }
    else
    {
        IoSymbol *fullPath = IoDirectory_justFullPath(self, subfolderName);

        MKDIR(CSTRING(fullPath), S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
        return IoDirectory_newWithPath_(state, fullPath);
    }

    return IONIL(self);
}
Пример #15
0
IoObject *IoMessage_locals_addressArgAt_(IoMessage *self, IoObject *locals, int n)
{
	IoObject *v = IoMessage_locals_valueArgAt_(self, locals, n);

	if(ISIPADDRESS(v))
	{
		return v;
	}
#if !defined(_WIN32) || defined(__CYGWIN__)
	else if(ISUNIXPATH(v))
	{
		return v;
	}
#endif
	else
	{
#if !defined(_WIN32) || defined(__CYGWIN__)
		char *type = "IPAddress or UnixPath";
#else
		char *type = "IPAddress";
#endif
		IoMessage_locals_numberArgAt_errorForType_(self, locals, n, type);
	}
	
	return IONIL(self);
}
Пример #16
0
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;
}
Пример #17
0
IoObject *IoRegexMatches_next(IoRegexMatches *self, IoObject *locals, IoMessage *m)
{
	/*doc RegexMatches next
	Returns the next match, or nil if there is none.
	*/
	IoRegexMatch *match = 0;

	if (DATA(self)->position >= DATA(self)->endPosition)
		/* We've passed the end position, so we're done. */
		return IONIL(self);

	if (!DATA(self)->currentMatchIsEmpty)
		/* The previous match was not a zero length match, so we can just continue searching
		from the end of that match. */
		return IoRegexMatches_search(self, m);

	/* The last match was a zero length match. If we just continue searching as normal,
	we'll get the same empty match again, and we'll end up in an infinite loop when trying
	to iterate through all matches. Instead we try to find an alternative match by performing
	a search using the options PCRE_NOTEMPTY and PCRE_ANCHORED: */
	match = IoRegexMatches_searchWithOptions_(self, m, PCRE_NOTEMPTY | PCRE_ANCHORED);
	if (!ISNIL(match))
		return match;

	/* No alternative match was found, so we do what Perl does: we advance our position
	by one character, and continue searching from there: */
	++DATA(self)->position;
	return IoRegexMatches_search(self, m);
}
Пример #18
0
IoObject *IoAsyncRequest_write(IoAsyncRequest *self, IoObject *locals, IoMessage *m)
{
	/*doc AsyncRequest write(fileOffset, aSeq, bufferOffset, numberOfBytesToWrite)
	Submits an async write request. Returns nil on error, self otherwise. 
	*/
	
	int r;
	IoSeq *data;
	UArray *ba;
	int bufferOffset;
	int bytesToWrite;

	IOCB(self)->aio_offset = (size_t)CNUMBER(IoMessage_locals_numberArgAt_(m, locals, 0));

	data = IoMessage_locals_seqArgAt_(m, locals, 1);
	ba = IoSeq_rawUArray(data);

	bufferOffset = IoMessage_locals_intArgAt_(m, locals, 2);
	bytesToWrite = IoMessage_locals_intArgAt_(m, locals, 3);

	if (bytesToWrite > UArray_size(ba) - bufferOffset)
	{
		bytesToWrite = UArray_size(ba) - bufferOffset;
	}

	IOCB(self)->aio_nbytes = bytesToWrite;
	IOCB(self)->aio_buf = realloc(IOCB_BUFFER(self), bytesToWrite);
	memcpy(IOCB_BUFFER(self), UArray_bytes(ba), bytesToWrite);

	r = aio_write(IOCB(self));

	return r == 0 ? self : IONIL(self);
}
Пример #19
0
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);
}
Пример #20
0
IO_METHOD(IoSandbox, doSandboxString)
{
	/*doc Sandbox doSandboxString(aString)
	Evaluate aString inside the Sandbox.
	*/

	IoState *boxState = IoSandbox_boxState(self);
	char *s = IoMessage_locals_cStringArgAt_(m, locals, 0);

	IoObject *result = IoState_doSandboxCString_(boxState, s);

	if (ISSYMBOL(result))
	{
		return IOSYMBOL(CSTRING(result));
	}

	if (ISSEQ(result))
	{
		return IOSEQ(IOSEQ_BYTES(result), IOSEQ_LENGTH(result));
	}

	if (ISNUMBER(result))
	{
		return IONUMBER(CNUMBER(result));
	}

	return IONIL(self);
}
Пример #21
0
IO_METHOD(IoObject, errorNumberDescription)
{
	/*doc System errorNumber
	Returns the C errno string.
	*/
	return errno ? IOSYMBOL(strerror(errno)) : IONIL(self);
}
Пример #22
0
IoObject *IoAVCodec_open(IoAVCodec *self, IoObject *locals, IoMessage *m)
{
	/*doc AVCodec open
	Opens the input file. Return self on success or raises an exception on error.
	*/
	
	int err;

	IoAVCodec_registerIfNeeded(self);
	IoAVCodec_freeContextIfNeeded(self);
	IoAVCodec_createContextIfNeeded(self);

	DATA(self)->isAtEnd = 0;

	err = IoAVCodec_openFile(self);

	if (err != 0)
	{
		IoObject *fileName = IoObject_symbolGetSlot_(self, IOSYMBOL("path"));
		IoState_error_(IOSTATE, m, "error %i opening file %s\n", err, CSTRING(fileName));
		return IONIL(self);
	}

	IoAVCodec_findStreams(self);
	av_read_play(DATA(self)->formatContext);

	return self;
}
Пример #23
0
IoObject *IoSQLite3_execWithCallback(IoSQLite3 *self,
									 IoObject *locals, IoMessage *m, IoSymbol *s, ResultRowCallback *callback)
{
	IoList *results;

	if (!DATA(self)->db)
	{
		IoSQLite3_justOpen(self);

		if (!DATA(self)->db)
		{
			return IONIL(self);
		}
	}

	DATA(self)->results = IOREF(IoList_new(IOSTATE));

	if (DATA(self)->debugOn)
	{
		IoState_print_(IOSTATE, "*** %s ***\n", CSTRING(s));
	}

	{
		char *zErrMsg;
		sqlite3_exec(DATA(self)->db, CSTRING(s), callback, self, &zErrMsg);

		IoSQLite3_showError(self);
	}

	results = DATA(self)->results;
	DATA(self)->results = NULL;
	return results;
}
Пример #24
0
IoObject *IoSocket_asyncStreamRead(IoSocket *self, IoObject *locals, IoMessage *m)
{
	/*doc Socket asyncStreamRead(aSeq, readSize) 
	Reads up to readSize number of bytes into aSeq if data is available. 
	Returns self immediately if successful. Returns an error object on Error. Returns nil if the socket is disconnected.
	*/
	
	IoSeq *bufferSeq = IoMessage_locals_mutableSeqArgAt_(m, locals, 0);
	UArray *buffer = IoSeq_rawUArray(bufferSeq);
	size_t readSize = IoMessage_locals_intArgAt_(m, locals, 1);

	if (Socket_streamRead(SOCKET(self), buffer, readSize))
	{
		return self;
	}

	if (Socket_asyncFailed())
	{
		IoSocket_close(self, locals, m);
		return SOCKETERROR("Socket stream read failed");
	}

	//if (readSize == 0) //SocketErrorStatus() == 0)
	if (SocketErrorStatus() == 0)
	{
		// 0 bytes means the other end disconnected
		//printf("SocketErrorStatus() == 0, closing\n");
		IoSocket_close(self, locals, m);
	}
	
	return IONIL(self);
}
Пример #25
0
IoRegexMatch *IoRegexMatch_proto(void *state)
{
	IoObject *self = IoObject_new(state);
	IoObject_tag_(self, IoRegexMatch_newTag(state));

	IoObject_setDataPointer_(self, calloc(1, sizeof(IoRegexMatchData)));
	DATA(self)->regex = IONIL(self);
	DATA(self)->subject = IOSYMBOL("");
	DATA(self)->ranges = IoList_new(state);

	IoState_registerProtoWithFunc_(state, self, IoRegexMatch_proto);

	{
		IoMethodTable methodTable[] = {
			{"regex", IoRegexMatch_regex},
			{"subject", IoRegexMatch_subject},
			{"ranges", IoRegexMatch_ranges},
			{0, 0},
		};

		IoObject_addMethodTable_(self, methodTable);
	}

	return self;
}
Пример #26
0
IoObject *IoCFFIPointer_castTo(IoCFFIPointer *self, IoObject *locals, IoMessage *m)
{
    IoObject *toType = IoMessage_locals_valueArgAt_(m, locals, 0);
    IoObject *o = IoState_on_doCString_withLabel_(IOSTATE, toType, "?typeString", "IoCFFIPointer_castTo");

    if(!ISNIL(o)) {
        char *typeStr = CSTRING(o);

        switch(typeStr[0]) {
            case '^':
                toType = IOCLONE(toType);
                *(DATA(toType)->valuePointer) = *((void **)IoCFFIDataType_ValuePointerFromObject_(toType, self));
                return toType;
            case '*':
                toType = IOCLONE(toType);
                IoCFFIDataType_rawSetValue(toType, self);
                return toType;
            default:
                IoState_error_(IOSTATE, m, "Wrong type to cast to.");
                break;
        }
    }
    else {
        // Mm... well, if the type to cast to does not have a typeString slot,
        // it should be an Io Object, so the address stored here is a pointer to an
        // Io Object. Simply cast the pointer and return it... dangerous but...
        
        IoObject *obj = (IoObject *)*(DATA(self)->valuePointer);
        if(ISOBJECT(obj))
            return (IoObject *)*(DATA(self)->valuePointer);
    }

    return IONIL(self);
}
Пример #27
0
IoMessage *IoMessage_rawPrevious(IoMessage *self)
{
#ifdef IOMESSAGE_HASPREV
	return DATA(self)->previous;
#else
	return IONIL(self);
#endif
}
Пример #28
0
IoObject *IoSocket_setSocketWriteBufferSize(IoSocket *self, IoObject *locals, IoMessage *m)
{
	//doc Socket setSocketWriteBufferSize(numberOfBytes) Sets the write buffer size for the socket. Returns self on success or nil on error.

	int size = IoMessage_locals_intArgAt_(m, locals, 0);
	int r = setsockopt(SOCKET(self)->fd, SOL_SOCKET, SO_SNDBUF, &size, sizeof(int));
	return (r == 0) ? self : IONIL(self);
}
Пример #29
0
IO_METHOD(IoMessage, next)
{
	/*doc Message next
	Returns the next message in the message chain or nil if there is no next message. 
	*/

	return DATA(self)->next ? (IoObject *)DATA(self)->next : IONIL(self);
}
Пример #30
0
IoObject *IoAudioDevice_isActive(IoAudioDevice *self, IoObject *locals, IoMessage *m)
{
	/*doc AudioDevice isActive
	Returns self if the receiver is active, Nil otherwise.
	*/

	return AudioDevice_isActive(DATA(self)->audioDevice) ? self : IONIL(self);
}