예제 #1
0
static Eina_Bool
_eldbus_message_arguments_vappend(Eldbus_Message *msg, const char *signature, va_list *aq)
{
   DBusSignatureIter signature_iter;
   Eldbus_Message_Iter *iter;
   int type;
   Eina_Bool r = EINA_TRUE;

   if (!signature[0]) return EINA_TRUE;
   EINA_SAFETY_ON_FALSE_RETURN_VAL(dbus_signature_validate(signature, NULL),
                                   EINA_FALSE);

   iter = eldbus_message_iter_get(msg);
   EINA_SAFETY_ON_FALSE_RETURN_VAL(iter->writable, EINA_FALSE);

   dbus_signature_iter_init(&signature_iter, signature);
   while ((type = dbus_signature_iter_get_current_type(&signature_iter)))
     {
        if (dbus_type_is_basic(type))
          r = append_basic(type, aq, &iter->dbus_iterator);
        else
          {
             ERR("sig = %s | eldbus_message_arguments_append() and \
                  eldbus_message_arguments_vappend() only support basic types, \
                  to complex types use eldbus_message_iter_* functions",
                  signature);
             r = EINA_FALSE;
          }

        if (!r || !dbus_signature_iter_next(&signature_iter))
          break;
     }

   return r;
}
예제 #2
0
파일: script.c 프로젝트: Pardus-Linux/COMAR
//! Splits signature into atomic DBus object signatures
PyObject *
script_signature_each(const char *signature)
{
    PyObject *py_list = PyList_New(0);

    DBusError error;
    DBusSignatureIter iter;

    dbus_signature_iter_init(&iter, signature);
    while (dbus_signature_iter_get_current_type(&iter) != DBUS_TYPE_INVALID) {
        char *sign = dbus_signature_iter_get_signature(&iter);

        dbus_error_init(&error);
        dbus_signature_validate(sign, &error);
        if (dbus_error_is_set(&error)) {
            dbus_error_free(&error);
            return NULL;
        }
        else {
            PyList_Append(py_list, PyString_FromString(sign));
        }

        dbus_free(sign);
        dbus_signature_iter_next(&iter);
    }

    return py_list;
}
예제 #3
0
static PyObject *
Signature_tp_iter(PyObject *self)
{
    SignatureIter *iter = PyObject_New(SignatureIter, &SignatureIterType);
    PyObject *self_as_bytes;

    if (!iter) return NULL;

#ifdef PY3
    self_as_bytes = PyUnicode_AsUTF8String(self);
    if (!self_as_bytes) {
        Py_CLEAR(iter);
        return NULL;
    }
#else
    self_as_bytes = self;
    Py_INCREF(self_as_bytes);
#endif

    if (PyBytes_GET_SIZE(self_as_bytes) > 0) {
        iter->bytes = self_as_bytes;
        dbus_signature_iter_init(&(iter->iter),
                                 PyBytes_AS_STRING(self_as_bytes));
    }
    else {
        /* this is a null string, make a null iterator */
        iter->bytes = NULL;
        Py_CLEAR(self_as_bytes);
    }
    return (PyObject *)iter;
}
예제 #4
0
파일: add.c 프로젝트: dtaht/lem-dbus
EXPORT unsigned int
lem_dbus_add_arguments(lua_State *L, int start,
                       const char *signature, DBusMessage *msg)
{
	DBusMessageIter args;
	DBusSignatureIter type;
	int i = start;
	int end = lua_gettop(L);

	dbus_message_iter_init_append(msg, &args);
	dbus_signature_iter_init(&type, signature);

	do {
		if (i > end) {
			lua_pushfstring(L, "type error adding value #%d "
					"of '%s' (too few arguments)",
					i - start + 1, signature);
			return -1;
		}

		if ((get_addfunc(&type))(L, i, &type, &args)) {
			lua_pushfstring(L, "type error adding value #%d of '%s' ",
					i - start + 1, signature);
			lua_insert(L, -2);
			lua_concat(L, 2);
			return -1;
		}

		i++;
	} while (dbus_signature_iter_next(&type));

	return 0;
}
예제 #5
0
GType
_dbus_gtype_from_signature (const char *signature, gboolean is_client)
{
  DBusSignatureIter iter;

  dbus_signature_iter_init (&iter, signature);

  return _dbus_gtype_from_signature_iter (&iter, is_client);
}
예제 #6
0
static DBusMessage *
build_reply_from_jsval(SeedContext ctx,
                       const char    *signature,
                       const char    *sender,
                       dbus_uint32_t  serial,
		       SeedValue rval,
		       SeedException *exception)
{
    DBusMessage *reply;
    DBusMessageIter arg_iter;
    DBusSignatureIter sig_iter;
    gboolean marshalled = FALSE;

    reply = dbus_message_new(DBUS_MESSAGE_TYPE_METHOD_RETURN);
    dbus_message_set_destination(reply, sender);
    dbus_message_set_reply_serial(reply, serial);
    dbus_message_set_no_reply(reply, TRUE);

    dbus_message_iter_init_append(reply, &arg_iter);

    if (seed_value_is_undefined (ctx, rval) || g_str_equal(signature, ""))
      {
        /* We don't want to send anything in these cases so skip the
         * marshalling altogether.
         */
        return reply;
      }

    dbus_signature_iter_init(&sig_iter, signature);

    if (signature_has_one_element(signature))
      {
	marshalled = seed_js_one_value_to_dbus(ctx, rval, &arg_iter, &sig_iter, exception);
      }
    else
      {
        if (!seed_value_is_object (ctx, rval))
	  {
	    g_warning("Signature has multiple items but return value is not an array");
	    return reply;
	  }
        marshalled = seed_js_values_to_dbus(ctx, 0, rval, &arg_iter, &sig_iter, exception);
      }

    if (!marshalled) {
        /* replace our planned reply with an error */
        dbus_message_unref(reply);
        if (!dbus_reply_from_exception_and_sender(ctx, sender, serial, &reply, exception))
	  g_warning ("conversion of dbus return value failed but no exception was set?");
    }

    return reply;
}
예제 #7
0
static gboolean
signature_has_one_element(const char *signature)
{
    DBusSignatureIter iter;

    if (!signature)
        return FALSE;

    dbus_signature_iter_init(&iter, signature);

    return !dbus_signature_iter_next(&iter);
}
예제 #8
0
static Eina_Bool
_eldbus_message_iter_arguments_vget(Eldbus_Message_Iter *iter, const char *signature, va_list *aq)
{
   int iter_type;
   DBusSignatureIter sig_iter;

   ELDBUS_MESSAGE_ITERATOR_CHECK_RETVAL(iter, EINA_FALSE);
   EINA_SAFETY_ON_TRUE_RETURN_VAL(iter->writable, EINA_FALSE);
   EINA_SAFETY_ON_NULL_RETURN_VAL(signature, EINA_FALSE);
   EINA_SAFETY_ON_FALSE_RETURN_VAL(dbus_signature_validate(signature, NULL), EINA_FALSE);

   dbus_signature_iter_init(&sig_iter, signature);
   iter_type = dbus_message_iter_get_arg_type(&iter->dbus_iterator);

   while (iter_type != DBUS_TYPE_INVALID)
     {
        int sig_type = dbus_signature_iter_get_current_type(&sig_iter);

        if (sig_type == DBUS_TYPE_INVALID)
          break;

        if (sig_type != iter_type)
          {
             ERR("Type in iterator different of signature expected:%c got %c", iter_type, sig_type);
             return EINA_FALSE;
          }

        if (dbus_type_is_basic(iter_type))
          get_basic(iter_type, &iter->dbus_iterator, aq);
        else
          {
             Eldbus_Message_Iter **user_itr = va_arg(*aq, Eldbus_Message_Iter **);
             Eldbus_Message_Iter *sub_itr;

             sub_itr = _message_iterator_new(EINA_FALSE);
             EINA_SAFETY_ON_NULL_RETURN_VAL(sub_itr, EINA_FALSE);
             dbus_message_iter_recurse(&iter->dbus_iterator,
                                       &sub_itr->dbus_iterator);
             iter->iterators = eina_inlist_append(iter->iterators,
                                                  EINA_INLIST_GET(sub_itr));
             *user_itr = sub_itr;
          }

        dbus_message_iter_next(&iter->dbus_iterator);
        dbus_signature_iter_next(&sig_iter);
        iter_type = dbus_message_iter_get_arg_type(&iter->dbus_iterator);
     }

   return dbus_signature_iter_get_current_type(&sig_iter) == DBUS_TYPE_INVALID;

}
예제 #9
0
/**
 * Check that a type signature is both valid and contains exactly one
 * complete type. "One complete type" means a single basic type,
 * array, struct, or dictionary, though the struct or array may be
 * arbitrarily recursive and complex. More than one complete type
 * would mean for example "ii" or two integers in sequence.
 *
 * @param signature a potentially invalid type signature
 * @param error error return
 * @returns #TRUE if signature is valid and has exactly one complete type
 */
dbus_bool_t
dbus_signature_validate_single (const char       *signature,
				DBusError        *error)
{
  DBusSignatureIter iter;

  if (!dbus_signature_validate (signature, error))
    return FALSE;

  dbus_signature_iter_init (&iter, signature);
  if (dbus_signature_iter_get_current_type (&iter) == DBUS_TYPE_INVALID)
    goto lose;
  if (!dbus_signature_iter_next (&iter))
    return TRUE;
 lose:
  dbus_set_error (error, DBUS_ERROR_INVALID_SIGNATURE, "Exactly one complete type required in signature");
  return FALSE;
}
예제 #10
0
GArray *
_dbus_gtypes_from_arg_signature (const char *argsig, gboolean is_client)
{
  GArray *ret;
  int current_type;
  DBusSignatureIter sigiter;

  ret = g_array_new (FALSE, FALSE, sizeof (GType));

  dbus_signature_iter_init (&sigiter, argsig);
  while ((current_type = dbus_signature_iter_get_current_type (&sigiter)) != DBUS_TYPE_INVALID)
    {
      GType curtype;

      curtype = _dbus_gtype_from_signature_iter (&sigiter, is_client);
      g_array_append_val (ret, curtype);
      dbus_signature_iter_next (&sigiter);
    }
  return ret;
}
예제 #11
0
int bridge_request_dbus_params_array(bridge_request_t *self,
				     struct json_object *params,
				     int idx, const char *sig,
				     DBusMessageIter *it)
{
	DBusSignatureIter sigIt;
	struct json_object *element;
	int i, ret, len;

	if (!dbus_signature_validate(sig, 0)) {
		bridge_request_error(self,
			"invalid argument signature.");
		return EINVAL;
	}
	dbus_signature_iter_init(&sigIt, sig);

	len = json_object_array_length(params);

	for (i = idx; i < len; ++i) {
		element = json_object_array_get_idx(params, i);
		if (!element) {
			bridge_request_error(self,
				"Unexpected 'null' parameter found.");
			return EINVAL;
		}
		ret = bridge_request_dbus_params_element(self,
			element, &sigIt, it);
		if (ret != 0)
			return ret;
		if (!dbus_signature_iter_next(&sigIt)) {
			if (i+1 == len)
				return 0;
			bridge_request_error(self,
				"Unexpected extra parameter found.");
			return EINVAL;
		}
	}
	bridge_request_error(self, "Aditional parameter expexted.");
	return EINVAL;
}
예제 #12
0
static Eina_Bool
_eldbus_message_iter_arguments_vappend(Eldbus_Message_Iter *iter, const char *signature, va_list *aq)
{
   DBusSignatureIter signature_iter;
   Eina_Bool r = EINA_TRUE;
   char *type;

   ELDBUS_MESSAGE_ITERATOR_CHECK_RETVAL(iter, EINA_FALSE);
   EINA_SAFETY_ON_FALSE_RETURN_VAL(iter->writable, EINA_FALSE);
   EINA_SAFETY_ON_NULL_RETURN_VAL(signature, EINA_FALSE);

   dbus_signature_iter_init(&signature_iter, signature);
   while ((type = dbus_signature_iter_get_signature(&signature_iter)))
     {
        if (type[0] != DBUS_TYPE_VARIANT && !type[1])
          r = append_basic(type[0], aq, &iter->dbus_iterator);
        else
          {
             Eldbus_Message_Iter **user_itr;
             Eldbus_Message_Iter *sub;

             user_itr = va_arg(*aq, Eldbus_Message_Iter **);
             sub = _message_iterator_new(EINA_TRUE);
             if (!sub)
               {
                  ERR("Could not create sub iterator");
                  r = EINA_FALSE;
                  goto next;
               }

             iter->iterators = eina_inlist_append(iter->iterators,
                                                  EINA_INLIST_GET(sub));

             if (type[0] == DBUS_TYPE_ARRAY)
               r = dbus_message_iter_open_container(&iter->dbus_iterator,
                                                    type[0], type+1,
                                                    &sub->dbus_iterator);
             else if (type[1] == DBUS_TYPE_VARIANT)
               {
                  ERR("variant not supported by \
                      eldbus_message_iter_arguments_append(), \
                      try eldbus_message_iter_container_new()");
                  r = EINA_FALSE;
                  goto next;
               }
             else
               {
                  char real_type;

                  if (type[0] == DBUS_STRUCT_BEGIN_CHAR)
                    real_type = DBUS_TYPE_STRUCT;
                  else real_type = DBUS_TYPE_DICT_ENTRY;
                  r = dbus_message_iter_open_container(&iter->dbus_iterator,
                                                       real_type, NULL,
                                                       &sub->dbus_iterator);
               }
             *user_itr = sub;
          }

next:
        dbus_free(type);
        if (!r || !dbus_signature_iter_next(&signature_iter))
          break;
     }

   return r;

}
예제 #13
0
/**
 * @ingroup DBusSignatureInternals
 * Unit test for DBusSignature.
 *
 * @returns #TRUE on success.
 */
dbus_bool_t
_dbus_signature_test (void)
{
  DBusSignatureIter iter;
  DBusSignatureIter subiter;
  DBusSignatureIter subsubiter;
  DBusSignatureIter subsubsubiter;
  const char *sig;
  dbus_bool_t boolres;

  _dbus_assert (sizeof (DBusSignatureIter) >= sizeof (DBusSignatureRealIter));

  sig = "";
  _dbus_assert (dbus_signature_validate (sig, NULL));
  _dbus_assert (!dbus_signature_validate_single (sig, NULL));
  dbus_signature_iter_init (&iter, sig);
  _dbus_assert (dbus_signature_iter_get_current_type (&iter) == DBUS_TYPE_INVALID);

  sig = DBUS_TYPE_STRING_AS_STRING;
  _dbus_assert (dbus_signature_validate (sig, NULL));
  _dbus_assert (dbus_signature_validate_single (sig, NULL));
  dbus_signature_iter_init (&iter, sig);
  _dbus_assert (dbus_signature_iter_get_current_type (&iter) == DBUS_TYPE_STRING);

  sig = DBUS_TYPE_STRING_AS_STRING DBUS_TYPE_BYTE_AS_STRING;
  _dbus_assert (dbus_signature_validate (sig, NULL));
  dbus_signature_iter_init (&iter, sig);
  _dbus_assert (dbus_signature_iter_get_current_type (&iter) == DBUS_TYPE_STRING);
  boolres = dbus_signature_iter_next (&iter);
  _dbus_assert (boolres);
  _dbus_assert (dbus_signature_iter_get_current_type (&iter) == DBUS_TYPE_BYTE);

  sig = DBUS_TYPE_UINT16_AS_STRING
    DBUS_STRUCT_BEGIN_CHAR_AS_STRING
    DBUS_TYPE_STRING_AS_STRING
    DBUS_TYPE_UINT32_AS_STRING
    DBUS_TYPE_VARIANT_AS_STRING
    DBUS_TYPE_DOUBLE_AS_STRING
    DBUS_STRUCT_END_CHAR_AS_STRING;
  _dbus_assert (dbus_signature_validate (sig, NULL));
  dbus_signature_iter_init (&iter, sig);
  _dbus_assert (dbus_signature_iter_get_current_type (&iter) == DBUS_TYPE_UINT16);
  boolres = dbus_signature_iter_next (&iter);
  _dbus_assert (boolres);
  _dbus_assert (dbus_signature_iter_get_current_type (&iter) == DBUS_TYPE_STRUCT);
  dbus_signature_iter_recurse (&iter, &subiter);
  _dbus_assert (dbus_signature_iter_get_current_type (&subiter) == DBUS_TYPE_STRING);
  boolres = dbus_signature_iter_next (&subiter);
  _dbus_assert (boolres);
  _dbus_assert (dbus_signature_iter_get_current_type (&subiter) == DBUS_TYPE_UINT32);
  boolres = dbus_signature_iter_next (&subiter);
  _dbus_assert (boolres);
  _dbus_assert (dbus_signature_iter_get_current_type (&subiter) == DBUS_TYPE_VARIANT);
  boolres = dbus_signature_iter_next (&subiter);
  _dbus_assert (boolres);
  _dbus_assert (dbus_signature_iter_get_current_type (&subiter) == DBUS_TYPE_DOUBLE);

  sig = DBUS_TYPE_UINT16_AS_STRING
    DBUS_STRUCT_BEGIN_CHAR_AS_STRING
    DBUS_TYPE_UINT32_AS_STRING
    DBUS_TYPE_BYTE_AS_STRING
    DBUS_TYPE_ARRAY_AS_STRING
    DBUS_TYPE_ARRAY_AS_STRING
    DBUS_TYPE_DOUBLE_AS_STRING
    DBUS_STRUCT_BEGIN_CHAR_AS_STRING
    DBUS_TYPE_BYTE_AS_STRING
    DBUS_STRUCT_END_CHAR_AS_STRING
    DBUS_STRUCT_END_CHAR_AS_STRING;
  _dbus_assert (dbus_signature_validate (sig, NULL));
  dbus_signature_iter_init (&iter, sig);
  _dbus_assert (dbus_signature_iter_get_current_type (&iter) == DBUS_TYPE_UINT16);
  boolres = dbus_signature_iter_next (&iter);
  _dbus_assert (boolres);
  _dbus_assert (dbus_signature_iter_get_current_type (&iter) == DBUS_TYPE_STRUCT);
  dbus_signature_iter_recurse (&iter, &subiter);
  _dbus_assert (dbus_signature_iter_get_current_type (&subiter) == DBUS_TYPE_UINT32);
  boolres = dbus_signature_iter_next (&subiter);
  _dbus_assert (boolres);
  _dbus_assert (dbus_signature_iter_get_current_type (&subiter) == DBUS_TYPE_BYTE);
  boolres = dbus_signature_iter_next (&subiter);
  _dbus_assert (boolres);
  _dbus_assert (dbus_signature_iter_get_current_type (&subiter) == DBUS_TYPE_ARRAY);
  _dbus_assert (dbus_signature_iter_get_element_type (&subiter) == DBUS_TYPE_ARRAY);

  dbus_signature_iter_recurse (&subiter, &subsubiter);
  _dbus_assert (dbus_signature_iter_get_current_type (&subsubiter) == DBUS_TYPE_ARRAY);
  _dbus_assert (dbus_signature_iter_get_element_type (&subsubiter) == DBUS_TYPE_DOUBLE);

  dbus_signature_iter_recurse (&subsubiter, &subsubsubiter);
  _dbus_assert (dbus_signature_iter_get_current_type (&subsubsubiter) == DBUS_TYPE_DOUBLE);
  boolres = dbus_signature_iter_next (&subiter);
  _dbus_assert (boolres);
  _dbus_assert (dbus_signature_iter_get_current_type (&subiter) == DBUS_TYPE_STRUCT);
  dbus_signature_iter_recurse (&subiter, &subsubiter);
  _dbus_assert (dbus_signature_iter_get_current_type (&subsubiter) == DBUS_TYPE_BYTE);

  sig = DBUS_TYPE_ARRAY_AS_STRING
    DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING
    DBUS_TYPE_INT16_AS_STRING
    DBUS_TYPE_STRING_AS_STRING
    DBUS_DICT_ENTRY_END_CHAR_AS_STRING
    DBUS_TYPE_VARIANT_AS_STRING;
  _dbus_assert (dbus_signature_validate (sig, NULL));
  _dbus_assert (!dbus_signature_validate_single (sig, NULL));
  dbus_signature_iter_init (&iter, sig);
  _dbus_assert (dbus_signature_iter_get_current_type (&iter) == DBUS_TYPE_ARRAY);
  _dbus_assert (dbus_signature_iter_get_element_type (&iter) == DBUS_TYPE_DICT_ENTRY);

  dbus_signature_iter_recurse (&iter, &subiter);
  dbus_signature_iter_recurse (&subiter, &subsubiter);
  _dbus_assert (dbus_signature_iter_get_current_type (&subsubiter) == DBUS_TYPE_INT16);
  boolres = dbus_signature_iter_next (&subsubiter);
  _dbus_assert (boolres);
  _dbus_assert (dbus_signature_iter_get_current_type (&subsubiter) == DBUS_TYPE_STRING);
  boolres = dbus_signature_iter_next (&subsubiter);
  _dbus_assert (!boolres);

  boolres = dbus_signature_iter_next (&iter);
  _dbus_assert (boolres);
  _dbus_assert (dbus_signature_iter_get_current_type (&iter) == DBUS_TYPE_VARIANT);
  boolres = dbus_signature_iter_next (&iter);
  _dbus_assert (!boolres);

  sig = DBUS_TYPE_DICT_ENTRY_AS_STRING;
  _dbus_assert (!dbus_signature_validate (sig, NULL));

  sig = DBUS_TYPE_ARRAY_AS_STRING;
  _dbus_assert (!dbus_signature_validate (sig, NULL));

  sig = DBUS_TYPE_UINT32_AS_STRING
    DBUS_TYPE_ARRAY_AS_STRING;
  _dbus_assert (!dbus_signature_validate (sig, NULL));

  sig = DBUS_TYPE_ARRAY_AS_STRING
    DBUS_TYPE_DICT_ENTRY_AS_STRING;
  _dbus_assert (!dbus_signature_validate (sig, NULL));

  sig = DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING;
  _dbus_assert (!dbus_signature_validate (sig, NULL));

  sig = DBUS_DICT_ENTRY_END_CHAR_AS_STRING;
  _dbus_assert (!dbus_signature_validate (sig, NULL));

  sig = DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING
    DBUS_TYPE_INT32_AS_STRING;
  _dbus_assert (!dbus_signature_validate (sig, NULL));

  sig = DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING
    DBUS_TYPE_INT32_AS_STRING
    DBUS_TYPE_STRING_AS_STRING;
  _dbus_assert (!dbus_signature_validate (sig, NULL));

  sig = DBUS_STRUCT_END_CHAR_AS_STRING
    DBUS_STRUCT_BEGIN_CHAR_AS_STRING;
  _dbus_assert (!dbus_signature_validate (sig, NULL));

  sig = DBUS_STRUCT_BEGIN_CHAR_AS_STRING
    DBUS_TYPE_BOOLEAN_AS_STRING;
  _dbus_assert (!dbus_signature_validate (sig, NULL));
  return TRUE;
#if 0
 oom:
  _dbus_assert_not_reached ("out of memory");
  return FALSE;
#endif
}
예제 #14
0
gboolean js_to_dbus(JSContextRef ctx, const JSValueRef jsvalue,
    DBusMessageIter *iter, const char* sig, JSValueRef* exception)
{
    DBusSignatureIter s_iter;
    dbus_signature_iter_init(&s_iter, sig);

    int type;
    switch (type = dbus_signature_iter_get_current_type(&s_iter)) {
        case DBUS_TYPE_BOOLEAN:
            {
                dbus_bool_t value = JSValueToBoolean(ctx, jsvalue);
                if (!dbus_message_iter_append_basic(iter, type, (void*)&value)) {
                    g_warning("signatuer:%c error!", type);
                    return FALSE;
                }  else {
                    return TRUE;
                }
            }
        case DBUS_TYPE_DOUBLE:
            CASE_NUMBER
            {
                if (!JSValueIsNumber(ctx, jsvalue)) {
                    js_fill_exception(ctx, exception, "jsvalue is not an number!");
                    return FALSE;
                }
                double value = JSValueToNumber(ctx, jsvalue, NULL);
                if (!dbus_message_iter_append_basic(iter, type, (void*)&value)) {
                    g_warning("signatuer:%c error!", type);
                    return FALSE;
                } else {
                    return TRUE;
                }
            }
            CASE_STRING
            {
                char* value = jsvalue_to_cstr(ctx, jsvalue);
                if (value == NULL ||
                        !dbus_message_iter_append_basic(iter, type, (void*)&value)) {
                    g_free(value);
                    js_fill_exception(ctx, exception, "jsvalue is not an string or memory not enough!");
                    return FALSE;
                } else {
                    g_free(value);
                    return TRUE;
                }
            }

        case DBUS_TYPE_STRUCT:
            {
                if (!jsvalue_instanceof(ctx, jsvalue, "Array")) {
                    js_fill_exception(ctx, exception, "jsvalue should an array");
                    return FALSE;
                }

                JSPropertyNameArrayRef prop_names =
                    JSObjectCopyPropertyNames(ctx, (JSObjectRef)jsvalue);
                int p_num = JSPropertyNameArrayGetCount(prop_names);
                if (p_num == 0) {
                    JSPropertyNameArrayRelease(prop_names);
                    js_fill_exception(ctx, exception, "Struct at least have one element!");
                    return FALSE;
                }

                DBusMessageIter sub_iter;
                OPEN_CONTAINER(iter, type, NULL, &sub_iter);

                DBusSignatureIter sub_s_iter;
                dbus_signature_iter_recurse(&s_iter, &sub_s_iter);

                for (int i=0; i<p_num; i++) {
                    JSValueRef value = JSObjectGetProperty(ctx,
                            (JSObjectRef)jsvalue,
                            JSPropertyNameArrayGetNameAtIndex(prop_names, i),
                            NULL);

                    char *sig = dbus_signature_iter_get_signature(&sub_s_iter);
                    if (!js_to_dbus(ctx, value, &sub_iter, sig, exception)) {
                        js_fill_exception(ctx, exception, "Failed append struct with sig:%sTODO");
                        dbus_free(sig);
                        return FALSE;
                    }
                    dbus_free(sig);

                    if (i != p_num-1 && !dbus_signature_iter_next(&sub_s_iter)) {
                        JSPropertyNameArrayRelease(prop_names);
                        CLOSE_CONTAINER(iter, &sub_iter);
                        js_fill_exception(ctx, exception, "to many params filled to struct");
                        return FALSE;
                    }
                }

                if (dbus_signature_iter_next(&sub_s_iter)) {
                    JSPropertyNameArrayRelease(prop_names);
                    CLOSE_CONTAINER(iter, &sub_iter);
                    js_fill_exception(ctx, exception, "need more params by this struct");
                    return FALSE;
                }
                JSPropertyNameArrayRelease(prop_names);
                CLOSE_CONTAINER(iter, &sub_iter);
                return TRUE;
            }
        case DBUS_TYPE_ARRAY:
            if (dbus_signature_iter_get_element_type(&s_iter) ==
                    DBUS_TYPE_DICT_ENTRY) {

                DBusSignatureIter dict_s_iter;
                dbus_signature_iter_recurse(&s_iter, &dict_s_iter);
                char *d_sig = dbus_signature_iter_get_signature(&dict_s_iter);

                DBusMessageIter sub_iter;
                OPEN_CONTAINER(iter, type, d_sig, &sub_iter);
                dbus_free(d_sig);

                JSPropertyNameArrayRef prop_names = JSObjectCopyPropertyNames(ctx,
                        (JSObjectRef)jsvalue);
                int p_num = JSPropertyNameArrayGetCount(prop_names);

                DBusSignatureIter dict_sub_s_iter;
                dbus_signature_iter_recurse(&dict_s_iter, &dict_sub_s_iter);

                int key_type = dbus_signature_iter_get_current_type(&dict_sub_s_iter);
                dbus_signature_iter_next(&dict_sub_s_iter);
                char *val_sig = dbus_signature_iter_get_signature(&dict_sub_s_iter);


                for (int i=0; i<p_num; i++) {
                    DBusMessageIter dict_iter;
                    OPEN_CONTAINER(&sub_iter, DBUS_TYPE_DICT_ENTRY,
                            NULL, &dict_iter);

                    JSStringRef key_str = JSPropertyNameArrayGetNameAtIndex(prop_names, i);

                    //TODO: fetch key type
                    switch (key_type) {
                        CASE_STRING
                        {
                            char *value = jsstring_to_cstr(ctx, key_str);
                            dbus_message_iter_append_basic(&dict_iter, key_type, (void*)&value);
                            g_free(value);
                            break;
                        }
                        case DBUS_TYPE_DOUBLE:
                        CASE_NUMBER
                        {
                            //TODO detect illegal number format
                            JSValueRef excp;
                            double value = JSValueToNumber(ctx,
                                    JSValueMakeString(ctx, key_str), &excp);

                            if (excp != NULL) {
                                js_fill_exception(ctx, exception, "dict_entry's key must be an number to match the signature!");
                                return FALSE;
                            }

                            dbus_message_iter_append_basic(&dict_iter, key_type,
                                    (void*)&value);
                            break;
                        }
                        default:
                        {
                            js_fill_exception(ctx, exception, "DICT_ENTRY's key must basic type, and you should not see this warning in javascript runtime");
                            dbus_free(val_sig);
                            JSPropertyNameArrayRelease(prop_names);
                            CLOSE_CONTAINER(iter, &sub_iter);
                            return FALSE;
                        }
                    }



                    js_to_dbus(ctx,
                            JSObjectGetProperty(ctx, (JSObjectRef)jsvalue,
                                key_str, NULL),
                            &dict_iter, val_sig,
                            exception);

                    CLOSE_CONTAINER(&sub_iter, &dict_iter);
                }
                dbus_free(val_sig);
                JSPropertyNameArrayRelease(prop_names);

                CLOSE_CONTAINER(iter, &sub_iter);
                return TRUE;
            } else {
Eina_Bool
_message_iter_from_eina_value_struct(const char *signature, Eldbus_Message_Iter *iter, const Eina_Value *value)
{
   unsigned i;
   DBusSignatureIter signature_iter;
   Eina_Bool r = EINA_TRUE;
   char *type;
   Eina_Value_Struct st;

   EINA_SAFETY_ON_FALSE_RETURN_VAL(
            eina_value_type_get(value) == EINA_VALUE_TYPE_STRUCT, EINA_FALSE);
   EINA_SAFETY_ON_FALSE_RETURN_VAL(
      eina_value_pget(value, &st), EINA_FALSE);

   dbus_signature_iter_init(&signature_iter, signature);
   i = 0;
   while ((type = dbus_signature_iter_get_signature(&signature_iter)))
     {
        DBG("type: %s", type);
        if (type[0] != 'v' && !type[1])
          r = _basic_append(type[0], value, st.desc, i, iter);
        else if (type[0] == 'a')
          {
             Eina_Value value_array;

             EINA_SAFETY_ON_FALSE_RETURN_VAL(
                      _compatible_type(type[0], st.desc->members[i].type),
                      EINA_FALSE);
             eina_value_struct_value_get(value, st.desc->members[i].name,
                                         &value_array);
             r = _array_append(type, &value_array, iter);
             eina_value_flush(&value_array);
          }
        else if (type[0] == '(')
          {
             Eina_Value inner_st;
             Eldbus_Message_Iter *sub_iter;
             char *sub_sig;
             unsigned len = strlen(type+1) -1;
             sub_sig = alloca(sizeof(char) * len);
             memcpy(sub_sig, type+1, len);
             sub_sig[len-1] = 0;
             EINA_SAFETY_ON_FALSE_RETURN_VAL(
                         _compatible_type(type[0], st.desc->members[i].type),
                         EINA_FALSE);
             eina_value_struct_value_get(value, st.desc->members[i].name, &inner_st);
             eldbus_message_iter_arguments_append(iter, type, &sub_iter);
             r = _message_iter_from_eina_value_struct(sub_sig, sub_iter,
                                                      &inner_st);
             eldbus_message_iter_container_close(iter, sub_iter);
          }
        else if (type[0] == 'v')
          {
             ERR("Variant not supported");
             r = EINA_FALSE;
          }
        else
          {
             ERR("Unknown type %c", type[0]);
             r = EINA_FALSE;
          }
        i++;
        dbus_free(type);
        if (!r || !dbus_signature_iter_next(&signature_iter)) break;
     }
   return r;
}