From 51cbc6a30572ce4787ebfaf4bfbd0df992d522d0 Mon Sep 17 00:00:00 2001 From: skeezix Date: Mon, 23 Feb 2009 09:54:04 -0500 Subject: [PATCH] Syncing up before merging in cpasjuste changes in pxml --- Makefile | 1 + TODO.txt | 2 ++ include/pnd_discovery.h | 49 +++++------------------------------------ include/pnd_pndfiles.h | 16 ++++++++++++++ include/pnd_pxml.h | 3 +++ include/pnd_tinyxml.h | 16 ++++++++++++++ lib/pnd_discovery.c | 10 +++++++++ lib/pnd_pndfiles.c | 33 +++++++++++++++++++++++++++ lib/pnd_pxml.c | 20 ++++++++++++++--- lib/pnd_tinyxml.cpp | 47 ++++++++++++++++++++++++++++++++++----- 10 files changed, 145 insertions(+), 52 deletions(-) create mode 100644 include/pnd_tinyxml.h diff --git a/Makefile b/Makefile index 65721ce..f924fa2 100644 --- a/Makefile +++ b/Makefile @@ -13,6 +13,7 @@ RM = rm VPATH = lib test apps CFLAG_SO = -fPIC #-fPIC not always needed, but good to have CFLAGS = -Wall -I./include -g ${CFLAG_SO} +CXXFLAGS = -Wall -I./include -g ${CFLAG_SO} # code LIB = libpnd.a diff --git a/TODO.txt b/TODO.txt index 58ebe01..77245c3 100644 --- a/TODO.txt +++ b/TODO.txt @@ -3,6 +3,8 @@ Some things to be done.. - review pnd_tinyxml to ensure the PXML_FILENAME is csae insensitive as needed +- make pnd_pndfiles seek of PXML more efficient; fread ( 1, nmemb ) gotta be slow :) + apps/pndnotifyd.c:// TODO: Catch HUP and reparse config apps/pndnotifyd.c:// TODO: Should perhaps direct all printf's through a vsprintf handler to avoid redundant "if ! g_daemon_mode" apps/pndnotifyd.c:// TODO: During daemon mode, should perhaps syslog or log errors diff --git a/include/pnd_discovery.h b/include/pnd_discovery.h index 2bb31ea..0943fae 100644 --- a/include/pnd_discovery.h +++ b/include/pnd_discovery.h @@ -36,49 +36,12 @@ pnd_box_handle pnd_disco_search ( char *searchpath, char *overridespath ); // fetch the full PXML and get all the details. But I think we got out of control here :) typedef struct { - char *title_en; - char *title_de; - char *title_it; - char *title_fr; - char *unique_id; - char *standalone; - char *icon; - char *description_en; - char *description_de; - char *description_it; - char *description_fr; - char *previewpic1; - char *previewpic2; - char *author_name; - char *author_website; - char *version_major; - char *version_minor; - char *version_release; - char *version_build; - char *exec; - char *main_category; - char *subcategory1; - char *subcategory2; - char *altcategory; - char *altsubcategory1; - char *altsubcategory2; - char *osversion_major; - char *osversion_minor; - char *osversion_release; - char *osversion_build; - char *associationitem1_name; - char *associationitem1_filetype; - char *associationitem1_parameter; - char *associationitem2_name; - char *associationitem2_filetype; - char *associationitem2_parameter; - char *associationitem3_name; - char *associationitem3_filetype; - char *associationitem3_parameter; - char *clockspeed; - char *background; - char *startdir; - + char *title_en; + char *unique_id; + char *icon; + char *exec; + char *main_category; + char *clockspeed; } pnd_disco_t; void pnd_disco_destroy ( pnd_disco_t *p ); // a function name that simply could not be avoided diff --git a/include/pnd_pndfiles.h b/include/pnd_pndfiles.h index c603f17..e141482 100644 --- a/include/pnd_pndfiles.h +++ b/include/pnd_pndfiles.h @@ -6,8 +6,24 @@ extern "C" { #endif +// the filename of PND files must end with a well defined (case insensitive!) extension #define PND_PACKAGE_FILEEXT ".pnd" /* case insensitive due to SD FAT fs */ +// when seeking the PXML appended (or embedded within if they forgot to append it) +// to a PND file, this buffer size will be used in the seek. It'll actually under-seek +// a bit, so in the odd chance the "" tag borders right on the window size, we'll +// still find it. +// Being SD reads, it might be nice to pick a decent size .. SD is constant read regardless +// of read size for certain sizes, but of course strstr() within a giant buffer is no good +// either if the goods are near the end. How big is an average .png for an average icon +// size? +#define PND_PXML_WINDOW_SIZE 4096 + +// pnd_seek_pxml should vaguely work like fseek, trying to position at begin of the appended/found PXML +// On return of 0, assuming nothing. +// On 1, assume that the FILE pointer is positioned for next read to pull in the PXML line by line +unsigned char pnd_pnd_seek_pxml ( FILE *f ); + #ifdef __cplusplus } /* "C" */ #endif diff --git a/include/pnd_pxml.h b/include/pnd_pxml.h index 4bca9b3..f8fbbbb 100644 --- a/include/pnd_pxml.h +++ b/include/pnd_pxml.h @@ -9,6 +9,8 @@ extern "C" { // this code is for very basic PXML.xml file parsing #define PXML_FILENAME "PXML.xml" /* a specification defined name */ +#define PXML_TAGHEAD "" /* case insensitive */ +#define PXML_TAGFOOT "" /* case insensitive */ // use this handle to interact with PXML; this hides the mechanics of parsing a PXML file so that // it can be upgraded with impacting applications @@ -17,6 +19,7 @@ typedef void* pnd_pxml_handle; /* pxml_fetch() will return NULL on fail, otherwise a valid handle which may be further queried */ pnd_pxml_handle pnd_pxml_fetch ( char *fullpath ); +pnd_pxml_handle pnd_pxml_fetch_buffer ( char *filename, char *buffer ); void pnd_pxml_delete ( pnd_pxml_handle h ); /* overrides() allow for customization of a PXML that persists; ie: An application might be sitting diff --git a/include/pnd_tinyxml.h b/include/pnd_tinyxml.h new file mode 100644 index 0000000..efa4371 --- /dev/null +++ b/include/pnd_tinyxml.h @@ -0,0 +1,16 @@ + +#ifndef h_pnd_tinyxml_h +#define h_pnd_tinyxml_h + +#ifdef __cplusplus +extern "C" { +#endif + +unsigned char pnd_pxml_load ( const char* pFilename, pnd_pxml_t *app ); +unsigned char pnd_pxml_parse ( const char *pFilename, char *buffer, unsigned int length, pnd_pxml_t *app ); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/lib/pnd_discovery.c b/lib/pnd_discovery.c index bfac709..01f4c9a 100644 --- a/lib/pnd_discovery.c +++ b/lib/pnd_discovery.c @@ -106,6 +106,12 @@ static int pnd_disco_callback ( const char *fpath, const struct stat *sb, } else if ( valid == 2 ) { // PND ... ?? + printf ( "PND: disco callback encountered '%s'\n", fpath ); + + // is this a valid .pnd file? The filename is a candidate already, but verify.. + // .. presence of PXML appeneded, or at least contained within? + // .. presence of an icon appended after PXML? + } return ( 0 ); // continue the tree walk @@ -188,17 +194,21 @@ unsigned char pnd_emit_dotdesktop ( char *targetpath, pnd_disco_t *p ) { fprintf ( f, "%s", buffer ); } +#if 0 if ( p -> description_en ) { snprintf ( buffer, 1020, "Comment=%s\n", p -> description_en ); fprintf ( f, "%s", buffer ); } +#endif +#if 0 if ( p -> startdir ) { snprintf ( buffer, 1020, "Path=%s\n", p -> startdir ); fprintf ( f, "%s", buffer ); } else { fprintf ( f, "Path=%s\n", PND_DEFAULT_WORKDIR ); } +#endif if ( p -> exec ) { snprintf ( buffer, 1020, "Exec=%s\n", p -> exec ); diff --git a/lib/pnd_pndfiles.c b/lib/pnd_pndfiles.c index 1bfaa80..2b5a542 100644 --- a/lib/pnd_pndfiles.c +++ b/lib/pnd_pndfiles.c @@ -7,3 +7,36 @@ #include "pnd_pxml.h" #include "pnd_apps.h" #include "pnd_pndfiles.h" + +unsigned char pnd_pnd_seek_pxml ( FILE *f ) { + char *b; + unsigned int len; + + b = malloc ( PND_PXML_WINDOW_SIZE ); + + if ( ! b ) { + return ( 0 ); + } + + memset ( b, '\0', PND_PXML_WINDOW_SIZE ); + + // determine length of file + fseek ( f, 0, SEEK_END ); + + len = ftell ( f ); + + fseek ( f, 0, SEEK_SET ); + + /* ready to scan through the file, backwards + */ + + //strcasestr ( b, PXML_TAGHEAD ); + + + + // exeunt, with alarums + + free ( b ); + + return ( 1 ); +} diff --git a/lib/pnd_pxml.c b/lib/pnd_pxml.c index 484c418..5471ff6 100644 --- a/lib/pnd_pxml.c +++ b/lib/pnd_pxml.c @@ -9,8 +9,7 @@ #include "pnd_pxml.h" #include "pnd_pathiter.h" - -void pnd_pxml_load(const char* pFilename, pnd_pxml_t *app); +#include "pnd_tinyxml.h" pnd_pxml_handle pnd_pxml_fetch ( char *fullpath ) { @@ -18,7 +17,22 @@ pnd_pxml_handle pnd_pxml_fetch ( char *fullpath ) { memset ( p, '\0', sizeof(pnd_pxml_t) ); - pnd_pxml_load ( fullpath, p ); + if ( ! pnd_pxml_load ( fullpath, p ) ) { + return ( 0 ); + } + + return ( p ); +} + +pnd_pxml_handle pnd_pxml_fetch_buffer ( char *filename, char *buffer ) { + + pnd_pxml_t *p = malloc ( sizeof(pnd_pxml_t) ); + + memset ( p, '\0', sizeof(pnd_pxml_t) ); + + if ( ! pnd_pxml_parse ( filename, buffer, strlen ( buffer ), p ) ) { + return ( 0 ); + } return ( p ); } diff --git a/lib/pnd_tinyxml.cpp b/lib/pnd_tinyxml.cpp index b2c97ac..68e8f94 100644 --- a/lib/pnd_tinyxml.cpp +++ b/lib/pnd_tinyxml.cpp @@ -1,20 +1,54 @@ + #include "tinyxml/tinyxml.h" #include "../include/pnd_pxml.h" +#include "pnd_tinyxml.h" extern "C" { -void pnd_pxml_load(const char* pFilename, pnd_pxml_t *app) -{ +unsigned char pnd_pxml_load ( const char* pFilename, pnd_pxml_t *app ) { + FILE *f; + char *b; + unsigned int len; + + f = fopen ( pFilename, "r" ); + + if ( ! f ) { + return ( 0 ); + } + + fseek ( f, 0, SEEK_END ); + + len = ftell ( f ); + + fseek ( f, 0, SEEK_SET ); + + b = (char*) malloc ( len ); + + if ( ! b ) { + fclose ( f ); + return ( 0 ); + } - TiXmlDocument doc(pFilename); - if (!doc.LoadFile()) return; + fread ( b, 1, len, f ); + + return ( pnd_pxml_parse ( pFilename, b, len, app ) ); +} + +unsigned char pnd_pxml_parse ( const char *pFilename, char *buffer, unsigned int length, pnd_pxml_t *app ) { + + //TiXmlDocument doc(pFilename); + //if (!doc.LoadFile()) return; + + TiXmlDocument doc; + + doc.Parse ( buffer ); TiXmlHandle hDoc(&doc); TiXmlElement* pElem; TiXmlHandle hRoot(0); pElem=hDoc.FirstChildElement().Element(); - if (!pElem) return; + if (!pElem) return ( 0 ); hRoot=TiXmlHandle(pElem); pElem = hRoot.FirstChild( "title" ).FirstChildElement("en").Element(); @@ -276,7 +310,8 @@ void pnd_pxml_load(const char* pFilename, pnd_pxml_t *app) { app->startdir = strdup(pElem->GetText()); } -} + return ( 1 ); } +} // extern C -- 2.39.2