src/modules/systemd/dbus.c
/*
 * dbus_marshall_property gets the value of a d-bus property and marshalls it
 * into a Zabbix AGENT_RESULT struct.
 *
 * Returns SYSINFO_RET_FAIL on error.
 */
dbus_marshall_property gets the value of a d-bus property and marshalls it
into a Zabbix AGENT_RESULT struct.

Returns SYSINFO_RET_FAIL on error.
dbus_marshall_property gets the value of a d - bus property and marshalls it into a Zabbix AGENT_RESULT struct . Returns SYSINFO_RET_FAIL on error .
int dbus_marshall_property(
  AGENT_RESULT  *result,
  const char    *service,
  const char    *path,
  const char    *interface,
  const char    *property
) {
  int             type = 0;
  DBusMessageIter *iter = NULL, arr;
  DBusBasicValue  value;
  char            *s = NULL;
  StringBuilder   *sb = NULL;
  iter = dbus_get_property(
                      service,
                      path,
                      interface,
                      property);
  if (NULL == iter) {
    SET_MSG_RESULT(result, strdup("failed to get property"));
    zbx_free(iter);
    return SYSINFO_RET_FAIL;
  }
  type = dbus_message_iter_get_arg_type(iter);
  if (DBUS_TYPE_ARRAY == type) {
    dbus_message_iter_recurse(iter, &arr);
    sb = sb_create();
    while (DBUS_TYPE_INVALID != (type = dbus_message_iter_get_arg_type(&arr))) {
      if (DBUS_TYPE_STRING == type) {
        if (!sb_empty(sb))
          sb_append(sb, ",");
        dbus_message_iter_get_basic(&arr, &s);
        sb_append(sb, s);
      }
      dbus_message_iter_next(&arr);
    }
    SET_STR_RESULT(result, sb_concat(sb));
    sb_free(sb);
    return SYSINFO_RET_OK;
  }
  dbus_message_iter_get_basic(iter, &value);
  switch (type) {
  case DBUS_TYPE_STRING:
    SET_STR_RESULT(result, strdup(value.str));
    return SYSINFO_RET_OK;
  case DBUS_TYPE_BOOLEAN:
    SET_UI64_RESULT(result, value.bool_val);
    return SYSINFO_RET_OK;
  case DBUS_TYPE_UINT64:
  case DBUS_TYPE_INT64:
    SET_UI64_RESULT(result, value.u64);
    return SYSINFO_RET_OK;
  case DBUS_TYPE_UINT32:
  case DBUS_TYPE_INT32:
    SET_UI64_RESULT(result, value.u32);
    return SYSINFO_RET_OK;
  case DBUS_TYPE_DOUBLE:
    SET_DBL_RESULT(result, value.dbl);
    return SYSINFO_RET_OK;
  }
  zbx_free(iter);
  SET_MSG_RESULT(result, zbx_dsprintf(NULL, "unsupported value type: %c", type));
  return SYSINFO_RET_FAIL;
}
int dbus_marshall_property ( AGENT_RESULT * result , const char * service , const char * path , const char * interface , const char * property ) { int type = 0 ; DBusMessageIter * iter = NULL , arr ; DBusBasicValue value ; char * s = NULL ; StringBuilder * sb = NULL ; iter = dbus_get_property ( service , path , interface , property ) ; if ( NULL == iter ) { SET_MSG_RESULT ( result , strdup ( " " ) ) ; zbx_free ( iter ) ; return SYSINFO_RET_FAIL ; } type = dbus_message_iter_get_arg_type ( iter ) ; if ( DBUS_TYPE_ARRAY == type ) { dbus_message_iter_recurse ( iter , & arr ) ; sb = sb_create ( ) ; while ( DBUS_TYPE_INVALID != ( type = dbus_message_iter_get_arg_type ( & arr ) ) ) { if ( DBUS_TYPE_STRING == type ) { if ( ! sb_empty ( sb ) ) sb_append ( sb , " " ) ; dbus_message_iter_get_basic ( & arr , & s ) ; sb_append ( sb , s ) ; } dbus_message_iter_next ( & arr ) ; } SET_STR_RESULT ( result , sb_concat ( sb ) ) ; sb_free ( sb ) ; return SYSINFO_RET_OK ; } dbus_message_iter_get_basic ( iter , & value ) ; switch ( type ) { case DBUS_TYPE_STRING : SET_STR_RESULT ( result , strdup ( value . str ) ) ; return SYSINFO_RET_OK ; case DBUS_TYPE_BOOLEAN : SET_UI64_RESULT ( result , value . bool_val ) ; return SYSINFO_RET_OK ; case DBUS_TYPE_UINT64 : case DBUS_TYPE_INT64 : SET_UI64_RESULT ( result , value . u64 ) ; return SYSINFO_RET_OK ; case DBUS_TYPE_UINT32 : case DBUS_TYPE_INT32 : SET_UI64_RESULT ( result , value . u32 ) ; return SYSINFO_RET_OK ; case DBUS_TYPE_DOUBLE : SET_DBL_RESULT ( result , value . dbl ) ; return SYSINFO_RET_OK ; } zbx_free ( iter ) ; SET_MSG_RESULT ( result , zbx_dsprintf ( NULL , " " , type ) ) ; return SYSINFO_RET_FAIL ; }
dbus_marshall_property gets the value of a d-bus property and marshalls it
 into a Zabbix AGENT_RESULT struct.
dbus_marshall_property gets the value of a d - bus property and marshalls it into a Zabbix AGENT_RESULT struct .
// marshal string array // marshal basic type