pndnotifyd: fix some crashes
[pandora-libraries.git] / apps / pndvalidator.c
1
2 /* pndvalidator - a really dumb little tool to check a given PXML-app or pnd-app for 'compliance'.
3  * The "PXML spec" is not hard-defined so hopefull yover time this tool will prove useful, if it is
4  * updated to be 'tough enough' on PXML/pnd's and people actually use it
5  */
6
7 #include <stdio.h>     // for stdio
8 #include <string.h>    // for strcmp
9 #include "pnd_conf.h"
10 #include "pnd_apps.h"
11 #include "pnd_pxml.h"
12 #include "pnd_utility.h"
13
14 int main ( int argc, char *argv[] ) {
15   char *fullpath = NULL;
16   unsigned char do_override = 0;
17   unsigned char do_assets = 0;
18
19   if ( argc <= 1 ) {
20     printf ( "usage: %s [options] path-to-file\n", argv [ 0 ] );
21     printf ( "\n" );
22     printf ( "path-to-file\tCan refer to a PXML.xml in a subdir, or can refer to a .pnd-style application bundle\n" );
23     printf ( "\n" );
24     printf ( "Options:\n" );
25     printf ( "\t-a\tattempt to mount and verify assets (executable, icon, screenshots, etc) are present\n" );
26     printf ( "\t-m\tattempt to merge in PXML-overrides and validate against the result\n" );
27     printf ( "\n" );
28     printf ( "By default, the validator will only pick up the PXML and perform checks on field content.\n" );
29     return ( 0 );
30   }
31
32   unsigned char i = 1;
33
34   while ( i < argc ) {
35
36     if ( strncmp ( argv [ i ], "-m", 2 ) == 0 ) {
37       do_override = 1;
38     } else if ( strncmp ( argv [ i ], "-a", 2 ) == 0 ) {
39       do_assets = 1;
40     } else {
41       fullpath = argv [ i ];
42     }
43
44     i++;
45
46   } // while
47
48   // summarize
49
50   if ( do_assets ) {
51     printf ( "Note: Will attempt to examine application assets\n" );
52   }
53
54   if ( do_override ) {
55     printf ( "Note: Will merge PXML-overrides if found (not an error if not found.)\n" );
56   }
57
58   if ( ! fullpath ) {
59     printf ( "ERROR: No path provided.\n" );
60     return ( 0 );
61   }
62
63   printf ( "Path to examine: %s\n", fullpath );
64
65   printf ( "\n" );
66
67   //
68   // actually do useful work
69   //
70
71   pnd_pxml_handle *pxmlapps;
72
73   pxmlapps = pnd_pxml_get_by_path ( fullpath );
74
75   if ( ! pxmlapps ) {
76     printf ( "ERROR: PXML could not be extracted meaningfully.\n" );
77     return ( 0 );
78   }
79
80   printf ( "Got back a meaningful list of PXMLs.\n" );
81
82   unsigned int appiter = 0;
83   while ( 1 ) {
84
85     pnd_pxml_handle h = pxmlapps [ appiter ];
86
87     if ( ! h ) {
88       break;
89     }
90
91     // if you want to just go direct to struct - not wise!
92     //pnd_pxml_t *p = pxmlapps [ appiter ];
93     //printf ( "uid %s\n", p -> unique_id );
94
95     /* check the content
96      */
97     printf ( "Found name: '%s'\n", pnd_pxml_get_app_name_en ( h ) );
98
99     // check for required fields
100
101     // exec-path?
102
103     // app name?
104
105     // unique ID
106
107     // package-name (shortname)
108
109     // free up that particular pxml_handle within the return-list
110
111     // next
112     appiter++;
113   } // while
114
115   /* done!
116    */
117
118   return ( 0 );
119 }