1
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
3
* Linux Desktop Testing Project http://ldtp.freedesktop.org
6
* Veerapuram Varadhan <v.varadhan@gmail.com>
8
* Copyright 2004 - 2006 Novell, Inc.
10
* This program is free software; you can redistribute it and/or
11
* modify it under the terms of the GNU Lesser General Public
12
* License as published by the Free Software Foundation; either
13
* version 2 of the License, or (at your option) any later version.
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 GNU
18
* Lesser General Public License for more details.
20
* You should have received a copy of the GNU Lesser General Public
21
* License along with this program; if not, write to the
22
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
23
* Boston, MA 02110, USA.
27
#include <sys/types.h>
29
#include <libxml/parser.h>
31
#include "ldtp-request.h"
32
#include "ldtp-error.h"
33
#include "ldtp-logger.h"
35
/* Object initialization function for the ldtp request object */
37
ldtp_request_init (LDTPRequest* req)
39
req->request_type = 0;
40
req->application = NULL;
41
req->request_id = NULL;
43
req->action_name = NULL;
44
req->component = NULL;
48
/* Finalize handler for the ldtp request component object */
50
ldtp_request_free (LDTPRequest* req, int finalize)
55
g_slist_foreach (req->arg_list, (GFunc)g_free, NULL);
56
g_slist_free (req->arg_list);
60
req->request_type = 0;
63
g_free (req->context);
68
g_free (req->component);
69
req->component = NULL;
72
if (req->action_name) {
73
g_free (req->action_name);
74
req->action_name = NULL;
77
if (req->request_id) {
78
g_free (req->request_id);
79
req->request_id = NULL;
85
* ldtp_request_component_new_from_string:
87
* Creates a new ldtp request component object from request-packet.
89
* Return value: A newly-created ldtp request component object.
92
ldtp_request_fill_request (LDTPRequest* req, gchar* packet, size_t len, LDTPErrorCode* err)
96
xmlNodePtr node = NULL;
98
if (!req || !packet || len <= 0) {
99
*err = LDTP_ERROR_ARGUMENT_NULL;
103
doc = xmlParseMemory (packet, len);
105
ldtp_log ("Unable to parse XML in memory\n");
108
node = xmlDocGetRootElement (doc);
110
ldtp_log ("Empty request\n");
114
/* First level we expect GUI object attributes*/
115
node = node->xmlChildrenNode;
116
while (node && xmlIsBlankNode (node)) {
123
/* Free the previous contents */
124
ldtp_request_free (req, 0);
126
/* read the attributes */
127
for (;node != NULL; node = node->next) {
128
if (!node || !node->name)
130
/* Read action name*/
131
g_print ("Node: %s\n", node->name);
132
if(!xmlStrcmp (node->name, (const xmlChar *) "SCRIPT") ){
133
if (doc && node->xmlChildrenNode) {
134
req->request_type = LDTP_SCRIPT;
136
node = node -> xmlChildrenNode;
138
if(!xmlStrcmp (node->name, (const xmlChar *) "APPLICATION") ){
139
if (doc && node->xmlChildrenNode) {
140
tmp = xmlNodeListGetString (doc, node->xmlChildrenNode, 1);
142
req->application = g_strdup ((char *)tmp);
146
req->application = NULL;
151
if (!xmlStrcmp (node->name, (const xmlChar *) "ID")) {
152
if (doc && node->xmlChildrenNode) {
153
tmp = xmlNodeListGetString (doc,
154
node->xmlChildrenNode, 1);
156
req->request_id = g_strdup ((char *)tmp);
160
req->request_id = NULL;
162
g_print ("request_id: %s\n", req->request_id);
165
if (!xmlStrcmp (node->name, (const xmlChar *) "ACTION")) {
166
if (doc && node->xmlChildrenNode) {
167
tmp = xmlNodeListGetString (doc,
168
node->xmlChildrenNode, 1);
170
req->action_name = g_strdup ((char *)tmp);
174
req->action_name = NULL;
175
if (req->action_name)
176
g_print ("action_name: %s\n", req->action_name);
179
if (!xmlStrcmp (node->name, (const xmlChar *) "CONTEXT")) {
180
if (doc && node->xmlChildrenNode) {
181
tmp = xmlNodeListGetString (doc,
182
node->xmlChildrenNode, 1);
184
req->context = g_strdup ((char *)tmp);
190
g_print ("Window name: %s\n", req->context);
193
if (!xmlStrcmp (node->name, (const xmlChar *) "COMPONENT")) {
194
if (doc && node->xmlChildrenNode) {
195
tmp = xmlNodeListGetString (doc,
196
node->xmlChildrenNode, 1);
198
req->component = g_strdup ((char *)tmp);
202
req->component = NULL;
204
g_print ("Component name: %s\n", req->component);
207
if (!xmlStrcmp (node->name, (const xmlChar *) "ARGUMENTS")) {
208
/* next level is a list of arguments */
209
node = node->xmlChildrenNode;
210
g_print ("Has children\n");
213
If ARGUMENTS does not have any children, then the node will be empty
214
and node will be NULL. So its better to break the loop
215
NOTE: A better way to do this is, to have a seperate for loop to iterate
216
children of ARGUMENTS
221
if (!xmlStrcmp (node->name, (const xmlChar *) "ARGUMENT")) {
222
if (doc && node->xmlChildrenNode) {
223
tmp = (guchar *)xmlNodeListGetString (doc, node->xmlChildrenNode, 1);
225
req->arg_list = g_slist_prepend (req->arg_list,
226
(guchar *)g_strdup ((gchar *)tmp));
228
if (req->arg_list && req->arg_list->data)
229
g_print ("Argument value: %s\n", (char *)req->arg_list->data);
235
if (!req->request_id)
238
/* Reverse the argument list to get the
239
desired order of arguments.
241
req->arg_list = g_slist_reverse (req->arg_list);
242
*err = LDTP_ERROR_SUCCESS;
246
*err = LDTP_ERROR_PACKET_INVALID;
247
ldtp_request_free (req, 0);