Ejemplo n.º 1
0
/**
 * couchdb_document_contact_im_new:
 * @uuid: A unique ID
 * @address: IM address
 * @description: Description for this IM address
 * @protocol: Protocol used for this IM address
 *
 * Returns a #CouchdbStructField representing the given IM address.
 *
 * Returns: (transfer full): A newly-created #CouchdbStructField representing
 * the given IM address information.
 */
CouchdbStructField *
couchdb_document_contact_im_new (const char *uuid,
				 const char *address,
				 const char *description,
				 const char *protocol)
{
	CouchdbStructField *sf;

	sf = couchdb_struct_field_new_from_json_object (json_object_new ());
	if (uuid != NULL)
		couchdb_struct_field_set_uuid (sf, uuid);
	else {
		char *new_uuid = generate_uuid ();
		couchdb_struct_field_set_uuid (sf, new_uuid);
		g_free (new_uuid);
	}

	if (address != NULL)
		couchdb_document_contact_im_set_address (sf, address);
	if (description != NULL)
		couchdb_document_contact_im_set_description (sf, description);
	if (protocol != NULL)
		couchdb_document_contact_im_set_protocol (sf, protocol);

	return sf;
}
/**
 * couchdb_struct_field_get_struct_field:
 * @sf: A #CouchdbStructField object
 * @field: Name of the field
 *
 * Retrieve the value of a struct field from the given struct field.
 *
 * Return value: The value of the given field.
 */
CouchdbStructField *
couchdb_struct_field_get_struct_field (CouchdbStructField *sf, const char *field)
{
	g_return_val_if_fail (sf != NULL, NULL);
	g_return_val_if_fail (field != NULL, NULL);

	if (!json_object_has_member (sf->json_object, field))
		return NULL;

	return couchdb_struct_field_new_from_json_object (
		json_object_get_object_member (sf->json_object, field));
}
Ejemplo n.º 3
0
static void
foreach_object_cb (JsonObject *object,
		  const char *member_name,
		  JsonNode *member_node,
		  gpointer user_data)
{
	GSList **list = (GSList **) user_data;

	if (json_node_get_node_type (member_node) == JSON_NODE_OBJECT) {
		CouchdbStructField *sf;

		sf = couchdb_struct_field_new_from_json_object (
			json_object_ref (json_node_get_object (member_node)));
		couchdb_struct_field_set_uuid (sf, member_name);
		*list = g_slist_prepend (*list, sf);
	}
}
Ejemplo n.º 4
0
/**
 * couchdb_document_contact_address_new:
 * @uuid: A unique ID
 * @street: Street
 * @ext_street: Extra information for the street
 * @city: City
 * @state: State or region
 * @country: Country
 * @postalcode: Postal code
 * @pobox: Post Office box
 * @description: Description for thos address
 *
 * Returns a #CouchdbStructField representing the given address.
 *
 * Returns: (transfer full): A newly-created #CouchdbStructField representing
 * the given address information.
 */
CouchdbStructField *
couchdb_document_contact_address_new (const char *uuid,
				      const char *street,
				      const char *ext_street,
				      const char *city,
				      const char *state,
				      const char *country,
				      const char *postalcode,
				      const char *pobox,
				      const char *description)
{
	CouchdbStructField *sf;

	sf = couchdb_struct_field_new_from_json_object (json_object_new ());
	if (uuid != NULL)
		couchdb_struct_field_set_uuid (sf, uuid);
	else {
		char *new_uuid = generate_uuid ();
		couchdb_struct_field_set_uuid (sf, new_uuid);
		g_free (new_uuid);
	}

	if (street)
		couchdb_document_contact_address_set_street (sf, street);
	if (ext_street)
		couchdb_document_contact_address_set_ext_street (sf, ext_street);
	if (city)
		couchdb_document_contact_address_set_city (sf, city);
	if (state)
		couchdb_document_contact_address_set_state (sf, state);
	if (country)
		couchdb_document_contact_address_set_country (sf, country);
	if (postalcode)
		couchdb_document_contact_address_set_postalcode (sf, postalcode);
	if (pobox)
		couchdb_document_contact_address_set_pobox (sf, pobox);
	if (description)
		couchdb_document_contact_address_set_description (sf, description);

	return sf;
}
CouchdbStructField *
desktopcouch_document_contact_email_new (const char *uuid, const char *address, const char *description)
{
	CouchdbStructField *sf;

	sf = couchdb_struct_field_new_from_json_object (json_object_new ());
	if (uuid != NULL)
		couchdb_struct_field_set_uuid (sf, uuid);
	else {
		char *new_uuid = generate_uuid ();
		couchdb_struct_field_set_uuid (sf, new_uuid);
		g_free (new_uuid);
	}

	if (address)
		desktopcouch_document_contact_email_set_address (sf, address);
	if (description)
		desktopcouch_document_contact_email_set_description (sf, description);

	return sf;
}
Ejemplo n.º 6
0
/**
 * couchdb_document_contact_phone_new:
 * @uuid: A unique ID
 * @number: A phone number
 * @description: Description for this phone number
 * @priority: Priority of this phone number
 *
 * Returns a #CouchdbStructField representing the given phone number.
 *
 * Returns: (transfer full): A newly-created #CouchdbStructField representing
 * the given phone number information.
 */
CouchdbStructField *
couchdb_document_contact_phone_new (const char *uuid, const char *number, const char *description, gint priority)
{
	CouchdbStructField *sf;

	sf = couchdb_struct_field_new_from_json_object (json_object_new ());
	if (uuid != NULL)
		couchdb_struct_field_set_uuid (sf, uuid);
	else {
		char *new_uuid = generate_uuid ();
		couchdb_struct_field_set_uuid (sf, new_uuid);
		g_free (new_uuid);
	}

	if (number)
		couchdb_document_contact_phone_set_number (sf, number);
	if (description)
		couchdb_document_contact_phone_set_description (sf, description);
	couchdb_document_contact_phone_set_priority (sf, priority);

	return sf;
}
/**
 * couchdb_struct_field_new_from_string:
 * @str: A JSON string
 *
 * Create a new struct field object, filling it with values taken from a string
 * representing a JSON object.
 *
 * Return value: A newly-created #CouchdbStructField object.
 */
CouchdbStructField *
couchdb_struct_field_new_from_string (const char *str)
{
	JsonParser *parser;
	GError *error = NULL;
	CouchdbStructField *sf = NULL;

	g_return_val_if_fail (str != NULL, NULL);

	parser = json_parser_new ();
	if (json_parser_load_from_data (parser, str, strlen (str), &error)) {
		JsonNode *node = json_parser_get_root (parser);

		if (json_node_get_node_type (node) == JSON_NODE_OBJECT)
			sf = couchdb_struct_field_new_from_json_object (json_node_get_object (node));
	} else {
		g_warning ("Could not parse string: %s", error->message);
		g_error_free (error);
	}

	g_object_unref (G_OBJECT (parser));

	return sf;
}