Esempio n. 1
0
static status_t
_get_container_user_properties(gs_grid_storage_t *hc, struct hc_url_s *url,
		char ***props, gs_error_t **gserr)
{
	GError *gerr = NULL;
	gboolean rc;
	addr_info_t *m1 = NULL;
	GSList *excluded = NULL;

	gs_container_t *c = gs_get_container(hc, hc_url_get(url, HCURL_USER), 0, gserr);
	if(!c)
		return 0;
	for (;;) {

		m1 = gs_resolve_meta1v2(hc, hc_url_get_id(url), c->info.name, 1, &excluded, &gerr);

		if (!m1) {
			*gserr = gs_error_new(CODE_INTERNAL_ERROR, "No META1 found for [%s]", hc_url_get(url, HCURL_USER));
			break;
		}

		rc = meta1v2_remote_reference_get_property (m1, &gerr, url, NULL, props);

		if (!rc) {
			excluded = g_slist_prepend(excluded, m1);
			m1=NULL;
			if (gerr) {
				if (CODE_IS_NETWORK_ERROR(gerr->code)) {
					g_error_free(gerr);
					gerr = NULL;
				} else {
					GSERRORCAUSE(gserr, gerr, "Cannot get container user properties");
					break;
				}
			}
		} else {
			break;
		}
	}
	if (excluded) {
		g_slist_foreach(excluded, addr_info_gclean, NULL);
		g_slist_free(excluded);
	}
	if (m1)
		g_free(m1);

	gs_container_free(c);

	if (gerr)
		g_error_free(gerr);

	return rc;
}
Esempio n. 2
0
int
main(int argc, char **args)
{
	int rc;
	gs_error_t *err = NULL;
	gs_grid_storage_t *gs = NULL;
	gs_container_t *container = NULL;

	signal(SIGPIPE, sig_pipe);

	if (argc <= 1) {
		help();
		return 1;
	}

	if (!parse_opt(argc, args)) {
		PRINT_ERROR("Cannot parse the arguments\n");
		help();
		return 1;
	}

	if (!conf_check()) {
		PRINT_ERROR("Missing parameters\n");
		help();
		return 1;
	}

	/*open the connection to the META0 */
	gs = gs_grid_storage_init(meta0_url, &err);
	if (!gs) {
		PRINT_ERROR("grid storage error : cannot init the namespace configuration from %s\n", meta0_url);
		return -1;
	}
	PRINT_DEBUG("Connected to the GridStorage namespace %s\n", meta0_url);

	/*find the container */
	container = gs_get_container(gs, container_name, 0, &err);
	if (!container) {
		PRINT_ERROR("grid storage error : cannot find the container %s : %s\n",
			container_name, err->msg);
		gs_grid_storage_free(gs);
		return -1;
	}
	PRINT_DEBUG("container %s found\n", container_name);

	switch (action) {
	case A_CONTAINER_GET:
		rc = get_service_for_container(container,&err);
		if (rc != 0)
			PRINT_ERROR("Failed to list the index services used in container [%s] : %s\n",
				container_name, gs_error_get_message(err));
		break;
	case A_CONTAINER_LIST:
		rc = list_services_used_by_container(container,&err);
		if (rc != 0)
			PRINT_ERROR("Failed to list the index services used in container [%s] : %s\n",
				container_name, gs_error_get_message(err));
		break;
	case A_LISTSRV:
		rc = list_services_used(container,&err);
		if (rc != 0)
			PRINT_ERROR("Failed to list the index services used in container [%s] : %s\n",
				container_name, gs_error_get_message(err));
		break;
		
	case A_LISTCONTENT:
		rc = list_services_for_path(container,&err, remote_path);
		if (rc != 0)
			PRINT_ERROR("Failed to list the index services used in container [%s] for path [%s] : %s\n",
				container_name, remote_path, gs_error_get_message(err));
		break;

	default:
		PRINT_ERROR("Action not set, please provide at least '-l' or '-c'\n");
		rc = -1;
		break;
	}

	gs_container_free(container);
	gs_grid_storage_free(gs);
	return 0;
}
Esempio n. 3
0
static char *
geoniche_geostuff(const waypoint *wpt)
{
	char *gs = NULL, *tmp1, *tmp2, *tmp3;
	char tbuf[10240];

	if (!wpt->gc_data->terr) {
		return NULL;
	}

	snprintf(tbuf, sizeof(tbuf), "\n%s by %s\n\n", gs_get_cachetype(wpt->gc_data->type), wpt->gc_data->placer);
	gs = xstrappend(gs, tbuf);

/*
 * 3 May 06: Removed duplicated information
 *
 * 	snprintf(tbuf, sizeof(tbuf), "Waypoint: %s %s\n", wpt->shortname, wpt->description);	
 *	gs = xstrappend(gs, tbuf);
 */

/*
 * 3 May 06: Added container type
 */
	snprintf(tbuf, sizeof(tbuf), "Container: %s\nDifficulty: %3.1f\nTerrain: %3.1f\n\n", gs_get_container(wpt->gc_data->container), wpt->gc_data->diff/10.0, wpt->gc_data->terr/10.0);
	gs = xstrappend(gs, tbuf);

	tmp1 = strip_html(&wpt->gc_data->desc_short);
	tmp2 = strip_html(&wpt->gc_data->desc_long);
	gs = xstrappend(gs, tmp1);
	gs = xstrappend(gs, tmp2);

	tmp3 = rot13(wpt->gc_data->hint);
	snprintf(tbuf, sizeof(tbuf), "\n\nHint: %s\n", tmp3);
	gs = xstrappend(gs, tbuf);

	xfree(tmp1);
	xfree(tmp2);
	xfree(tmp3);

	tmp1 = enscape(gs);
	xfree(gs);

	return tmp1;
}
Esempio n. 4
0
static void
text_disp(const waypoint *wpt)
{
	int latint, lonint;
	char tbuf[1024];
	time_t tm = wpt->creation_time;
	gbint32 utmz;
	double utme, utmn;
	char utmzc;
	char *tmpout1, *tmpout2;
	char *altout;
	fs_xml *fs_gpx;

	waypoint_count++;
	
	if (split_output) {
		char *thisfname;
		xasprintf(&thisfname, "%s%d", output_name, waypoint_count);
		file_out = gbfopen(thisfname, "w", MYNAME);
	}
	
	lonint = abs((int) wpt->longitude);
	latint = abs((int) wpt->latitude);

	GPS_Math_WGS84_To_UTM_EN(wpt->latitude, wpt->longitude, 
		&utme, &utmn, &utmz, &utmzc);

	if (tm == 0) 
		tm = time(NULL);
	strftime(tbuf, sizeof(tbuf), "%d-%b-%Y", localtime(&tm));

	tmpout1 = pretty_deg_format(wpt->latitude, wpt->longitude, degformat[2], " ", 0);
	if (wpt->altitude != unknown_alt) {
		xasprintf(&altout, " alt:%d", (int) ( (altunits[0]=='f')?METERS_TO_FEET(wpt->altitude):wpt->altitude) );
	}
	else {
		altout = "";
	}
	xasprintf (&tmpout2, "%s (%d%c %6.0f %7.0f)%s", tmpout1, utmz, utmzc, utme, utmn, altout );
	gbfprintf(file_out, "%-16s  %59s\n",
		(global_opts.synthesize_shortnames) ? mkshort_from_wpt(mkshort_handle, wpt) : wpt->shortname,
		tmpout2);
	xfree(tmpout2);
	xfree(tmpout1);	
	if (altout[0]) 
		xfree(altout);
	

	if (strcmp(wpt->description, wpt->shortname)) {
		gbfprintf(file_out, "%s", wpt->description);
		if (wpt->gc_data->placer) 
			gbfprintf(file_out, " by %s", wpt->gc_data->placer);
		}
		if (wpt->gc_data->terr) {
			gbfprintf(file_out, " - %s / %s - (%d%s / %d%s)\n", 
				gs_get_cachetype(wpt->gc_data->type), gs_get_container(wpt->gc_data->container), 
				(int)(wpt->gc_data->diff / 10), (wpt->gc_data->diff%10)?".5":"", 
				(int)(wpt->gc_data->terr / 10), (wpt->gc_data->terr%10)?".5":""  ); 
	        if (wpt->gc_data->desc_short.utfstring) {
	                char *stripped_html = strip_html(&wpt->gc_data->desc_short);
			gbfprintf (file_out, "\n%s\n", stripped_html);
                	xfree(stripped_html);
       		}
	        if (wpt->gc_data->desc_long.utfstring) {
	                char *stripped_html = strip_html(&wpt->gc_data->desc_long);
			gbfprintf (file_out, "\n%s\n", stripped_html);
                	xfree(stripped_html);
       		}
		if (wpt->gc_data->hint) {
			char *hint = NULL;
			if ( txt_encrypt ) 
				hint = rot13( wpt->gc_data->hint );
			else
				hint = xstrdup( wpt->gc_data->hint );
			gbfprintf (file_out, "\nHint: %s\n", hint);
			xfree( hint );
		}
	}
	else if (wpt->notes && (!wpt->description || strcmp(wpt->notes,wpt->description))) {
		gbfprintf (file_out, "\n%s\n", wpt->notes);
	}

	fs_gpx = NULL;
	if ( includelogs ) {
		fs_gpx = (fs_xml *)fs_chain_find( wpt->fs, FS_GPX);
	}
	
	if ( fs_gpx && fs_gpx->tag ) {
		xml_tag *root = fs_gpx->tag;
		xml_tag *curlog = NULL;
		xml_tag *logpart = NULL;
		curlog = xml_findfirst( root, "groundspeak:log" );
		while ( curlog ) {
			time_t logtime = 0;
			struct tm *logtm = NULL;
			gbfprintf( file_out, "\n" );
			
			logpart = xml_findfirst( curlog, "groundspeak:type" );
			if ( logpart ) {
				gbfprintf( file_out, "%s by ", logpart->cdata );
			}
			
			logpart = xml_findfirst( curlog, "groundspeak:finder" );
			if ( logpart ) {
				gbfprintf( file_out, "%s on ", logpart->cdata );
			}
			
			logpart = xml_findfirst( curlog, "groundspeak:date" );
			if ( logpart ) {
				logtime = xml_parse_time( logpart->cdata, NULL);
				logtm = localtime( &logtime );
				if ( logtm ) {
					gbfprintf( file_out, 
						"%4.4d-%2.2d-%2.2d\n",
						logtm->tm_year+1900,
						logtm->tm_mon+1,
						logtm->tm_mday );
				}
			}
			
			logpart = xml_findfirst( curlog, "groundspeak:log_wpt" );
			if ( logpart ) {
				char *coordstr = NULL;
				float lat = 0;
				float lon = 0;
				coordstr = xml_attribute( logpart, "lat" );
				if ( coordstr ) {
					lat = atof( coordstr );
				}
			        coordstr = xml_attribute( logpart, "lon" );
				if ( coordstr ) {
					lon = atof( coordstr );
				}
				coordstr = pretty_deg_format(lat, lon, degformat[2], " ", 0);
				gbfprintf( file_out, "%s\n", coordstr);
				xfree(coordstr);
			}
			
			logpart = xml_findfirst( curlog, "groundspeak:text" );
			if ( logpart ) {
				char *encstr = NULL;
				char *s = NULL;
				int encoded = 0;
				encstr = xml_attribute( logpart, "encoded" );
				encoded = (encstr[0] != 'F');
				
				if ( txt_encrypt && encoded ) {
					s = rot13( logpart->cdata );
				}
				else {
					s = xstrdup( logpart->cdata );
				}
					
				gbfprintf( file_out, "%s", s ); 
				xfree( s );
			}

			gbfprintf( file_out, "\n" );
			curlog = xml_findnext( root, curlog, "groundspeak:log" );
		}
	}
	if (! suppresssep) 
		gbfprintf(file_out, "\n-----------------------------------------------------------------------------\n");
	else
		gbfprintf(file_out, "\n");

	if (split_output) {
		gbfclose(file_out);
		file_out = NULL;
	}
}
Esempio n. 5
0
int main (int argc, char ** args)
{
	int rc = -1;

	gs_error_t *err = NULL;
	gs_grid_storage_t *hc;
	gs_container_t *container;
	char *ns;
	char cname[60];

	srand(time(NULL));

	if (argc != 2) {
		g_error("Usage: %s NS\n", args[0]);
		return rc;
	}

	ns = args[1];

	bzero(cname, sizeof(cname));
	g_snprintf(cname, sizeof(cname), "SOLR%d", rand());

	printf("Working with container [%s]\n", cname);

	hc = gs_grid_storage_init( ns, &err );
	if(!hc) {
		printf("failed to init hc\n");
		return rc;
	}

	container = gs_get_container(hc, cname, 1, &err);
	if(!container) {
		printf("Failed to resolve container\n");
		goto end_label;
	}

	gs_service_t **srv_array = NULL;
	srv_array = gs_container_service_get_available(container, "meta0", &err);
	char url[256];
	bzero(url, sizeof(url));
	gs_service_get_url(srv_array[0], url, sizeof(url));
	printf("New service linked\n");
	printf("service url = [%s]\n", url);

	if(srv_array)
		gs_service_free_array(srv_array); 
	
	srv_array = gs_container_service_get_all(container, "meta0", &err);

	bzero(url, sizeof(url));
	gs_service_get_url(srv_array[0], url, sizeof(url));
	printf("Already linked service :\n");
	printf("service url = [%s]\n", url);

	if(srv_array)
		gs_service_free_array(srv_array); 

end_label:

	if(container) {
		gs_container_free(container);
		container = NULL;
	}

	if(hc) {
		gs_grid_storage_free(hc);
		hc = NULL;
	}

	if(err) {
		gs_error_free(err);
		err= NULL;
	}
}