summaryrefslogtreecommitdiffstats
path: root/lasso/id-wsf/personal_profile_service.c
blob: 5bd61b3f56a786667370b699cb9362c7b5dc5c18 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
/* $Id$
 *
 * Lasso - A free implementation of the Liberty Alliance specifications.
 *
 * Copyright (C) 2004-2007 Entr'ouvert
 * http://lasso.entrouvert.org
 *
 * Authors: See AUTHORS file in top-level directory.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, see <http://www.gnu.org/licenses/>.
 */

#include "../xml/private.h"
#include "personal_profile_service.h"
#include "../xml/idwsf_strings.h"
#include "data_service.h"
#include "wsf_profile_private.h"
#include "discovery.h"
#include "../utils.h"

/**
 * SECTION:personal_profile_service
 * @short_description: a subclass of LassoDataService to access Personal Profile datas
 * @stability: Unstable
 */

/*****************************************************************************/
/* public methods                                                            */
/*****************************************************************************/

char*
lasso_personal_profile_service_get_email(LassoPersonalProfileService *service)
{
	xmlNode *xmlnode, *child;
	xmlChar *msgAccount = NULL, *msgProvider = NULL;
	char *email;
	GList *answers = NULL, *answer = NULL;
	gint rc = 0;

	g_return_val_if_fail(LASSO_IS_PERSONAL_PROFILE_SERVICE(service) == TRUE, NULL);

	rc = lasso_data_service_get_answers_by_select(LASSO_DATA_SERVICE(service),
			"/pp:PP/pp:MsgContact", &answers);

	lasso_foreach(answer, answers)
	{
		xmlnode = (xmlNode*)answer->data;
		child = xmlnode->children;
		while (child != NULL) {
			if (child->type != XML_ELEMENT_NODE) {
				child = child->next;
				continue;
			}

			if (strcmp((char *)child->name, "MsgAccount") == 0) {
				msgAccount = xmlNodeGetContent(child);
			} else if (strcmp((char *)child->name, "MsgProvider") == 0) {
				msgProvider = xmlNodeGetContent(child);
			}

			if (msgAccount != NULL && msgProvider != NULL) {
				break;
			}

			child = child->next;
		}

		if (msgAccount && msgProvider) {
			email = g_strdup_printf("%s@%s", msgAccount, msgProvider);
			break;
		} else {
			email = NULL;
		}
		lasso_release_xml_string(msgAccount);
		lasso_release_xml_string(msgProvider);
		lasso_release_xml_node(xmlnode);
	}

	lasso_release_xml_string(msgAccount);
	lasso_release_xml_string(msgProvider);
	lasso_release_xml_node(xmlnode);
	return email;
}

/*****************************************************************************/
/* instance and class init functions                                         */
/*****************************************************************************/

GType
lasso_personal_profile_service_get_type()
{
	static GType this_type = 0;

	if (!this_type) {
		lasso_discovery_register_constructor_for_service_type(LASSO_PP10_HREF,
			(LassoWsfProfileConstructor)lasso_personal_profile_service_new_full);
		static const GTypeInfo this_info = {
			sizeof(LassoPersonalProfileServiceClass),
			NULL,
			NULL,
			NULL,
			NULL,
			NULL,
			sizeof(LassoPersonalProfileService),
			0,
			NULL,
			NULL
		};

		this_type = g_type_register_static(LASSO_TYPE_DATA_SERVICE,
				"LassoPersonalProfileService", &this_info, 0);
	}
	return this_type;
}

LassoPersonalProfileService*
lasso_personal_profile_service_new(LassoServer *server)
{
	LassoPersonalProfileService *service;

	g_return_val_if_fail(LASSO_IS_SERVER(server), NULL);

	service = g_object_new(LASSO_TYPE_PERSONAL_PROFILE_SERVICE, NULL);
	LASSO_WSF_PROFILE(service)->server = g_object_ref(server);

	return service;
}

LassoPersonalProfileService*
lasso_personal_profile_service_new_full(LassoServer *server, LassoDiscoResourceOffering *offering)
{
	LassoPersonalProfileService *service = lasso_personal_profile_service_new(server);

	g_return_val_if_fail(LASSO_IS_DISCO_RESOURCE_OFFERING(offering), NULL);

	if (service == NULL) {
		return NULL;
	}

	lasso_wsf_profile_set_resource_offering(&service->parent.parent, offering);

	return service;
}