1 /* |
|
2 * ============================================================================ |
|
3 * Name : isogetsearchkeys.c |
|
4 * Part of : isolation server. |
|
5 * Version : %version: 7 % |
|
6 * |
|
7 * Copyright © 2007-2008 Nokia. All rights reserved. |
|
8 * Redistribution and use in source and binary forms, with or without modification, |
|
9 * are permitted provided that the following conditions are met: |
|
10 * Redistributions of source code must retain the above copyright notice, this list |
|
11 * of conditions and the following disclaimer.Redistributions in binary form must |
|
12 * reproduce the above copyright notice, this list of conditions and the following |
|
13 * disclaimer in the documentation and/or other materials provided with the distribution. |
|
14 * Neither the name of the Nokia Corporation nor the names of its contributors may be used |
|
15 * to endorse or promote products derived from this software without specific prior written |
|
16 * permission. |
|
17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY |
|
18 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
|
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT |
|
20 * SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
|
21 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT |
|
22 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
|
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
|
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, |
|
25 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|
26 * ============================================================================ |
|
27 * Template version: 1.0 |
|
28 */ |
|
29 |
|
30 /*! \file |
|
31 * Impliments the functions in isosearch.h |
|
32 */ |
|
33 |
|
34 /*! \def For malloc |
|
35 */ |
|
36 #include <stdlib.h> |
|
37 |
|
38 /*! \def For string operations |
|
39 */ |
|
40 #include <string.h> |
|
41 |
|
42 |
|
43 /*! \def For search related declarations |
|
44 */ |
|
45 #include "isosearch.h" |
|
46 |
|
47 /*! \def For globalCon |
|
48 */ |
|
49 #include "isoservermain.h" |
|
50 |
|
51 /*! \def For tp_chan_type_search_async |
|
52 */ |
|
53 #include "tp-chan-type-search-gen.h" |
|
54 |
|
55 /*! \def For MSG_PRI_NORMAL |
|
56 */ |
|
57 #include "msgqlib.h" |
|
58 |
|
59 /*! \def For message_hdr_req |
|
60 */ |
|
61 #include "isoutils.h" |
|
62 |
|
63 /*! \def For RESPONSE_QUEUE |
|
64 */ |
|
65 #include "msgliterals.h" |
|
66 |
|
67 #include "isogetsearchkeys.h" |
|
68 |
|
69 /*! \struct key_value_struct isoserach.h |
|
70 * \brief This struct is used for to form the msg buffer that will be sent to client |
|
71 * \var msg As the key/value pairs are read those will be appended to msg |
|
72 * \var len is the no. of bytes appended to msg |
|
73 */ |
|
74 struct key_value_struct |
|
75 { |
|
76 gchar* msg; |
|
77 gint len; |
|
78 }; |
|
79 |
|
80 /*! \typedef struct key_value_struct to key_value_struct |
|
81 */ |
|
82 typedef struct key_value_struct key_value_struct; |
|
83 |
|
84 /*! \struct get_search_keys_cb_struct isosearch.h |
|
85 * \brief This struct bundles multiple(two ?) pointers to be passed |
|
86 * to getsearch keys callback |
|
87 * \var search_chan which should be closed when search keys are recieved |
|
88 * \var hdr_req message header request |
|
89 */ |
|
90 struct get_search_keys_cb_struct |
|
91 { |
|
92 TpChan* search_chan; |
|
93 message_hdr_req* hdr_req; |
|
94 }; |
|
95 |
|
96 /*! \typedef struct get_search_keys_cb_struct to get_search_keys_cb_struct |
|
97 */ |
|
98 typedef struct get_search_keys_cb_struct get_search_keys_cb_struct; |
|
99 |
|
100 |
|
101 static void getsearchkeys_cb( DBusGProxy *proxy, gchar *instr, |
|
102 gchar **keys, GError *error, gpointer userdata ); |
|
103 |
|
104 /*! \brief get_search_keys_reply is called as a callback to get_search_keys |
|
105 * This function creates a new channel and requests telepathy for the |
|
106 * search keys |
|
107 * |
|
108 * \param userdata message header request |
|
109 * |
|
110 * \remark calling tp_conn_new_channel results into esock_client 8 panic |
|
111 * Instead of calling function tp_conn_new_channel which makes a |
|
112 * a call to tp_conn_request_channel, tp_conn_request_channel_async is |
|
113 * called directly. |
|
114 */ |
|
115 |
|
116 static void get_search_keys_reply( DBusGProxy *proxy, char *chan_object_path, |
|
117 GError *error, gpointer user_data ) |
|
118 { |
|
119 |
|
120 |
|
121 TpChan *search_chan = NULL; |
|
122 DBusGProxy *search_iface = NULL; |
|
123 get_search_keys_cb_struct* chan_struct = NULL; |
|
124 message_hdr_resp* hdr_req = ( message_hdr_resp* )user_data; |
|
125 |
|
126 UNUSED_FORMAL_PARAM( proxy ); |
|
127 iso_logger( "in get_search_keys" ); |
|
128 |
|
129 if ( error ) |
|
130 { |
|
131 send_response_to_client( (message_hdr_req*)hdr_req, error->code, 0 ); |
|
132 free ( hdr_req ); |
|
133 return; |
|
134 } |
|
135 |
|
136 //Create new channel for the search |
|
137 search_chan = tp_chan_new( globalCon.dbusConn, globalCon.connmgr_bus, chan_object_path, |
|
138 TP_IFACE_CHANNEL_TYPE_CONTACT_SEARCH, TP_CONN_HANDLE_TYPE_NONE, 0 ); |
|
139 |
|
140 |
|
141 if ( NULL == search_chan ) |
|
142 { |
|
143 free ( hdr_req ); |
|
144 return ; |
|
145 } |
|
146 //Get chan interface |
|
147 search_iface = tp_chan_get_interface( search_chan, |
|
148 TELEPATHY_CHAN_IFACE_CONTACTSEARCH_QUARK ); |
|
149 |
|
150 if ( NULL == search_iface ) |
|
151 { |
|
152 tp_chan_close_async( DBUS_G_PROXY( search_chan ), |
|
153 search_chan_closed_cb, NULL ); |
|
154 free ( hdr_req ); |
|
155 return ; |
|
156 } |
|
157 |
|
158 chan_struct = ( get_search_keys_cb_struct* ) malloc ( |
|
159 sizeof ( get_search_keys_cb_struct ) ); |
|
160 |
|
161 chan_struct->search_chan = search_chan; |
|
162 chan_struct->hdr_req = ( message_hdr_req* ) malloc ( |
|
163 sizeof( message_hdr_req ) ); |
|
164 if ( NULL == chan_struct->hdr_req ) |
|
165 { |
|
166 tp_chan_close_async( DBUS_G_PROXY( search_chan ), |
|
167 search_chan_closed_cb, NULL ); |
|
168 free ( hdr_req ); |
|
169 return ; |
|
170 } |
|
171 //memset( chan_struct->hdr_req, ) |
|
172 memcpy( chan_struct->hdr_req, hdr_req, sizeof( message_hdr_req ) ); |
|
173 |
|
174 |
|
175 //Ownership of search_chan and chan_struct->hdr_req, |
|
176 //chan_struct is passed to getsearchkeys_cb |
|
177 free ( hdr_req ); |
|
178 |
|
179 tp_chan_type_search_get_search_keys_async( search_iface, |
|
180 getsearchkeys_cb, chan_struct ); |
|
181 |
|
182 iso_logger( "out get_search_keys" ); |
|
183 |
|
184 |
|
185 } |
|
186 |
|
187 /*! \brief Function to get the search keys(fields on which to |
|
188 * search ) supported by server |
|
189 * |
|
190 * \param hdr_req message header request |
|
191 * |
|
192 * \return gint MEM_ALLOCATION_ERROR |
|
193 */ |
|
194 gint get_search_keys( message_hdr_resp* hdr_req ) |
|
195 { |
|
196 |
|
197 message_hdr_resp* hdr_resp = ( message_hdr_resp* ) |
|
198 malloc ( sizeof ( message_hdr_resp ) ); |
|
199 |
|
200 if ( NULL == hdr_resp ) |
|
201 { |
|
202 return MEM_ALLOCATION_ERROR; |
|
203 } |
|
204 |
|
205 memcpy( hdr_resp, hdr_req, sizeof ( message_hdr_resp ) ); |
|
206 //ownership hdr_resp transfered |
|
207 tp_conn_request_channel_async( DBUS_G_PROXY( globalCon.conn ), |
|
208 TP_IFACE_CHANNEL_TYPE_CONTACT_SEARCH, |
|
209 TP_CONN_HANDLE_TYPE_NONE, 0, TRUE, |
|
210 get_search_keys_reply, (gpointer)hdr_resp ) ; |
|
211 |
|
212 return 0; |
|
213 } |
|
214 |
|
215 |
|
216 /*! \brief This is a callback to get_search_keys. The search keys |
|
217 * are sent to the requested client |
|
218 * |
|
219 * \param proxy unused |
|
220 * \param instr instruction on search keys |
|
221 * \param keys 2D string array of search keys supported by server |
|
222 * \param error Error from server, if any |
|
223 * \param userdata get_search_keys_cb_struct |
|
224 */ |
|
225 |
|
226 static void getsearchkeys_cb( DBusGProxy *proxy, gchar *instr, |
|
227 gchar **keys, GError *error, gpointer userdata ) |
|
228 { |
|
229 |
|
230 get_search_keys_cb_struct * search_struct = ( |
|
231 get_search_keys_cb_struct* )userdata; |
|
232 |
|
233 message_hdr_resp hdr_resp; |
|
234 gchar* msg = NULL; |
|
235 gint i = 0; |
|
236 gint len = 0; |
|
237 |
|
238 gint pri = MSG_PRI_NORMAL; |
|
239 gint result = 0; |
|
240 gint timeout = NO_WAIT; |
|
241 gint err = 0; |
|
242 |
|
243 |
|
244 UNUSED_FORMAL_PARAM( proxy ); |
|
245 UNUSED_FORMAL_PARAM( instr ); |
|
246 iso_logger( "in getsearchkeys_cb" ); |
|
247 |
|
248 |
|
249 tp_chan_close_async( DBUS_G_PROXY( search_struct->search_chan ), |
|
250 search_chan_closed_cb, NULL ); |
|
251 |
|
252 if ( error ) |
|
253 { |
|
254 send_response_to_client( search_struct->hdr_req, error->code, 0 ); |
|
255 |
|
256 free ( search_struct->hdr_req ); |
|
257 free ( search_struct ); |
|
258 |
|
259 return; |
|
260 } |
|
261 |
|
262 //Create the response header to be sent to client |
|
263 //Copy the message header request |
|
264 hdr_resp.hdr_req.message_type = ESearch_Get_Keys; |
|
265 hdr_resp.hdr_req.protocol_id = search_struct->hdr_req->protocol_id; |
|
266 hdr_resp.hdr_req.request_id = search_struct->hdr_req->request_id; |
|
267 hdr_resp.hdr_req.session_id = search_struct->hdr_req->session_id; |
|
268 //set continue flag |
|
269 hdr_resp.continue_flag = 0; |
|
270 hdr_resp.error_type = 0; |
|
271 hdr_resp.response = 1; |
|
272 |
|
273 free ( search_struct->hdr_req ); |
|
274 free ( search_struct ); |
|
275 |
|
276 //Allocate memory for the message and set memory to '\0' |
|
277 msg = ( gchar* ) malloc ( MAX_PARAM_LEN ); |
|
278 if ( NULL == msg ) |
|
279 { |
|
280 iso_logger( "malloc error @ pairs.msg" ); |
|
281 return ; |
|
282 } |
|
283 memset( msg, '\0', MAX_PARAM_LEN ); |
|
284 len = 0; |
|
285 //Copy the response |
|
286 memcpy( msg, &hdr_resp, sizeof ( message_hdr_resp ) ); |
|
287 len += sizeof( message_hdr_resp ); |
|
288 |
|
289 |
|
290 iso_logger( "Get search keys : Keys are" ); |
|
291 |
|
292 while ( keys[i] ) |
|
293 { |
|
294 strcpy( msg + len, keys[i] ); |
|
295 iso_logger( "Key %d : %s", i, keys[i] ); |
|
296 len += strlen( keys[i] ) + 1; |
|
297 i++; |
|
298 } |
|
299 |
|
300 iso_logger( "Get search keys : Keys End" ); |
|
301 |
|
302 //End the message with a '\0' |
|
303 len++; |
|
304 msg[len] = '\0'; |
|
305 //Send the message to client |
|
306 result = MsgQSend( RESPONSE_QUEUE, msg, len, |
|
307 pri, timeout, &err ); |
|
308 |
|
309 |
|
310 |
|
311 if ( result ) |
|
312 { |
|
313 |
|
314 } |
|
315 |
|
316 iso_logger( "out getsearchkeys_cb" ); |
|
317 |
|
318 } |
|