Esempio n. 1
0
void
sim_xml_config_set_config_max_event_tmp (SimConfig     *config)
{
	GdaDataModel  *dm;
  GdaValue      *value;
	gchar					*query;

  g_return_if_fail (config);
  g_return_if_fail (SIM_IS_CONFIG (config));


	query = g_strdup_printf ("SELECT value FROM config WHERE conf='max_event_tmp'");	
  dm = sim_database_execute_single_command (ossim.ossimdb, query);

	if (dm)
	{
	  value = (GdaValue *) gda_data_model_get_value_at (dm, 0, 0);
    if (gda_data_model_get_n_rows(dm) !=0) //to avoid (null)-Critical: gda_value_is_null: assertion `value != NULL' failed
    {                                       
      if (!gda_value_is_null (value))
      {
        config->max_event_tmp = gda_value_stringify (value);
      }
      else
        g_log (G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "sim_xml_config_set_config_max_event_tmp value null");
    }
    else
      config->max_event_tmp = 0;
	}
	else
	{
		g_message ("Error: Config DATA MODEL ERROR");
    config->max_event_tmp = 0;		
	}

	g_free (query);
}
Esempio n. 2
0
static gboolean
server_api_get_info_sensors (GPtrArray ** p_rsensors, GPtrArray ** p_unrsensors, GHashTable ** p_hash)
{
  gboolean result = FALSE;
  GPtrArray *r_array = NULL;
  GPtrArray *unr_array = NULL;
  GdaDataModel *data_model = NULL;
  GdaDataModelIter *iter = NULL;
  GHashTable *hash = NULL;
  GError *error = NULL;
  const GValue *v_av_uuid;
  const GValue *v_name;
  const GValue *v_internal_uuid;
  *p_rsensors = *p_unrsensors = NULL;
  *p_hash = NULL;
  do
  {
    if ((r_array = g_ptr_array_new_with_free_func (g_free)) == NULL)
      break;
    if ((unr_array = g_ptr_array_new_with_free_func (g_free)) == NULL)
      break;
    if ((hash = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free)) == NULL)
    {
      g_message ("%s: Can't create object", __FUNCTION__);
      break;
    }
    if ((data_model =
            sim_database_execute_single_command (ossim.dbossim,
                "SELECT s.name as SENSOR_NAME, HEX(s.id) AS SENSOR_TABLE_UUID, UCASE(HEX(cl.id)) AS SYSTEM_UUID FROM sensor s, system cl WHERE (s.ip=cl.vpn_ip OR s.ip=cl.admin_ip);")) == NULL)
    {
      g_message ("Query error in  server_api_get_info_sensors");
      break;
    }
    if ((iter = gda_data_model_create_iter (data_model)) == NULL)
    {
      g_message ("%s: Can't create data iterator", __FUNCTION__);
      break;
    }
    result = TRUE;
    while (gda_data_model_iter_move_next (iter))
    {

      if ((v_name = gda_data_model_iter_get_value_at_e (iter, 0, &error)) == NULL || !G_VALUE_HOLDS_STRING (v_name))
      {
        result = FALSE;
        break;
      }
      if ((v_internal_uuid = gda_data_model_iter_get_value_at_e (iter, 1, &error)) == NULL || !G_VALUE_HOLDS_STRING (v_internal_uuid))
      {
        result = FALSE;
        break;
      }

      if ((v_av_uuid = gda_data_model_iter_get_value_at_e (iter, 2, &error)) == NULL || !G_VALUE_HOLDS_STRING (v_av_uuid))
      {
        result = FALSE;
        break;
      }
      if (strcmp ("(null)", g_value_get_string (v_name)) == 0)
      {
        g_ptr_array_add (unr_array, g_strdup (g_value_get_string (v_av_uuid)));
      }
      else
      {
        g_ptr_array_add (r_array, g_strdup (g_value_get_string (v_av_uuid)));
      }
      /* Insert the data in the hash table indexed by IP, we need it for the connected sensors */
      /* XXX verify  the next case: New sensor detected, but without av uuid */
      g_hash_table_insert (hash, g_strdup (g_value_get_string (v_internal_uuid)), g_strdup (g_value_get_string (v_av_uuid)));




    }
    if (!result)
      break;

    result = TRUE;
  }
  while (0);
  /* Clean up */
  if (result == FALSE)
  {
    if (r_array != NULL)
      g_ptr_array_unref (r_array);
    if (unr_array != NULL)
      g_ptr_array_unref (unr_array);
    if (hash != NULL)
      g_hash_table_destroy (hash);

  }
  else
  {
    *p_rsensors = r_array;
    *p_unrsensors = unr_array;
    *p_hash = hash;
  }
  if (iter != NULL)
    g_object_unref (iter);
  if (data_model != NULL)
    g_object_unref (data_model);
  if (error != NULL)
    g_error_free (error);

  return result;
}