Пример #1
0
gboolean	ug_download_assign_attachment (UgDataset* dest_data, UgDataset* src_data)
{
	union {
		UgetHttp*		http;
		UgetRelation*		relation;
	} src;
	union {
		UgetHttp*		http;
		UgetRelation*		relation;
	} dest;

	// relation
	src.relation = UG_DATASET_RELATION (src_data);
	if (src.relation == NULL || src.relation->attached.stamp == 0)
		return FALSE;
	dest.relation = UG_DATASET_RELATION (dest_data);
	if (dest.relation == NULL)
		dest.relation = ug_dataset_alloc_front (src_data, UgetRelationInfo);
	ug_attachment_ref (src.relation->attached.stamp);
	ug_attachment_unref (dest.relation->attached.stamp);
	dest.relation->attached.stamp = src.relation->attached.stamp;
	ug_str_set (&dest.relation->attached.folder, src.relation->attached.folder, -1);

	// http
	src.http  = ug_dataset_get (src_data, UgetHttpInfo, 0);
	if (src.http) {
		dest.http = ug_dataset_realloc (dest_data, UgetHttpInfo, 0);
		ug_str_set (&dest.http->post_file,   src.http->post_file,   -1);
		ug_str_set (&dest.http->cookie_file, src.http->cookie_file, -1);
	}
	return TRUE;
}
Пример #2
0
// ----------------------------------------------------------------------------
// UgMarkup parse/write
static void ug_dataset_parser_start_element (GMarkupParseContext*	context,
                                              const gchar*		element_name,
                                              const gchar**		attr_names,
                                              const gchar**		attr_values,
                                              UgDataset*		dataset,
                                              GError**			error)
{
	const UgData1Interface*	iface;
	UgDatalist*			datalist;
	guint				index;

	if (strcmp (element_name, "DataClass") != 0) {
		g_markup_parse_context_push (context, &ug_markup_skip_parser, NULL);
		return;
	}

	for (index=0; attr_names[index]; index++) {
		if (strcmp (attr_names[index], "name") != 0)
			continue;

		// find registered data interface (UgData1Interface)
		iface = ug_data1_interface_find (attr_values[index]);
		if (iface) {
			// Create new instance by UgData1Interface and prepend it to list.
			datalist = ug_dataset_alloc_front (dataset, iface);
			g_markup_parse_context_push (context, &ug_data1_parser, datalist);
		}
		else {
			// Skip unregistered interface, don't parse anything.
			g_markup_parse_context_push (context, &ug_markup_skip_parser, NULL);
		}
		break;
	}
}
Пример #3
0
gboolean	ug_download_create_attachment (UgDataset* dataset, gboolean force)
{
	UgetHttp*		http;
	UgetRelation*		relation;
	gchar*			file;
	gchar*			dir;
	guint			dir_len;

	// check
	relation = UG_DATASET_RELATION (dataset);
	if (relation == NULL)
		relation = ug_dataset_alloc_front (dataset, UgetRelationInfo);
	else if (relation->attached.stamp)
		return FALSE;
	http = ug_dataset_get (dataset, UgetHttpInfo, 0);
	if ( (http && (http->cookie_file || http->post_file)) == FALSE && force == FALSE)
		return FALSE;

	// create attachment folder
	dir = ug_attachment_alloc (&relation->attached.stamp);
	if (dir == NULL)
		return FALSE;
	dir_len = strlen (dir);
	g_free (relation->attached.folder);
	relation->attached.folder = dir;

	// UgetHttp
	if (http) {
		if (http->cookie_file && dir_len != strspn (dir, http->cookie_file))
		{
			file = g_build_filename (dir, "http-CookieFile", NULL);
			// copy file and save path
			if (ug_copy_file (http->cookie_file, file) == -1)
				g_free (file);
			else {
				g_free (http->cookie_file);
				http->cookie_file = file;
			}
		}
		if (http->post_file && dir_len != strspn (dir, http->post_file))
		{
			file = g_build_filename (dir, "http-PostFile", NULL);
			// copy file and save path
			if (ug_copy_file (http->post_file, file) == -1)
				g_free (file);
			else {
				g_free (http->post_file);
				http->post_file = file;
			}
		}
	}

	return TRUE;
}