Beispiel #1
0
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;
}
Beispiel #2
0
Datei: IoDBI.c Projekt: BMeph/io
IoObject *IoDBI_drivers(IoDBI *self, IoObject *locals, IoMessage *m)
{
	/*doc DBI drivers
	Get a list of drivers and its associated information:

	<ol>
		<li>name</li>
		<li>description</li>
		<li>filename</li>
		<li>version</li>
		<li>date compiled</li>
		<li>maintainer</li>
		<li>url</li>
	</ol>
	*/
	IoList *list = IOREF(IoList_new(IOSTATE));
	dbi_driver driver = NULL;

	while((driver = dbi_driver_list(driver)) != NULL)
	{
		IoList *dlist = IOREF(IoList_new(IOSTATE));
		IoList_rawAppend_(dlist, IOSYMBOL(dbi_driver_get_name(driver)));
		IoList_rawAppend_(dlist, IOSYMBOL(dbi_driver_get_description(driver)));
		IoList_rawAppend_(dlist, IOSYMBOL(dbi_driver_get_filename(driver)));
		IoList_rawAppend_(dlist, IOSYMBOL(dbi_driver_get_version(driver)));
		IoList_rawAppend_(dlist, IOSYMBOL(dbi_driver_get_date_compiled(driver)));
		IoList_rawAppend_(dlist, IOSYMBOL(dbi_driver_get_maintainer(driver)));
		IoList_rawAppend_(dlist, IOSYMBOL(dbi_driver_get_url(driver)));

		IoList_rawAppend_(list, dlist);
	}

	return list;
}
Beispiel #3
0
int IoAVCodec_decodeVideoPacket(IoAVCodec *self, AVCodecContext *c, uint8_t *inbuf, size_t size)
{
	AVFrame *decodeFrame = DATA(self)->decodedFrame;

	while (size > 0)
	{
		int got_picture;
		size_t len = avcodec_decode_video(c, DATA(self)->decodedFrame, &got_picture, inbuf, size);

		if (len < 0)
		{
			printf("Error while decoding video packet\n");
			return -1;
		}

		if (got_picture)
		{
			IoList_rawAppend_(DATA(self)->frames, IoAVCode_frameSeqForAVFrame_(self, decodeFrame, c->pix_fmt, c->width, c->height));
		}

		size -= len;
		inbuf += len;
	}

	return 0;
}
Beispiel #4
0
void IoEvDNSRequest_callback(int result, char type, int count, int ttl, void *addresses, void *arg)
{
	IoEvDNSRequest *self = arg;
	//type is either DNS_IPv4_A or DNS_PTR or DNS_IPv6_AAAA

	IoObject_setSlot_to_(self, IOSYMBOL("ttl"), IONUMBER(ttl));

	if(result == DNS_ERR_NONE)
	{
		IoList *ioAddresses = IoList_new(IOSTATE);
		IoObject_setSlot_to_(self, IOSYMBOL("addresses"), ioAddresses);
		
		int i;
		for (i = 0; i < count; i ++)
		{
			//addresses needs to be cast according to type
			uint32_t a = ((uint32_t *)addresses)[i];
			struct in_addr addr;
			char *ip;
			addr.s_addr = htonl(get32(rr->rdata));
			ip = (char *)inet_ntoa(addr);
			IoList_rawAppend_(ioAddresses, IOSYMBOL(ip));
		}
	}
	else 
	{
		IoObject_setSlot_to_(self, IOSYMBOL("error"), IOSYMBOL("fail"));
	}

	
	IoMessage *m = IoMessage_newWithName_label_(IOSTATE, IOSYMBOL("handleResponse"), IOSYMBOL("IoEvDNSRequest"));
	IoMessage_locals_performOn_(m, self, self);
}
Beispiel #5
0
static int IoSQLite3_resultRow(void *context, int argc, char **argv, char **azColName)
{
	IoSQLite3 *self = context;
	IoState_pushRetainPool(IOSTATE);

	{
		IoMap *map = IoMap_new(IOSTATE);
		PHash *hash = IoMap_rawHash(map);
		int i;
		IoSymbol *key, *value;

		for(i = 0; i < argc; i ++)
		{
			key = IOSYMBOL(azColName[i]);

			if (argv[i])
			{
				value = IOSYMBOL(argv[i]);
			}
			else
			{
				value = IOSYMBOL((char *)"NULL");
			}

			PHash_at_put_(hash, key, value);
			/*printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL"); */
		}

		IoList_rawAppend_(DATA(self)->results, map);
	}

	IoState_popRetainPool(IOSTATE);

	return 0;
}
Beispiel #6
0
IoObject *IoCertificate_attributes(IoCertificate *self, IoObject *locals, IoMessage *m)
{
	IoObject *map = IoObject_new(IoObject_state(self));
	const EVP_PKEY *pkey = X509_extract_key(X509(self));
	int i;
	for(i = 0; i < EVP_PKEY_get_attr_count(pkey); i++)
	{
		IoList *list = IoList_new(IoObject_state(self));
		X509_ATTRIBUTE *attr = EVP_PKEY_get_attr(pkey, i);
		const char *key = (const char *)OBJ_nid2ln(OBJ_obj2nid(X509_ATTRIBUTE_get0_object(attr)));
		int j;
		for(j = 0; j < X509_ATTRIBUTE_count(attr); j++)
		{
			ASN1_TYPE *attrType = X509_ATTRIBUTE_get0_type(attr, j);
			ASN1_OBJECT *attrData = X509_ATTRIBUTE_get0_data(attr, j, attrType->type, NULL);
			//consider switching on attrType instead; 
			//really, that would be wiser, so that dates, 
			//numbers, etc can be happy
			/*
			switch(attrType->type) {
				case V_ASN1_OCTET_STRING:
			...
			*/
			int len = i2t_ASN1_OBJECT(NULL, 0, attrData);
			char *value = calloc(len, sizeof(char));
			i2t_ASN1_OBJECT(value, len, attrData);
			IoList_rawAppend_(list, IoSeq_newWithCString_(IoObject_state(self), value));
		}
		IoObject_setSlot_to_(map, IOSYMBOL(key), list);
	}
	return map;
}
Beispiel #7
0
IO_METHOD(IoDirectory, items)
{
    /*doc Directory items
    Returns a list object containing File and Directory objects
    for the files and directories of the receiver's path.
    */

    IoList *items = IoList_new(IOSTATE);
    IoDirectoryData *data = DATA(self);
    DIR *dirp = opendir(CSTRING(data->path));
    struct dirent *dp;

    if (!dirp)
    {
        IoState_error_(IOSTATE, m, "Unable to open directory %s", CSTRING(DATA(self)->path));
    }

    while ((dp = readdir(dirp)) != NULL)
    {
        IoList_rawAppend_(items, IoDirectory_itemForDirent_(self, dp));
    }

    (void)closedir(dirp);
    return items;
}
Beispiel #8
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);
}
Beispiel #9
0
IO_METHOD(IoClutterActor, getAllocationVertices) {
  ClutterVertex vertices[4] = {};
  IoList *result = IoList_new(IOSTATE);

  if(IoMessage_argCount(m) > 0) {
    ClutterActor *ancestor = IOCACTOR(IoMessage_locals_clutterActorArgAt_(m, locals, 0));
    clutter_actor_get_allocation_vertices(IOCACTOR(self), ancestor, vertices);
  } else {
    clutter_actor_get_allocation_vertices(IOCACTOR(self), NULL, vertices);
  }

  IoList_rawAppend_(result, IoClutterVertex_newWithVertex(IOSTATE, &vertices[0]));
  IoList_rawAppend_(result, IoClutterVertex_newWithVertex(IOSTATE, &vertices[1]));
  IoList_rawAppend_(result, IoClutterVertex_newWithVertex(IOSTATE, &vertices[2]));
  IoList_rawAppend_(result, IoClutterVertex_newWithVertex(IOSTATE, &vertices[3]));

  return result;
}
Beispiel #10
0
IO_METHOD(IoObject, symbols)
{
	/*doc System symbols
	Returns a List containing all Symbols currently in the system.
	*/

	IoList *list = IoList_new(IOSTATE);
	CHASH_FOREACH(IOSTATE->symbols, i, v, IoList_rawAppend_(list, v));
	return list;
}
Beispiel #11
0
IoObject *IoCollector_allObjects(IoCollector *self, IoObject *locals, IoMessage *m)
{
	/*doc Collector allObjects
	Returns a List containing all objects known to the collector.
	*/

	IoList *results = IoList_new(IOSTATE);
	Collector *collector = IOSTATE->collector;

	COLLECTOR_FOREACH(collector, v, IoList_rawAppend_(results, (void *)v));
	return results;
}
Beispiel #12
0
IoObject *IoCairoSVGSurface_getVersions(IoCairoSVGSurface *self, IoObject *locals, IoMessage *m)
{
	IoList *versionList = IoList_new(IOSTATE);
	const cairo_svg_version_t *versions = 0;
	int versionCount = 0;
	int i = 0;

	cairo_svg_get_versions(&versions, &versionCount);
	for (i = 0; i < versionCount; i++)
		IoList_rawAppend_(versionList, IONUMBER(versions[i]));
	return versionList;
}
Beispiel #13
0
IoObject *IoCollector_dirtyObjects(IoCollector *self, IoObject *locals, IoMessage *m)
{
	/*doc Collector dirtyObjects
	Returns a List containing all dirty objects known to the collector.
	*/

	IoList *results = IoList_new(IOSTATE);
	Collector *collector = IOSTATE->collector;

	COLLECTOR_FOREACH(collector, v,
		if(IoObject_isDirty(v))
		{
			IoList_rawAppend_(results, (void *)v);
		}
	);
Beispiel #14
0
static int IoSQLite3_columnNamesResultRow(void *context, int argc, char **argv, char **azColName)
{
	IoSQLite3 *self = context;
	int i = 0;

	for (i= 0; i < argc; i ++)
	{
		if (!strcmp(azColName[i], "name"))
		{
			IoList_rawAppend_(DATA(self)->results, IOSYMBOL(argv[i]));
			break;
		}
	}
	return 0;
}
Beispiel #15
0
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;
}
Beispiel #16
0
static int IoSQLite3_singleItemResultRow(void *context, int argc, char **argv, char **azColName)
{
	IoSQLite3 *self = context;
	int i = 0;
	IoSymbol *value;

	if (argv[i])
	{
		value = IOSYMBOL(argv[i]);
	}
	else
	{
		value = IOSYMBOL((char *)"NULL");
	}

	IoList_rawAppend_(DATA(self)->results, value);
	return 0;
}
Beispiel #17
0
IO_METHOD(IoObject, tokensForString)
{
	/*doc Compiler tokensForString(aString)
	Returns a list of token objects lexed from the input string.
*/

	IoSymbol *text = IoMessage_locals_seqArgAt_(m, locals, 0);
	IoList *tokensList = IoList_new(IOSTATE);
	IoLexer *lexer = IoLexer_new();
	IoSymbol *name = IOSYMBOL("name");
	IoSymbol *line = IOSYMBOL("line");
	IoSymbol *character = IOSYMBOL("character");
	IoSymbol *type = IOSYMBOL("type");

	IoLexer_string_(lexer, CSTRING(text));
	IoLexer_lex(lexer);

	if (IoLexer_errorToken(lexer))
	{
		IoSymbol *errorString  = IOSYMBOL(IoLexer_errorDescription(lexer));
		IoLexer_free(lexer);
		IoState_error_(IOSTATE, NULL, "compile error: %s", CSTRING(errorString));
	}
	else
	{
		IoToken *t;

		while ((t = IoLexer_pop(lexer)))
		{
			IoObject *tokenObject = IoObject_new(IOSTATE);

			IoObject_setSlot_to_(tokenObject, name, IOSYMBOL(IoToken_name(t)));
			IoObject_setSlot_to_(tokenObject, line, IONUMBER(IoToken_lineNumber(t)));
			IoObject_setSlot_to_(tokenObject, character, IONUMBER(IoToken_charNumber(t)));
			IoObject_setSlot_to_(tokenObject, type, IOSYMBOL(IoToken_typeName(t)));

			IoList_rawAppend_(tokensList, tokenObject);
		}
	}

	IoLexer_free(lexer);

	return tokensList;
}
Beispiel #18
0
IoObject *IoTagDB_tagsAtKey(IoTagDB *self, IoObject *locals, IoMessage *m)
{
	/*doc TagDB tagsAtKey(key)
	Returns the tags for the specified key.
	*/
	
	TagDB *tdb = DATA(self);
	IoSeq *key = IoMessage_locals_seqArgAt_(m, locals, 0);
	symbolid_t keyid = TagDB_idForSymbol_size_(tdb, CSTRING(key), IoSeq_rawSize(key));
	IoList *tagNames = IoList_new(IOSTATE);
	Uint64Array *tags = TagDB_tagsAtKey_(tdb, keyid);
	int i;

	//printf("IoTagDB_tagsAt self = %p\n", (void *)self);

	if (!tags) 
	{
		//printf("IoTagDB_tagsAtKey: no tags found for key\n");
		return IONIL(self);
	}
	
	for (i = 0; i < Uint64Array_size(tags); i ++)
	{
		uint64_t tagid = Uint64Array_at_(tags, i);
		Datum *name = TagDB_symbolForId_(tdb, tagid);
		//printf("tagid %i = %i\n", i, (int)tagid);
		//printf("name '%s'\n", (char *)name->data);

		if (!name)
		{
			printf("IoTagDB_tagsAtKey: no datum returned for TagDB_symbolForId_\n");
		}
		else
		{
			IoList_rawAppend_(tagNames, IoSeq_newWithData_length_(IOSTATE, name->data, name->size));
			Datum_free(name);
		}
	}

	//Uint64Array_free(tags);

	return tagNames;
}
Beispiel #19
0
IoObject *IoAVCodec_decodeCodecNames(IoAVCodec *self, IoObject *locals, IoMessage *m)
{
	/*doc AVCodec decodeCodecNames
	Returns a list of strings with the names of the decode codecs.
	*/

	AVCodec *p = first_avcodec;
	IoList *names = IoList_new(IOSTATE);

	while (p)
	{
		if (p->decode)
		{
			IoList_rawAppend_(names, IOSYMBOL(p->name));
		}

		p = p->next;
	}

	return names;
}
Beispiel #20
0
IoObject *IoAVCodec_encodeCodecNames(IoAVCodec *self, IoObject *locals, IoMessage *m)
{
	/*doc AVCodec encodeCodecNames
	Returns a list of strings with the names of the encode codecs.
	*/

	AVCodec *p = av_codec_next(NULL);
	IoList *names = IoList_new(IOSTATE);

	while (p)
	{
		if (p->encode)
		{
			IoList_rawAppend_(names, IOSYMBOL(p->name));
		}

        p = av_codec_next(p);
	}

	return names;
}
Beispiel #21
0
Datei: geom.c Projekt: ADTSH/io
IoObject *IoODEGeom_collide(IoObject *self, IoObject *locals, IoMessage *m)
{
	dGeomID g1 = DATA(self)->geomId;
	dGeomID g2 = IoMessage_locals_odeGeomIdArgAt_(m, locals, 0);

	int max = IoMessage_argCount(m) > 1 ? IoMessage_locals_doubleArgAt_(m, locals, 1) : 1;
	dContactGeom* contacts = calloc(max, sizeof(*contacts));

	int count = dCollide(g1, g2, max, contacts, sizeof(*contacts));

	IoList *result = IoList_new(IOSTATE);
	int i;

	for(i=0; i < count; i++)
	{
		IoODEContact *contact = IoODEContact_newContactGeom(IOSTATE, &(contacts[i]));
		IoList_rawAppend_(result, contact);
	}

	free(contacts);
	return result;
}
Beispiel #22
0
Datei: IoFile.c Projekt: achoy/io
IO_METHOD(IoFile, readLines)
{
	/*doc File readLines
	Returns list containing all lines in the file.
	*/

	IoState *state = IOSTATE;

	if (!DATA(self)->stream)
	{
		IoFile_openForReading(self, locals, m);
	}

	IoFile_assertOpen(self, locals, m);

	{
		IoList *lines = IoList_new(state);
		IoObject *newLine;

		IoState_pushRetainPool(state);

		for (;;)
		{
			IoState_clearTopPool(state);
			newLine = IoFile_readLine(self, locals, m);

			if (ISNIL(newLine))
			{
				break;
			}

			IoList_rawAppend_(lines, newLine);
		}
		IoState_popRetainPool(state);

		return lines;
	}
}
Beispiel #23
0
IoObject* IoMySQL_query(IoObject* self, IoObject* locals, IoMessage* m)
{
    /*doc MySQL query(aQueryString)
    Perform a SQL query and return a list of results.
    <pre>
    db query("SELECT * FROM accounts") foreach(println)
    </pre>
    */

    IoObject * queryString = 0x0;
    bool useMap;

    MYSQL* conn = &DATA(self)->connection;
    MYSQL_RES* result;
    MYSQL_ROW row;
    MYSQL_FIELD* column;
    char** columnNames;
    unsigned c, colLength;
    unsigned long* colLengths;
    IoObject *list, *rowObject; //, *tmpObject;

    if(IoMessage_argCount(m) < 1 || !ISSEQ(queryString = IoMessage_locals_quickValueArgAt_(m, locals, 0)))
        IoState_error_(IOSTATE, m, "argument 0 to method 'query' must be a Sequence");

    useMap = IoMessage_argCount(m) > 1 && ISTRUE(IoMessage_locals_quickValueArgAt_(m, locals, 1));

    if(!DATA(self)->connected) //printf("not connected?\n");
        IoState_error_(IOSTATE, m, "not connected yet");

    if(mysql_real_query(conn, CSTRING(queryString), IOSEQ_LENGTH(queryString)))
        IoState_error_(IOSTATE, m, "query error(%d): %s", mysql_errno(&DATA(self)->connection), mysql_error(&DATA(self)->connection));

    if((result = mysql_store_result(conn)) && (colLength = mysql_num_fields(result))) {
        list = IoList_new(IOSTATE);

        if(useMap) {
            columnNames = (char**) malloc(colLength * sizeof(char*));
            for(c = 0; c < colLength && (column = mysql_fetch_field(result)); ++c)
                columnNames[c] = column->name;

            while((row = mysql_fetch_row(result)))
            {
                colLengths = mysql_fetch_lengths(result);
                rowObject = IoMap_new(IOSTATE);

                for(c = 0; c < colLength; ++c)
                    IoMap_rawAtPut(rowObject, IOSYMBOL(columnNames[c]), IOSEQ((unsigned char *)row[c], (size_t)colLengths[c]));

                IoList_rawAppend_(list, rowObject);
            }

            free(columnNames);
        }
        else
        {
            while((row = mysql_fetch_row(result))) {
                colLengths = mysql_fetch_lengths(result);
                rowObject = IoList_new(IOSTATE);

                for(c = 0; c < colLength; ++c)
                    IoList_rawAppend_(rowObject, IOSEQ((unsigned char *)row[c], (size_t)colLengths[c]));

                IoList_rawAppend_(list, rowObject);
            }
        }

        mysql_free_result(result);
        return list;
    }
    else
        return IONUMBER(mysql_affected_rows(conn));
}