merge some cpas changes in for the PXML.[ch] fields
[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   SEARCHPATH_PRE
215   {
216
217     // do it
218     strncat ( buffer, "/", FILENAME_MAX );
219     strncat ( buffer, pnd_pxml_get_unique_id ( h ), FILENAME_MAX );
220     strncat ( buffer, ".xml", FILENAME_MAX );
221     //printf ( "  Path to seek merges: '%s'\n", buffer );
222
223     mergeh = pnd_pxml_fetch ( buffer );
224
225     if ( mergeh ) {
226
227       if ( pnd_pxml_get_app_name_en ( mergeh ) ) {
228         pnd_pxml_set_app_name ( h, pnd_pxml_get_app_name_en ( mergeh ) );
229       }
230
231       pnd_pxml_delete ( mergeh );
232     }
233
234   }
235   SEARCHPATH_POST
236
237   return ( retval );
238 }
239
240 char *pnd_pxml_get_app_name_en ( pnd_pxml_handle h ) {
241   pnd_pxml_t *p = (pnd_pxml_t*) h;
242   return ( p -> title_en );
243 }
244
245 char *pnd_pxml_get_app_name_de ( pnd_pxml_handle h ) {
246   pnd_pxml_t *p = (pnd_pxml_t*) h;
247   return ( p -> title_de );
248 }
249
250 char *pnd_pxml_get_app_name_it ( pnd_pxml_handle h ) {
251   pnd_pxml_t *p = (pnd_pxml_t*) h;
252   return ( p -> title_it );
253 }
254
255 char *pnd_pxml_get_app_name_fr ( pnd_pxml_handle h ) {
256   pnd_pxml_t *p = (pnd_pxml_t*) h;
257   return ( p -> title_fr );
258 }
259
260 char *pnd_pxml_get_unique_id ( pnd_pxml_handle h ) {
261   pnd_pxml_t *p = (pnd_pxml_t*) h;
262   return ( p -> unique_id );
263 }
264
265 char *pnd_pxml_get_standalone ( pnd_pxml_handle h ) {
266   pnd_pxml_t *p = (pnd_pxml_t*) h;
267   return ( p -> standalone );
268 }
269
270 char *pnd_pxml_get_icon ( pnd_pxml_handle h ) {
271   pnd_pxml_t *p = (pnd_pxml_t*) h;
272   return ( p -> icon );
273 }
274
275 char *pnd_pxml_get_description_en ( pnd_pxml_handle h ) {
276   pnd_pxml_t *p = (pnd_pxml_t*) h;
277   return ( p -> description_en );
278 }
279
280 char *pnd_pxml_get_description_de ( pnd_pxml_handle h ) {
281   pnd_pxml_t *p = (pnd_pxml_t*) h;
282   return ( p -> description_de );
283 }
284
285 char *pnd_pxml_get_description_it ( pnd_pxml_handle h ) {
286   pnd_pxml_t *p = (pnd_pxml_t*) h;
287   return ( p -> description_it );
288 }
289
290 char *pnd_pxml_get_description_fr ( pnd_pxml_handle h ) {
291   pnd_pxml_t *p = (pnd_pxml_t*) h;
292   return ( p -> description_fr );
293 }
294
295 char *pnd_pxml_get_previewpic1 ( pnd_pxml_handle h ) {
296   pnd_pxml_t *p = (pnd_pxml_t*) h;
297   return ( p -> previewpic1 );
298 }
299
300 char *pnd_pxml_get_previewpic2 ( pnd_pxml_handle h ) {
301   pnd_pxml_t *p = (pnd_pxml_t*) h;
302   return ( p -> previewpic2 );
303 }
304
305 char *pnd_pxml_get_author_name ( pnd_pxml_handle h ) {
306   pnd_pxml_t *p = (pnd_pxml_t*) h;
307   return ( p -> author_name );
308 }
309
310 char *pnd_pxml_get_author_website ( pnd_pxml_handle h ) {
311   pnd_pxml_t *p = (pnd_pxml_t*) h;
312   return ( p -> author_website );
313 }
314
315 char *pnd_pxml_get_version_major ( pnd_pxml_handle h ) {
316   pnd_pxml_t *p = (pnd_pxml_t*) h;
317   return ( p -> version_major );
318 }
319
320 char *pnd_pxml_get_version_minor ( pnd_pxml_handle h ) {
321   pnd_pxml_t *p = (pnd_pxml_t*) h;
322   return ( p -> version_minor );
323 }
324
325 char *pnd_pxml_get_version_release ( pnd_pxml_handle h ) {
326   pnd_pxml_t *p = (pnd_pxml_t*) h;
327   return ( p -> version_release );
328 }
329
330 char *pnd_pxml_get_version_build ( pnd_pxml_handle h ) {
331   pnd_pxml_t *p = (pnd_pxml_t*) h;
332   return ( p -> version_build );
333 }
334
335 char *pnd_pxml_get_exec ( pnd_pxml_handle h ) {
336   pnd_pxml_t *p = (pnd_pxml_t*) h;
337   return ( p -> exec );
338 }
339
340 char *pnd_pxml_get_main_category ( pnd_pxml_handle h ) {
341   pnd_pxml_t *p = (pnd_pxml_t*) h;
342   return ( p -> main_category );
343 }
344
345 char *pnd_pxml_get_subcategory1 ( pnd_pxml_handle h ) {
346   pnd_pxml_t *p = (pnd_pxml_t*) h;
347   return ( p -> subcategory1 );
348 }
349
350 char *pnd_pxml_get_subcategory2 ( pnd_pxml_handle h ) {
351   pnd_pxml_t *p = (pnd_pxml_t*) h;
352   return ( p -> subcategory2 );
353 }
354
355 char *pnd_pxml_get_altcategory ( pnd_pxml_handle h ) {
356   pnd_pxml_t *p = (pnd_pxml_t*) h;
357   return ( p -> altcategory );
358 }
359
360 char *pnd_pxml_get_altsubcategory1 ( pnd_pxml_handle h ) {
361   pnd_pxml_t *p = (pnd_pxml_t*) h;
362   return ( p -> altsubcategory1 );
363 }
364
365 char *pnd_pxml_get_altsubcategory2 ( pnd_pxml_handle h ) {
366   pnd_pxml_t *p = (pnd_pxml_t*) h;
367   return ( p -> altsubcategory2 );
368 }
369
370 char *pnd_pxml_get_osversion_major ( pnd_pxml_handle h ) {
371   pnd_pxml_t *p = (pnd_pxml_t*) h;
372   return ( p -> osversion_major );
373 }
374
375 char *pnd_pxml_get_osversion_minor ( pnd_pxml_handle h ) {
376   pnd_pxml_t *p = (pnd_pxml_t*) h;
377   return ( p -> osversion_minor );
378 }
379
380 char *pnd_pxml_get_osversion_release ( pnd_pxml_handle h ) {
381   pnd_pxml_t *p = (pnd_pxml_t*) h;
382   return ( p -> osversion_release );
383 }
384
385 char *pnd_pxml_get_osversion_build ( pnd_pxml_handle h ) {
386   pnd_pxml_t *p = (pnd_pxml_t*) h;
387   return ( p -> osversion_build );
388 }
389
390 char *pnd_pxml_get_associationitem1_name ( pnd_pxml_handle h ) {
391   pnd_pxml_t *p = (pnd_pxml_t*) h;
392   return ( p -> associationitem1_name );
393 }
394
395 char *pnd_pxml_get_associationitem1_filetype ( pnd_pxml_handle h ) {
396   pnd_pxml_t *p = (pnd_pxml_t*) h;
397   return ( p -> associationitem1_filetype );
398 }
399
400 char *pnd_pxml_get_associationitem1_parameter ( pnd_pxml_handle h ) {
401   pnd_pxml_t *p = (pnd_pxml_t*) h;
402   return ( p -> associationitem1_parameter );
403 }
404
405 char *pnd_pxml_get_associationitem2_name ( pnd_pxml_handle h ) {
406   pnd_pxml_t *p = (pnd_pxml_t*) h;
407   return ( p -> associationitem2_name );
408 }
409
410 char *pnd_pxml_get_associationitem2_filetype ( pnd_pxml_handle h ) {
411   pnd_pxml_t *p = (pnd_pxml_t*) h;
412   return ( p -> associationitem2_filetype );
413 }
414
415 char *pnd_pxml_get_associationitem2_parameter ( pnd_pxml_handle h ) {
416   pnd_pxml_t *p = (pnd_pxml_t*) h;
417   return ( p -> associationitem2_parameter );
418 }
419
420 char *pnd_pxml_get_associationitem3_name ( pnd_pxml_handle h ) {
421   pnd_pxml_t *p = (pnd_pxml_t*) h;
422   return ( p -> associationitem3_name );
423 }
424
425 char *pnd_pxml_get_associationitem3_filetype ( pnd_pxml_handle h ) {
426   pnd_pxml_t *p = (pnd_pxml_t*) h;
427   return ( p -> associationitem3_filetype );
428 }
429
430 char *pnd_pxml_get_associationitem3_parameter ( pnd_pxml_handle h ) {
431   pnd_pxml_t *p = (pnd_pxml_t*) h;
432   return ( p -> associationitem3_parameter );
433 }
434
435 char *pnd_pxml_get_clockspeed ( pnd_pxml_handle h ) {
436   pnd_pxml_t *p = (pnd_pxml_t*) h;
437   return ( p -> clockspeed );
438 }
439
440 char *pnd_pxml_get_background ( pnd_pxml_handle h ) {
441   pnd_pxml_t *p = (pnd_pxml_t*) h;
442   return ( p -> background );
443 }
444
445 char *pnd_pxml_get_startdir ( pnd_pxml_handle h ) {
446   pnd_pxml_t *p = (pnd_pxml_t*) h;
447   return ( p -> startdir );
448 }