1 /* $Id$
2 *
3 * Lasso - A free implementation of the Liberty Alliance specifications.
4 *
5 * Copyright (C) 2004-2007 Entr'ouvert
6 * http://lasso.entrouvert.org
7 *
8 * Authors: See AUTHORS file in top-level directory.
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, see <http://www.gnu.org/licenses/>.
22 */
23
24 #include "../xml/private.h"
25 #include "personal_profile_service.h"
26 #include "../xml/idwsf_strings.h"
27 #include "data_service.h"
28 #include "wsf_profile_private.h"
29 #include "discovery.h"
30 #include "../utils.h"
31
32 /**
33 * SECTION:personal_profile_service
34 * @short_description: a subclass of LassoDataService to access Personal Profile datas
35 * @stability: Unstable
36 */
37
38 /*****************************************************************************/
39 /* public methods */
40 /*****************************************************************************/
41
42 char*
lasso_personal_profile_service_get_email(LassoPersonalProfileService * service)43 lasso_personal_profile_service_get_email(LassoPersonalProfileService *service)
44 {
45 xmlNode *xmlnode, *child;
46 xmlChar *msgAccount = NULL, *msgProvider = NULL;
47 char *email;
48 GList *answers = NULL, *answer = NULL;
49 gint rc = 0;
50
51 g_return_val_if_fail(LASSO_IS_PERSONAL_PROFILE_SERVICE(service) == TRUE, NULL);
52
53 rc = lasso_data_service_get_answers_by_select(LASSO_DATA_SERVICE(service),
54 "/pp:PP/pp:MsgContact", &answers);
55
56 lasso_foreach(answer, answers)
57 {
58 xmlnode = (xmlNode*)answer->data;
59 child = xmlnode->children;
60 while (child != NULL) {
61 if (child->type != XML_ELEMENT_NODE) {
62 child = child->next;
63 continue;
64 }
65
66 if (strcmp((char *)child->name, "MsgAccount") == 0) {
67 msgAccount = xmlNodeGetContent(child);
68 } else if (strcmp((char *)child->name, "MsgProvider") == 0) {
69 msgProvider = xmlNodeGetContent(child);
70 }
71
72 if (msgAccount != NULL && msgProvider != NULL) {
73 break;
74 }
75
76 child = child->next;
77 }
78
79 if (msgAccount && msgProvider) {
80 email = g_strdup_printf("%s@%s", msgAccount, msgProvider);
81 break;
82 } else {
83 email = NULL;
84 }
85 lasso_release_xml_string(msgAccount);
86 lasso_release_xml_string(msgProvider);
87 lasso_release_xml_node(xmlnode);
88 }
89
90 lasso_release_xml_string(msgAccount);
91 lasso_release_xml_string(msgProvider);
92 lasso_release_xml_node(xmlnode);
93 return email;
94 }
95
96 /*****************************************************************************/
97 /* instance and class init functions */
98 /*****************************************************************************/
99
100 GType
lasso_personal_profile_service_get_type()101 lasso_personal_profile_service_get_type()
102 {
103 static GType this_type = 0;
104
105 if (!this_type) {
106 lasso_discovery_register_constructor_for_service_type(LASSO_PP10_HREF,
107 (LassoWsfProfileConstructor)lasso_personal_profile_service_new_full);
108 static const GTypeInfo this_info = {
109 sizeof(LassoPersonalProfileServiceClass),
110 NULL,
111 NULL,
112 NULL,
113 NULL,
114 NULL,
115 sizeof(LassoPersonalProfileService),
116 0,
117 NULL,
118 NULL
119 };
120
121 this_type = g_type_register_static(LASSO_TYPE_DATA_SERVICE,
122 "LassoPersonalProfileService", &this_info, 0);
123 }
124 return this_type;
125 }
126
127 LassoPersonalProfileService*
lasso_personal_profile_service_new(LassoServer * server)128 lasso_personal_profile_service_new(LassoServer *server)
129 {
130 LassoPersonalProfileService *service;
131
132 g_return_val_if_fail(LASSO_IS_SERVER(server), NULL);
133
134 service = g_object_new(LASSO_TYPE_PERSONAL_PROFILE_SERVICE, NULL);
135 LASSO_WSF_PROFILE(service)->server = g_object_ref(server);
136
137 return service;
138 }
139
140 LassoPersonalProfileService*
lasso_personal_profile_service_new_full(LassoServer * server,LassoDiscoResourceOffering * offering)141 lasso_personal_profile_service_new_full(LassoServer *server, LassoDiscoResourceOffering *offering)
142 {
143 LassoPersonalProfileService *service = lasso_personal_profile_service_new(server);
144
145 g_return_val_if_fail(LASSO_IS_DISCO_RESOURCE_OFFERING(offering), NULL);
146
147 if (service == NULL) {
148 return NULL;
149 }
150
151 lasso_wsf_profile_set_resource_offering(&service->parent.parent, offering);
152
153 return service;
154 }
155
156