78c41e7a1011faf905ebd0b5f62636860118923c
[pandora-libraries.git] / lib / pnd_pxml.c
1
2 #include <stdio.h> /* for FILE */
3 #include <stdlib.h> /* for malloc */
4 #include <string.h> /* for string ops */
5
6 #include <sys/types.h> /* for stat */
7 #include <sys/stat.h> /* for stat */
8 #include <unistd.h> /* for stat */
9
10 #include "pnd_pxml.h"
11 #include "pnd_pathiter.h"
12 #include "pnd_tinyxml.h"
13
14 pnd_pxml_handle pnd_pxml_fetch ( char *fullpath ) {
15
16   pnd_pxml_t *p = malloc ( sizeof(pnd_pxml_t) );
17
18   memset ( p, '\0', sizeof(pnd_pxml_t) );
19
20   if ( ! pnd_pxml_load ( fullpath, p ) ) {
21     return ( 0 );
22   }
23
24   return ( p );
25 }
26
27 pnd_pxml_handle pnd_pxml_fetch_buffer ( char *filename, char *buffer ) {
28
29   pnd_pxml_t *p = malloc ( sizeof(pnd_pxml_t) );
30
31   memset ( p, '\0', sizeof(pnd_pxml_t) );
32
33   if ( ! pnd_pxml_parse ( filename, buffer, strlen ( buffer ), p ) ) {
34     return ( 0 );
35   }
36
37   return ( p );
38 }
39
40 void pnd_pxml_delete ( pnd_pxml_handle h ) {
41   pnd_pxml_t *p = (pnd_pxml_t*) h;
42
43   if ( p -> title_en ) {
44     free ( p -> title_en );
45   }
46   if ( p -> title_de ) {
47     free ( p -> title_de );
48   }
49   if ( p -> title_it ) {
50     free ( p -> title_it );
51   }
52   if ( p -> title_fr ) {
53     free ( p -> title_fr );
54   }
55   if ( p -> unique_id ) {
56     free ( p -> unique_id );
57   }
58   if ( p -> standalone ) {
59     free ( p -> standalone );
60   }
61   if ( p -> icon ) {
62     free ( p -> icon );
63   }
64   if ( p -> description_en ) {
65     free ( p -> description_en );
66   }
67   if ( p -> description_de ) {
68     free ( p -> description_de );
69   }
70   if ( p -> description_it ) {
71     free ( p -> description_it );
72   }
73   if ( p -> description_fr ) {
74     free ( p -> description_fr );
75   }
76   if ( p -> previewpic1 ) {
77     free ( p -> previewpic1 );
78   }
79   if ( p -> previewpic2 ) {
80     free ( p -> previewpic2 );
81   }
82   if ( p -> author_name ) {
83     free ( p -> author_name );
84   }
85   if ( p -> author_website ) {
86     free ( p -> author_website );
87   }
88   if ( p -> version_major ) {
89     free ( p -> version_major );
90   }
91   if ( p -> version_minor ) {
92     free ( p -> version_minor );
93   }
94   if ( p -> version_release ) {
95     free ( p -> version_release );
96   }
97   if ( p -> version_build ) {
98     free ( p -> version_build );
99   }
100   if ( p -> exec ) {
101     free ( p -> exec );
102   }
103   if ( p -> main_category ) {
104     free ( p -> main_category );
105   }
106   if ( p -> subcategory1 ) {
107     free ( p -> subcategory1 );
108   }
109   if ( p -> subcategory2 ) {
110     free ( p -> subcategory2 );
111   }
112   if ( p -> altcategory ) {
113     free ( p -> altcategory );
114   }
115   if ( p -> altsubcategory1 ) {
116     free ( p -> altsubcategory1 );
117   }
118   if ( p -> altsubcategory2 ) {
119     free ( p -> altsubcategory2 );
120   }
121   if ( p -> osversion_major ) {
122     free ( p -> osversion_major );
123   }
124   if ( p -> osversion_minor ) {
125     free ( p -> osversion_minor );
126   }
127   if ( p -> osversion_release ) {
128     free ( p -> osversion_release );
129   }
130   if ( p -> osversion_build ) {
131     free ( p -> osversion_build );
132   }
133   if ( p -> associationitem1_name ) {
134     free ( p -> associationitem1_name );
135   }
136   if ( p -> associationitem1_filetype ) {
137     free ( p -> associationitem1_filetype );
138   }
139   if ( p -> associationitem1_parameter ) {
140     free ( p -> associationitem1_parameter );
141   }
142   if ( p -> associationitem2_name ) {
143     free ( p -> associationitem2_name );
144   }
145   if ( p -> associationitem2_filetype ) {
146     free ( p -> associationitem2_filetype );
147   }
148   if ( p -> associationitem2_parameter ) {
149     free ( p -> associationitem2_parameter );
150   }
151   if ( p -> associationitem3_name ) {
152     free ( p -> associationitem3_name );
153   }
154   if ( p -> associationitem1_filetype ) {
155     free ( p -> associationitem3_filetype );
156   }
157   if ( p -> associationitem1_parameter ) {
158     free ( p -> associationitem3_parameter );
159   }
160   if ( p -> clockspeed ) {
161     free ( p -> clockspeed );
162   }
163   if ( p -> background ) {
164     free ( p -> background );
165   }
166   if ( p -> startdir ) {
167     free ( p -> startdir );
168   }
169
170   return;
171 }
172
173 void pnd_pxml_set_app_name ( pnd_pxml_handle h, char *v ) {
174   pnd_pxml_t *p = (pnd_pxml_t*) h;
175   if ( p -> title_en ) {
176     free ( p -> title_en );
177     p -> title_en = NULL;
178   }
179
180   if ( v ) {
181     p -> title_en = strdup ( v );
182   }
183
184   return;
185 }
186
187 unsigned char pnd_is_pxml_valid_app ( pnd_pxml_handle h ) {
188   pnd_pxml_t *p = (pnd_pxml_t*) h;
189
190   // for now, lets just verify the exec-path is valid
191
192   //printf ( "exec is '%s'\n", p -> exec );
193
194   return ( 1 );
195
196   // even this is complicated by pnd_run.sh semantics .. can't check if it exists
197   // during discovery, since it is not mounted yet..
198 #if 0
199   struct stat buf;
200   if ( stat ( p -> exec, &buf ) == 0 ) {
201     return ( 1 ); // path is present
202   }
203 #endif
204
205   return ( 0 );
206 }
207
208 signed char pnd_pxml_merge_override ( pnd_pxml_handle h, char *searchpath ) {
209   // the pxml includes a unique-id; use this value to attempt to find an
210   // override in the given searchpath
211   signed char retval = 0;
212   pnd_pxml_handle mergeh;
213
214   if ( ! pnd_pxml_get_unique_id ( h ) ) {
215     return ( -1 ); // no unique-id present, so can't use it to name potential override files
216   }
217
218   SEARCHPATH_PRE
219   {
220
221     // do it
222     strncat ( buffer, "/", FILENAME_MAX );
223     strncat ( buffer, pnd_pxml_get_unique_id ( h ), FILENAME_MAX );
224     strncat ( buffer, ".xml", FILENAME_MAX );
225     //printf ( "  Path to seek merges: '%s'\n", buffer );
226
227     mergeh = pnd_pxml_fetch ( buffer );
228
229     if ( mergeh ) {
230
231       if ( pnd_pxml_get_app_name_en ( mergeh ) ) {
232         pnd_pxml_set_app_name ( h, pnd_pxml_get_app_name_en ( mergeh ) );
233       }
234
235       pnd_pxml_delete ( mergeh );
236     }
237
238   }
239   SEARCHPATH_POST
240
241   return ( retval );
242 }
243
244 char *pnd_pxml_get_app_name_en ( pnd_pxml_handle h ) {
245   pnd_pxml_t *p = (pnd_pxml_t*) h;
246   return ( p -> title_en );
247 }
248
249 char *pnd_pxml_get_app_name_de ( pnd_pxml_handle h ) {
250   pnd_pxml_t *p = (pnd_pxml_t*) h;
251   return ( p -> title_de );
252 }
253
254 char *pnd_pxml_get_app_name_it ( pnd_pxml_handle h ) {
255   pnd_pxml_t *p = (pnd_pxml_t*) h;
256   return ( p -> title_it );
257 }
258
259 char *pnd_pxml_get_app_name_fr ( pnd_pxml_handle h ) {
260   pnd_pxml_t *p = (pnd_pxml_t*) h;
261   return ( p -> title_fr );
262 }
263
264 char *pnd_pxml_get_unique_id ( pnd_pxml_handle h ) {
265   pnd_pxml_t *p = (pnd_pxml_t*) h;
266   return ( p -> unique_id );
267 }
268
269 char *pnd_pxml_get_standalone ( pnd_pxml_handle h ) {
270   pnd_pxml_t *p = (pnd_pxml_t*) h;
271   return ( p -> standalone );
272 }
273
274 char *pnd_pxml_get_icon ( pnd_pxml_handle h ) {
275   pnd_pxml_t *p = (pnd_pxml_t*) h;
276   return ( p -> icon );
277 }
278
279 char *pnd_pxml_get_description_en ( pnd_pxml_handle h ) {
280   pnd_pxml_t *p = (pnd_pxml_t*) h;
281   return ( p -> description_en );
282 }
283
284 char *pnd_pxml_get_description_de ( pnd_pxml_handle h ) {
285   pnd_pxml_t *p = (pnd_pxml_t*) h;
286   return ( p -> description_de );
287 }
288
289 char *pnd_pxml_get_description_it ( pnd_pxml_handle h ) {
290   pnd_pxml_t *p = (pnd_pxml_t*) h;
291   return ( p -> description_it );
292 }
293
294 char *pnd_pxml_get_description_fr ( pnd_pxml_handle h ) {
295   pnd_pxml_t *p = (pnd_pxml_t*) h;
296   return ( p -> description_fr );
297 }
298
299 char *pnd_pxml_get_previewpic1 ( pnd_pxml_handle h ) {
300   pnd_pxml_t *p = (pnd_pxml_t*) h;
301   return ( p -> previewpic1 );
302 }
303
304 char *pnd_pxml_get_previewpic2 ( pnd_pxml_handle h ) {
305   pnd_pxml_t *p = (pnd_pxml_t*) h;
306   return ( p -> previewpic2 );
307 }
308
309 char *pnd_pxml_get_author_name ( pnd_pxml_handle h ) {
310   pnd_pxml_t *p = (pnd_pxml_t*) h;
311   return ( p -> author_name );
312 }
313
314 char *pnd_pxml_get_author_website ( pnd_pxml_handle h ) {
315   pnd_pxml_t *p = (pnd_pxml_t*) h;
316   return ( p -> author_website );
317 }
318
319 char *pnd_pxml_get_version_major ( pnd_pxml_handle h ) {
320   pnd_pxml_t *p = (pnd_pxml_t*) h;
321   return ( p -> version_major );
322 }
323
324 char *pnd_pxml_get_version_minor ( pnd_pxml_handle h ) {
325   pnd_pxml_t *p = (pnd_pxml_t*) h;
326   return ( p -> version_minor );
327 }
328
329 char *pnd_pxml_get_version_release ( pnd_pxml_handle h ) {
330   pnd_pxml_t *p = (pnd_pxml_t*) h;
331   return ( p -> version_release );
332 }
333
334 char *pnd_pxml_get_version_build ( pnd_pxml_handle h ) {
335   pnd_pxml_t *p = (pnd_pxml_t*) h;
336   return ( p -> version_build );
337 }
338
339 char *pnd_pxml_get_exec ( pnd_pxml_handle h ) {
340   pnd_pxml_t *p = (pnd_pxml_t*) h;
341   return ( p -> exec );
342 }
343
344 char *pnd_pxml_get_main_category ( pnd_pxml_handle h ) {
345   pnd_pxml_t *p = (pnd_pxml_t*) h;
346   return ( p -> main_category );
347 }
348
349 char *pnd_pxml_get_subcategory1 ( pnd_pxml_handle h ) {
350   pnd_pxml_t *p = (pnd_pxml_t*) h;
351   return ( p -> subcategory1 );
352 }
353
354 char *pnd_pxml_get_subcategory2 ( pnd_pxml_handle h ) {
355   pnd_pxml_t *p = (pnd_pxml_t*) h;
356   return ( p -> subcategory2 );
357 }
358
359 char *pnd_pxml_get_altcategory ( pnd_pxml_handle h ) {
360   pnd_pxml_t *p = (pnd_pxml_t*) h;
361   return ( p -> altcategory );
362 }
363
364 char *pnd_pxml_get_altsubcategory1 ( pnd_pxml_handle h ) {
365   pnd_pxml_t *p = (pnd_pxml_t*) h;
366   return ( p -> altsubcategory1 );
367 }
368
369 char *pnd_pxml_get_altsubcategory2 ( pnd_pxml_handle h ) {
370   pnd_pxml_t *p = (pnd_pxml_t*) h;
371   return ( p -> altsubcategory2 );
372 }
373
374 char *pnd_pxml_get_osversion_major ( pnd_pxml_handle h ) {
375   pnd_pxml_t *p = (pnd_pxml_t*) h;
376   return ( p -> osversion_major );
377 }
378
379 char *pnd_pxml_get_osversion_minor ( pnd_pxml_handle h ) {
380   pnd_pxml_t *p = (pnd_pxml_t*) h;
381   return ( p -> osversion_minor );
382 }
383
384 char *pnd_pxml_get_osversion_release ( pnd_pxml_handle h ) {
385   pnd_pxml_t *p = (pnd_pxml_t*) h;
386   return ( p -> osversion_release );
387 }
388
389 char *pnd_pxml_get_osversion_build ( pnd_pxml_handle h ) {
390   pnd_pxml_t *p = (pnd_pxml_t*) h;
391   return ( p -> osversion_build );
392 }
393
394 char *pnd_pxml_get_associationitem1_name ( pnd_pxml_handle h ) {
395   pnd_pxml_t *p = (pnd_pxml_t*) h;
396   return ( p -> associationitem1_name );
397 }
398
399 char *pnd_pxml_get_associationitem1_filetype ( pnd_pxml_handle h ) {
400   pnd_pxml_t *p = (pnd_pxml_t*) h;
401   return ( p -> associationitem1_filetype );
402 }
403
404 char *pnd_pxml_get_associationitem1_parameter ( pnd_pxml_handle h ) {
405   pnd_pxml_t *p = (pnd_pxml_t*) h;
406   return ( p -> associationitem1_parameter );
407 }
408
409 char *pnd_pxml_get_associationitem2_name ( pnd_pxml_handle h ) {
410   pnd_pxml_t *p = (pnd_pxml_t*) h;
411   return ( p -> associationitem2_name );
412 }
413
414 char *pnd_pxml_get_associationitem2_filetype ( pnd_pxml_handle h ) {
415   pnd_pxml_t *p = (pnd_pxml_t*) h;
416   return ( p -> associationitem2_filetype );
417 }
418
419 char *pnd_pxml_get_associationitem2_parameter ( pnd_pxml_handle h ) {
420   pnd_pxml_t *p = (pnd_pxml_t*) h;
421   return ( p -> associationitem2_parameter );
422 }
423
424 char *pnd_pxml_get_associationitem3_name ( pnd_pxml_handle h ) {
425   pnd_pxml_t *p = (pnd_pxml_t*) h;
426   return ( p -> associationitem3_name );
427 }
428
429 char *pnd_pxml_get_associationitem3_filetype ( pnd_pxml_handle h ) {
430   pnd_pxml_t *p = (pnd_pxml_t*) h;
431   return ( p -> associationitem3_filetype );
432 }
433
434 char *pnd_pxml_get_associationitem3_parameter ( pnd_pxml_handle h ) {
435   pnd_pxml_t *p = (pnd_pxml_t*) h;
436   return ( p -> associationitem3_parameter );
437 }
438
439 char *pnd_pxml_get_clockspeed ( pnd_pxml_handle h ) {
440   pnd_pxml_t *p = (pnd_pxml_t*) h;
441   return ( p -> clockspeed );
442 }
443
444 char *pnd_pxml_get_background ( pnd_pxml_handle h ) {
445   pnd_pxml_t *p = (pnd_pxml_t*) h;
446   return ( p -> background );
447 }
448
449 char *pnd_pxml_get_startdir ( pnd_pxml_handle h ) {
450   pnd_pxml_t *p = (pnd_pxml_t*) h;
451   return ( p -> startdir );
452 }