コード例 #1
0
ファイル: IoLoudmouth.c プロジェクト: ADTSH/io
//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);
}
コード例 #2
0
/* 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;
}
コード例 #3
0
ファイル: IoClutterActor.c プロジェクト: Akiyah/io
IO_METHOD(IoClutterActor, setName) {
  clutter_actor_set_name(
    IOCACTOR(self),
    IoMessage_locals_cStringArgAt_(m, locals, 0)
  );
  return self;
}
コード例 #4
0
ファイル: IoSandbox.c プロジェクト: Habaut/GameBindings
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);
}
コード例 #5
0
ファイル: IoLoudmouth.c プロジェクト: ADTSH/io
//doc Loudmouth sendRaw(body) Sends raw text over XMPP stream. Returns <code>true</code> if no errors occur.
IoObject *IoLoudmouth_sendRaw(IoLoudmouth *self, IoObject *locals, IoMessage *m) {
  char *seq = IoMessage_locals_cStringArgAt_(m, locals, 0);
  int success = lm_connection_send_raw(LMCONN(self), seq, NULL);
  free(seq);

  return IOBOOL(self, success);
}
コード例 #6
0
ファイル: IoLoudmouth.c プロジェクト: ADTSH/io
//doc Loudmouth send(toJid, message) Sends a message (<code>Sequence</code>) to provided JID (<code>Sequence</code>). Returns <code>true</code> or <code>false</code>.
IoObject *IoLoudmouth_send(IoLoudmouth *self, IoObject *locals, IoMessage *m) {
  char *to        = IoMessage_locals_cStringArgAt_(m, locals, 0);
  char *msg_body  = IoMessage_locals_cStringArgAt_(m, locals, 1);
  int success     = 0;

  LmMessage *xmpp_msg = lm_message_new_with_sub_type(
    to, LM_MESSAGE_TYPE_MESSAGE, LM_MESSAGE_SUB_TYPE_CHAT
  );

  lm_message_node_add_child(xmpp_msg->node, "body", msg_body);
  success = lm_connection_send(LMCONN(self), xmpp_msg, NULL);
  lm_message_unref(xmpp_msg);
  free(to);
  free(msg_body);

  return IOBOOL(self, success);
}
コード例 #7
0
ファイル: IoClutterUnits.c プロジェクト: ADTSH/io
//doc ClutterUnits withString(string)
IO_METHOD(IoClutterUnits, withString) {
  ClutterUnits units;
  clutter_units_from_string(
    &units,
    IoMessage_locals_cStringArgAt_(m, locals, 0)
  );

  return IoClutterUnits_newWithUnits(IOSTATE, units);
}
コード例 #8
0
ファイル: IoClutterUnits.c プロジェクト: ADTSH/io
//doc ClutterUnits withEmForFont(valueInEm, fontName)
IO_METHOD(IoClutterUnits, withEmForFont) {
  ClutterUnits units;
  clutter_units_from_em_for_font(
    &units,
    IoMessage_locals_cStringArgAt_(m, locals, 0),
    IoMessage_locals_floatArgAt_(m, locals, 1)
  );

  return IoClutterUnits_newWithUnits(IOSTATE, units);
}
コード例 #9
0
ファイル: IoMemcached.c プロジェクト: ADTSH/io
/*doc Memcached addServer(address)
Adds a memcached server. address is a "host:port" string, e.g., "127.0.0.1:11211"
Returns self.
*/
IoObject *IoMemcached_addServer(IoMemcached *self, IoObject *locals, IoMessage *m)
{
	memcached_server_list_st server;

	server = memcached_servers_parse(IoMessage_locals_cStringArgAt_(m, locals, 0));
	memcached_server_push(DATA(self)->mc, server);

	memcached_server_list_free(server);

	return self;
}
コード例 #10
0
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;
}
コード例 #11
0
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;
}
コード例 #12
0
ファイル: IoCompiler.c プロジェクト: doublec/io
IO_METHOD(IoObject, messageForString2)
{
  /*doc Compiler messageForString2(aString)
	Returns the compiled message object for aString. (Runs raw string against lexer directly.)
	*/
	IoLexer *lexer = IoLexer_new();
	char *text = IoMessage_locals_cStringArgAt_(m, locals, 0);
	IoMessage *msg;

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

	msg = IoMessage_newParse(IOSTATE, lexer);

	IoLexer_free(lexer);
	return msg;
}
コード例 #13
0
ファイル: IoLoudmouth.c プロジェクト: ADTSH/io
IoObject *IoLoudmouth_setPresence(IoLoudmouth *self, IoObject *locals, IoMessage *m) {
  char *pres_c  = IoMessage_locals_cStringArgAt_(m, locals, 0);
  IoSeq *status = IoMessage_locals_valueArgAt_(m, locals, 1);
  int success   = 0;
  LmMessage *xmpp_msg = lm_message_new_with_sub_type(
    NULL,
    LM_MESSAGE_TYPE_PRESENCE,
    str2msg_subtype(pres_c)
  );

  if(ISSEQ(status))
    lm_message_node_add_child(xmpp_msg->node, "status", CSTRING(status));

  success = lm_connection_send(LMCONN(self), xmpp_msg, NULL);
  lm_message_unref(xmpp_msg);
  free(pres_c);

  return IOBOOL(self, success);
}
コード例 #14
0
ファイル: IoClutterStage.c プロジェクト: Akiyah/io
IO_METHOD(IoClutterStage, setTitle) {
  char *title = IoMessage_locals_cStringArgAt_(m, locals, 0);
  clutter_stage_set_title(IOCSTAGE(self), title);
  return self;
}