コード例 #1
0
ファイル: weather_wunder.c プロジェクト: maxux/z03
static char * wunder_multiple(json_t *root, char *chan) {
	json_t *node, *subnode;
	char temp[128];
	
	node = json_object_get(root, "response");
	if(!json_is_object(root)) {
		printf("[+] wunder/parse: no response found\n");
		return NULL;
	}
	
	subnode = json_object_get(node, "results");
	if(!json_is_array(subnode)) {
		printf("[+] wunder/parse: not a multiple results, skipping\n");
		return NULL;
	}
	
	size_t index;
	json_t *value;
	list_t *rlist = list_init(NULL);

	json_array_foreach(subnode, index, value) {
		const char *name = json_string_value(json_object_get(value, "name"));
		const char *country = json_string_value(json_object_get(value, "country_name"));
		const char *link = json_string_value(json_object_get(value, "l"));
		
		sprintf(temp, "%s/%s: %s", country, name, link + 3);
		list_append(rlist, temp, temp);
	}

	char *implode = list_implode(rlist, 10);
	list_free(rlist);
	
	return implode;
}
コード例 #2
0
ファイル: ows_storage.c プロジェクト: joathan00/gitted.ig3
static void ows_layer_storage_fill(ows * o, ows_layer * l, bool is_geom)
{
  buffer * sql;
  PGresult *res;
  int i, end;

  assert(o);
  assert(l);
  assert(l->storage);

  sql = buffer_init();
  if (is_geom) buffer_add_str(sql, "SELECT srid, f_geometry_column FROM geometry_columns");
  else         buffer_add_str(sql, "SELECT srid, f_geography_column FROM geography_columns");

  buffer_add_str(sql, " WHERE f_table_schema='");
  buffer_copy(sql, l->storage->schema);
  buffer_add_str(sql, "' AND f_table_name='");
  buffer_copy(sql, l->storage->table);
  buffer_add_str(sql, "'");
  if (l->include_items) {
    buffer_add_str(sql, is_geom?" AND f_geometry_column IN ('":" AND f_geography_column IN ('");
    list_implode(sql, "','", l->include_items);
    buffer_add_str(sql, "')");
  }
  if (l->exclude_items) {
    buffer_add_str(sql, is_geom?" AND f_geometry_column NOT IN ('":" AND f_geography_column NOT IN ('");
    list_implode(sql, "','", l->exclude_items);
    buffer_add_str(sql, "')");
  }
  buffer_add_str(sql, ";");

  res = ows_psql_exec(o, sql->buf);
  buffer_empty(sql);

  if (PQresultStatus(res) != PGRES_TUPLES_OK || PQntuples(res) == 0) {
    PQclear(res);

    ows_error(o, OWS_ERROR_REQUEST_SQL_FAILED,
              "All config file layers are not availables in geometry_columns or geography_columns",
              "storage");
    return;
  }

  l->storage->srid = atoi(PQgetvalue(res, 0, 0));

  for (i = 0, end = PQntuples(res); i < end; i++)
    list_add_str(l->storage->geom_columns, PQgetvalue(res, i, 1));

  buffer_add_str(sql, "SELECT * FROM spatial_ref_sys WHERE srid=");
  buffer_add_str(sql, PQgetvalue(res, 0, 0));
  buffer_add_str(sql, " AND proj4text like '%%units=m%%'");

  PQclear(res);

  res = ows_psql_exec(o, sql->buf);
  buffer_free(sql);

  if (PQntuples(res) != 1)
    l->storage->is_degree = true;
  else
    l->storage->is_degree = false;

  PQclear(res);

  ows_storage_fill_pkey(o, l);
  ows_storage_fill_attributes(o, l);
  ows_storage_fill_not_null(o, l);
}