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 "interaction_profile_service.h"
25 #include "../xml/idwsf_strings.h"
26 #include "wsf_profile.h"
27 #include "../xml/soap-1.1/soap_detail.h"
28 #include "../xml/soap-1.1/soap_fault.h"
29 #include "../xml/is_redirect_request.h"
30 #include "../utils.h"
31 
32 /**
33  * SECTION:interaction_profile_service
34  * @short_description: A service to request user interaction from a principal
35  * @stability: Unstable
36  *
37  */
38 
39 
40 struct _LassoInteractionProfileServicePrivate
41 {
42 	gboolean dispose_has_run;
43 };
44 
45 /*****************************************************************************/
46 /* public methods                                                            */
47 /*****************************************************************************/
48 
49 gint
lasso_interaction_profile_service_init_request(LassoInteractionProfileService * service)50 lasso_interaction_profile_service_init_request(LassoInteractionProfileService *service)
51 {
52 	LassoWsfProfile *profile;
53 	LassoIsInteractionRequest *request;
54 
55 	profile = LASSO_WSF_PROFILE(service);
56 
57 	request = lasso_is_interaction_request_new();
58 
59 	profile->request = LASSO_NODE(request);
60 
61 	return 0;
62 }
63 
64 
65 gint
lasso_interaction_profile_service_process_request_msg(LassoInteractionProfileService * service,const gchar * msg)66 lasso_interaction_profile_service_process_request_msg(LassoInteractionProfileService *service,
67 		const gchar *msg)
68 {
69 	LassoIsInteractionRequest *request;
70 
71 	request = lasso_is_interaction_request_new();
72 	lasso_node_init_from_message((LassoNode*)request, msg);
73 	LASSO_WSF_PROFILE(service)->request = LASSO_NODE(request);
74 
75 	return 0;
76 }
77 
78 gint
lasso_interaction_profile_service_process_response_msg(LassoInteractionProfileService * service,const gchar * msg)79 lasso_interaction_profile_service_process_response_msg(LassoInteractionProfileService *service,
80 		const gchar *msg)
81 {
82 	LassoIsInteractionResponse *response;
83 
84 	response = lasso_is_interaction_response_new();
85 	lasso_node_init_from_message((LassoNode*)response, msg);
86 	LASSO_WSF_PROFILE(service)->response = LASSO_NODE(response);
87 
88 	return 0;
89 }
90 
91 /**
92  * lasso_interaction_profile_service_build_redirect_response_msg:
93  * @profile: a #LassoWsfProfile
94  * @redirect_url: an #xmlChar string containing an HTTP url for interaction with the user
95  *
96  * The redirect_url must contain a way for the interaction service to link this interaction with the
97  * current request, usually it is the xml:id of the original request.
98  *
99  * Return value: 0 if successful, an error code otherwise.
100  */
101 gint
lasso_wsf_profile_init_interaction_service_redirect(LassoWsfProfile * profile,char * redirect_url)102 lasso_wsf_profile_init_interaction_service_redirect(LassoWsfProfile *profile, char *redirect_url)
103 {
104 	LassoSoapDetail *detail = NULL;
105 	LassoSoapFault *fault = NULL;
106 
107 	lasso_bad_param(WSF_PROFILE, profile);
108 
109 	detail = lasso_soap_detail_new();
110 	fault = lasso_soap_fault_new();
111 	lasso_assign_new_gobject(fault->Detail, detail);
112 	lasso_assign_string(fault->faultcode, LASSO_SOAP_FAULT_CODE_SERVER);
113 	lasso_list_add_new_gobject(detail->any, lasso_is_redirect_request_new(redirect_url));
114 
115 	return lasso_wsf_profile_init_soap_response(profile, &fault->parent);
116 }
117 
118 
119 /*****************************************************************************/
120 /* private methods                                                           */
121 /*****************************************************************************/
122 
123 static LassoInteractionProfileServiceClass *parent_class = NULL;
124 
125 
126 /*****************************************************************************/
127 /* instance and class init functions                                         */
128 /*****************************************************************************/
129 
130 static void
class_init(LassoInteractionProfileServiceClass * klass,void * unused G_GNUC_UNUSED)131 class_init(LassoInteractionProfileServiceClass *klass, void *unused G_GNUC_UNUSED)
132 {
133 	parent_class = g_type_class_peek_parent(klass);
134 
135 }
136 
137 GType
lasso_interaction_profile_service_get_type()138 lasso_interaction_profile_service_get_type()
139 {
140 	static GType this_type = 0;
141 
142 	if (!this_type) {
143 		static const GTypeInfo this_info = {
144 			sizeof(LassoInteractionProfileServiceClass),
145 			NULL,
146 			NULL,
147 			(GClassInitFunc) class_init,
148 			NULL,
149 			NULL,
150 			sizeof(LassoInteractionProfileService),
151 			0,
152 			NULL,
153 			NULL
154 		};
155 
156 		this_type = g_type_register_static(LASSO_TYPE_WSF_PROFILE,
157 				"LassoInteractionProfileService", &this_info, 0);
158 	}
159 	return this_type;
160 }
161 
162 LassoInteractionProfileService*
lasso_interaction_profile_service_new(LassoServer * server)163 lasso_interaction_profile_service_new(LassoServer *server)
164 {
165 	LassoInteractionProfileService *service = NULL;
166 
167 	g_return_val_if_fail(LASSO_IS_SERVER(server), NULL);
168 
169 	service = g_object_new(LASSO_TYPE_INTERACTION_PROFILE_SERVICE, NULL);
170 
171 	return service;
172 }
173