contentLister/inc/erMdsContent.h File Reference

eReader Content Lister content and filesystem datatypes More...

#include <glib.h>

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  mdsSortStruct_t
struct  mdsFsItem_t
struct  clDisplayItem_t
struct  mdsDirectory_t
struct  mdsSelectionItem_t
struct  mdsSelection_t
struct  mdsSelectionList_t

Defines

#define OUTBOX_NAME   "outbox"
#define XMLNODE_SELECTION_LIST   "/package/metadata/selection-list"
#define SELECTION_TRANSFER_MODE   "transfer-mode"
#define ITEM_TRANSFER_MOVE   "move"
#define SELECTION_DOCUMENT_SIGNING   "document-signing"
#define ITEM_SIGN_YES   "sign"
#define ERMDS_MAX_FILENAME_SIZE   1024
#define ERMDS_MAX_EXTENSION_SIZE   5
#define ERMDS_MAX_SEARCH_STRING_SIZE   512
#define ERMDS_MAX_EXTENSION_ID_SIZE   128
#define ERMDS_MAX_SYMLINK_CHAIN   10
#define ERCL_MAX_TITLE_SIZE   512
#define ERCL_MAX_SUBTITLE_SIZE   512
#define ERCL_MAX_DESCRIPTION_SIZE   512
#define ERCL_MAX_FIELDNAME_SIZE   128
#define ERMDS_INITIAL_CONTENT_SCAN_ARRAY_SIZE   100
#define ERMDS_MAX_CONTENT_SCAN_ARRAY_SIZE   (1024-1)
#define ERMDS_CONTENT_SCAN_OK   0
#define ERMDS_CONTENT_SCAN_FAILED   -1
#define ERMDS_CONTENT_SCAN_TOO_MANY_ITEMS   -2
#define ERMDS_CONTENT_SORT_OK   0
#define ERMDS_CONTENT_SORT_FAILED   -1
#define ERMDS_CONTENT_SORT_NOT_IMPLEMENTED   -2
#define ERCL_OK   0
#define ERCL_INVALID_ARGS   -10
#define ERCL_NOMATCH   -11
#define ERCL_INVALID_SIZE   -1
#define MOBIPOCKET_FOLDER   "/books/Mobipocket"
#define MOBIPOCKET_FOLDER_LENGTH   17
#define MOBIPOCKET_FOLDER_SORT_PRIORITY   10
#define ICON_COUNT   clIconUrlDefined
#define GFT_IGNORE   -1
#define GFT_NOSUCHFILE   0
#define GFT_DIR   1
#define GFT_FILE   2
#define GFT_SYMLINK   3

Enumerations

enum  mdsFsItemType_e {
  mdsFitFile = 0, mdsFitContainer, mdsFitFolder, mdsFitStorage,
  mdsFitApplication, mdsFitManifestDirectory, mdsFitSymlink, mdsFitManifestSymlink,
  mdsFitManifestSymlinkLocale, mdsFitUndefined
}
enum  mdsFieldType_e {
  mdsFieldAuthor = 0, mdsFieldDate, mdsFieldDescription, mdsFieldFile,
  mdsFieldTitle, mdsFieldFsName, mdsFieldExtName, mdsFieldSize,
  mdsFieldNone
}
enum  clIconID_e {
  clFolderIcon = 0, clUnknownIcon, clBookIcon, clDocumentIcon,
  clMagazineIcon, clMiscIcon, clMp3Icon, clNewspaperIcon,
  clNoteIcon, clPhotoIcon, clReviewIcon, clOutboxIcon,
  clIconUrlDefined
}
enum  mdsSelType_e { mdsSingleSel_e = 0, mdsMultiSel_e, mdsSelUndefined }

Functions

int erMdsContentScan (GArray *dirArray, GArray **contentItemArray)
int erMdsContentSort (GArray *contentItemArray, mdsSortStruct_t *sort)
int erClGetDisplayItems (GArray *contentItemArray, int nBegin, int *nChunk, clDisplayItem_t *displayItemArray)
int erClXmlParseManifest (char *szContainerPath, clDisplayItem_t *displayItem)
void erClXmlFetchField (char *szFilename, mdsFieldType_e fieldType, char *szField)
gboolean erClXmlSetFieldSize (const gchar *szContainer, int size)
const mdsSelectionList_terClXmlFetchSelectionList (const char *szManifestPath)
int erClXmlSaveSelectionList (const mdsSelectionList_t *selectionList)
void erClXmlFreeSelectionList (const mdsSelectionList_t *selectionList)
int erClXmlSetSelectionItem (const mdsSelectionList_t *selectionList, const guint selectionIndex, const guint itemIndex, const gboolean state)
int erClXmlGetSelectionListItemState (const mdsSelectionList_t *selectionList, const char *selectionId, const char *itemId, gboolean *state)
const gchar * ctrl_is_trusted_path (const char *path)


Detailed Description

eReader Content Lister content and filesystem datatypes

Definition in file erMdsContent.h.


Define Documentation

#define ERCL_INVALID_ARGS   -10

Definition at line 80 of file erMdsContent.h.

#define ERCL_INVALID_SIZE   -1

Definition at line 83 of file erMdsContent.h.

#define ERCL_MAX_DESCRIPTION_SIZE   512

Definition at line 61 of file erMdsContent.h.

#define ERCL_MAX_FIELDNAME_SIZE   128

Definition at line 63 of file erMdsContent.h.

#define ERCL_MAX_SUBTITLE_SIZE   512

Definition at line 60 of file erMdsContent.h.

#define ERCL_MAX_TITLE_SIZE   512

Definition at line 59 of file erMdsContent.h.

#define ERCL_NOMATCH   -11

Definition at line 81 of file erMdsContent.h.

#define ERCL_OK   0

Definition at line 79 of file erMdsContent.h.

#define ERMDS_CONTENT_SCAN_FAILED   -1

Definition at line 70 of file erMdsContent.h.

#define ERMDS_CONTENT_SCAN_OK   0

Definition at line 69 of file erMdsContent.h.

#define ERMDS_CONTENT_SCAN_TOO_MANY_ITEMS   -2

Definition at line 71 of file erMdsContent.h.

#define ERMDS_CONTENT_SORT_FAILED   -1

Definition at line 75 of file erMdsContent.h.

#define ERMDS_CONTENT_SORT_NOT_IMPLEMENTED   -2

Definition at line 76 of file erMdsContent.h.

#define ERMDS_CONTENT_SORT_OK   0

Definition at line 74 of file erMdsContent.h.

#define ERMDS_INITIAL_CONTENT_SCAN_ARRAY_SIZE   100

Definition at line 65 of file erMdsContent.h.

#define ERMDS_MAX_CONTENT_SCAN_ARRAY_SIZE   (1024-1)

Definition at line 66 of file erMdsContent.h.

#define ERMDS_MAX_EXTENSION_ID_SIZE   128

Definition at line 55 of file erMdsContent.h.

#define ERMDS_MAX_EXTENSION_SIZE   5

Definition at line 53 of file erMdsContent.h.

#define ERMDS_MAX_FILENAME_SIZE   1024

Definition at line 52 of file erMdsContent.h.

#define ERMDS_MAX_SEARCH_STRING_SIZE   512

Definition at line 54 of file erMdsContent.h.

#define ERMDS_MAX_SYMLINK_CHAIN   10

Definition at line 57 of file erMdsContent.h.

#define GFT_DIR   1

Definition at line 259 of file erMdsContent.h.

#define GFT_FILE   2

Definition at line 260 of file erMdsContent.h.

#define GFT_IGNORE   -1

Definition at line 257 of file erMdsContent.h.

#define GFT_NOSUCHFILE   0

Definition at line 258 of file erMdsContent.h.

#define GFT_SYMLINK   3

Definition at line 261 of file erMdsContent.h.

#define ICON_COUNT   clIconUrlDefined

Definition at line 139 of file erMdsContent.h.

#define ITEM_SIGN_YES   "sign"

Definition at line 49 of file erMdsContent.h.

#define ITEM_TRANSFER_MOVE   "move"

Definition at line 46 of file erMdsContent.h.

#define MOBIPOCKET_FOLDER   "/books/Mobipocket"

Definition at line 87 of file erMdsContent.h.

#define MOBIPOCKET_FOLDER_LENGTH   17

Definition at line 88 of file erMdsContent.h.

#define MOBIPOCKET_FOLDER_SORT_PRIORITY   10

Definition at line 91 of file erMdsContent.h.

#define OUTBOX_NAME   "outbox"

Definition at line 39 of file erMdsContent.h.

#define SELECTION_DOCUMENT_SIGNING   "document-signing"

Definition at line 48 of file erMdsContent.h.

#define SELECTION_TRANSFER_MODE   "transfer-mode"

Definition at line 45 of file erMdsContent.h.

#define XMLNODE_SELECTION_LIST   "/package/metadata/selection-list"

Definition at line 42 of file erMdsContent.h.


Enumeration Type Documentation

enum clIconID_e

Enumerator:
clFolderIcon 
clUnknownIcon 
clBookIcon 
clDocumentIcon 
clMagazineIcon 
clMiscIcon 
clMp3Icon 
clNewspaperIcon 
clNoteIcon 
clPhotoIcon 
clReviewIcon 
clOutboxIcon 
clIconUrlDefined 

Definition at line 122 of file erMdsContent.h.

00123 {
00124     clFolderIcon = 0,
00125     clUnknownIcon,
00126     clBookIcon,
00127     clDocumentIcon,
00128     clMagazineIcon,
00129     clMiscIcon,
00130     clMp3Icon,
00131     clNewspaperIcon,
00132     clNoteIcon,
00133     clPhotoIcon,
00134     clReviewIcon,
00135     clOutboxIcon,
00136     clIconUrlDefined,   // icon specified in manifest file
00137 } clIconID_e;

Enumerator:
mdsFieldAuthor 
mdsFieldDate 
mdsFieldDescription 
mdsFieldFile 
mdsFieldTitle 
mdsFieldFsName 
mdsFieldExtName 
mdsFieldSize 
mdsFieldNone 

Definition at line 108 of file erMdsContent.h.

00109 {
00110     mdsFieldAuthor = 0,
00111     mdsFieldDate,
00112     mdsFieldDescription,
00113     mdsFieldFile,
00114     mdsFieldTitle,
00115     mdsFieldFsName, // Corresponds to the name of the file/folder/container. Not necessarily to
00116                     // the filename that will be passed to the viewer.
00117     mdsFieldExtName,
00118     mdsFieldSize,
00119     mdsFieldNone
00120 } mdsFieldType_e;

Enumerator:
mdsFitFile 
mdsFitContainer 
mdsFitFolder 
mdsFitStorage 
mdsFitApplication 
mdsFitManifestDirectory 
mdsFitSymlink 
mdsFitManifestSymlink 
mdsFitManifestSymlinkLocale 
mdsFitUndefined 

Definition at line 94 of file erMdsContent.h.

00095 {
00096     mdsFitFile = 0,
00097     mdsFitContainer,
00098     mdsFitFolder,
00099     mdsFitStorage,               //extension to the manifest file
00100     mdsFitApplication,           //extension to the manifest file
00101     mdsFitManifestDirectory,     //extension to the manifest file
00102     mdsFitSymlink,
00103     mdsFitManifestSymlink,       //extension to the manifest file
00104     mdsFitManifestSymlinkLocale, //extension to the manifest file
00105     mdsFitUndefined
00106 } mdsFsItemType_e;

Enumerator:
mdsSingleSel_e 
mdsMultiSel_e 
mdsSelUndefined 

Definition at line 141 of file erMdsContent.h.

00142 {
00143    mdsSingleSel_e = 0,
00144    mdsMultiSel_e,
00145    mdsSelUndefined
00146 }mdsSelType_e;


Function Documentation

const gchar* ctrl_is_trusted_path ( const char *  path  ) 

Definition at line 123 of file erMdsFs.c.

00124 {
00125     const gchar*       ret = NULL;  // return value
00126     trusted_device_t*  pDevice;
00127 
00128     static gboolean first_time = TRUE;
00129     static char*    download_history = NULL;  // name of the download history directory
00130     static int      download_history_len = 0;
00131 
00132 
00133     // do first-time initialisations
00134     if (first_time)
00135     {
00136         char   dirname[ERMDS_MAX_FILENAME_SIZE];
00137 
00138         // determine length for pathnames of trusted devices
00139         for (pDevice = (trusted_device_t*)&g_trusted_devices[0] ; pDevice->path != NULL ; pDevice++)
00140         {
00141             pDevice->len = strlen(pDevice->path);
00142         }
00143 
00144         // determine location of download history
00145         if (mdsGetRootLocation(st_DownloadHistory, dirname, sizeof(dirname)) > 0)
00146         {
00147             download_history     = strdup(dirname);
00148             download_history_len = strlen(download_history);
00149         }
00150 
00151         // first time happens only once ;-)
00152         first_time = FALSE;
00153     }
00154     
00155     // check path in trusted devices
00156     for (pDevice = &g_trusted_devices[0] ; pDevice->path != NULL && ret == NULL ; pDevice++)
00157     {
00158         if (strncmp(path, pDevice->path, pDevice->len) == 0)
00159         {
00160             // found
00161             ret = pDevice->path;
00162         }
00163     }
00164 
00165     // if not found, check for download history
00166     if (ret == NULL  &&  download_history)
00167     {
00168         if (strncmp(path, download_history, download_history_len) == 0)
00169         {
00170             // found
00171             ret = download_history;
00172         }
00173     }
00174 
00175     // return what we found
00176     return ret;
00177 }

Here is the call graph for this function:

int erClGetDisplayItems ( GArray *  contentItemArray,
int  nBegin,
int *  nChunk,
clDisplayItem_t displayItemArray 
)

Definition at line 1449 of file erMdsFs.c.

01450 {
01451     int     nEnd = 0;
01452     int     i;
01453     int     j;
01454     mdsFsItem_t*    pFsItem;
01455 
01456     // Validate parameters
01457     if (nBegin < 0 || nBegin >= contentItemArray->len)
01458     {
01459         return ERCL_INVALID_ARGS;
01460     }
01461     else if (*nChunk < 0)
01462     {
01463         return ERCL_INVALID_ARGS;
01464     }
01465 
01466     nEnd = (contentItemArray->len - 1 <= nBegin + *nChunk - 1) ? contentItemArray->len - 1 : nBegin + *nChunk - 1;
01467     *nChunk = nEnd - nBegin + 1;
01468 
01469     // i counts displayItemArray items
01470     // j counts contentItemArray items
01471     for (i = 0, j = nBegin; i < *nChunk; i++, j++)
01472     {
01473         pFsItem = &g_array_index(contentItemArray, mdsFsItem_t, j);
01474 
01475         // set default value of displayItem
01476         displayItemSetDefault(&displayItemArray[i]);
01477         
01478         // Get information to be displayed
01479         switch (pFsItem->fit)
01480         {
01481             case mdsFitFile:            
01482                 fileGetDisplayItem(pFsItem, &displayItemArray[i]);
01483                 break;
01484 
01485             case mdsFitContainer:
01486                 containerGetDisplayItem(pFsItem, &displayItemArray[i]);
01487                 break;
01488 
01489             case mdsFitFolder:
01490                 folderGetDisplayItem(pFsItem, &displayItemArray[i]);
01491                 break;
01492 
01493             case mdsFitSymlink:
01494                 symlinkGetDisplayItem(pFsItem, &displayItemArray[i]);
01495                 break;
01496 
01497             case mdsFitStorage:
01498             case mdsFitApplication:
01499             case mdsFitManifestDirectory:
01500             default:
01501                 CL_LOGPRINTF("No action required."); // No action required.
01502         }
01503     }
01504     
01505     return ERCL_OK;
01506 }

Here is the call graph for this function:

void erClXmlFetchField ( char *  szFilename,
mdsFieldType_e  fieldType,
char *  szField 
)

Definition at line 612 of file erMdsXml.c.

00613 {
00614     char    szFieldType[ERCL_MAX_FIELDNAME_SIZE];
00615     int     nDcBranch;
00616     xmlDoc *doc = NULL;
00617     xmlNode *rootElement = NULL;
00618     xmlNode *cur = NULL;
00619 
00620     strcpy(szField, "");
00621 
00622     switch (fieldType)
00623     {
00624     case mdsFieldDate:
00625         strcpy(szFieldType, "Date");
00626         break;
00627 
00628     case mdsFieldDescription:
00629         strcpy(szFieldType, "Description");
00630         break;
00631 
00632     case mdsFieldFile:
00633         strcpy(szFieldType, "startpage");
00634         break;
00635 
00636     case mdsFieldTitle:
00637         strcpy(szFieldType, "Title");
00638         break;
00639     
00640     case mdsFieldSize:
00641         strcpy(szFieldType, "ItemSize");
00642         break;
00643 
00644     default:
00645         CL_ERRORPRINTF("FieldType %d can not be retrieved from a manifest file", (int) fieldType);
00646         strcpy(szField, "");
00647         return;
00648     }
00649 
00650     // Another switch to determine the branch in which we need to search for this field
00651     switch (fieldType)
00652     {
00653     case mdsFieldFile:
00654         nDcBranch = 0;
00655         break;
00656 
00657     default:
00658         nDcBranch = 1;
00659         break;
00660     }
00661 
00662     LIBXML_TEST_VERSION doc = xmlParseFile(szFilename);
00663 
00664     if (doc == NULL)
00665     {
00666         CL_ERRORPRINTF("Document not parsed successfully");
00667         return;
00668     }
00669 
00670     /* Get the root element node */
00671     rootElement = xmlDocGetRootElement(doc);
00672 
00673     // Check whether we have a document with the correct root (i.e. package)
00674     if (xmlStrcmp(rootElement->name, (const xmlChar *) "package"))
00675     {
00676         CL_ERRORPRINTF("Document of the wrong type, root node != package");
00677         xmlFreeDoc(doc);
00678         return;
00679     }
00680 
00681     cur = rootElement->xmlChildrenNode;
00682     while (cur != NULL)
00683     {
00684         if ((!xmlStrcmp(cur->name, (const xmlChar *) "metadata")))
00685         {
00686             CL_LOGPRINTF("Found node metadata");
00687             parseMetadataForBranch(doc, cur, szFieldType, nDcBranch, szField);
00688         }
00689         cur = cur->next;
00690     }
00691 
00692     /* free the document */
00693     xmlFreeDoc(doc);
00694 
00695     /* Free the global variables that may have been allocated by the parser */
00696     xmlCleanupParser();
00697 
00698     return;
00699 }

Here is the call graph for this function:

const mdsSelectionList_t* erClXmlFetchSelectionList ( const char *  szManifestPath  ) 

Get list of selections from manifest file

Parameters:
szManifestPath - pathname of manifest file
Returns:
ptr to s selection-list structure, must be freed with erClXmlFreeSelectionList()

Definition at line 747 of file erMdsXml.c.

00748 {
00749     int  rc;
00750     int  selNum;  // number of selections
00751     int  selIdx;  // selection index
00752 
00753     erManifest*         pCtx           = NULL;  // XML context for libermanifest
00754     xmlXPathObjectPtr   xpathObj       = NULL;
00755     xmlNodePtr*         p_node         = NULL;
00756     xmlNodeSetPtr       selectionNodes = NULL;  // list of "selection" nodes
00757     xmlNodePtr          nodeRoot       = NULL;  // root node of the attribute list
00758     mdsSelectionList_t* selectionList  = NULL;
00759     mdsSelection_t*     selection      = NULL;
00760 
00761     CL_LOGPRINTF("entry: manifest [%s]", szManifestPath);
00762 
00763     selectionList = g_new0(mdsSelectionList_t, 1);
00764     
00765     // open manifest file
00766     pCtx = &(selectionList->manifest);
00767     rc = ermXmlOpenFile(szManifestPath, pCtx);
00768     if (rc != RET_OK)
00769     {
00770         CL_ERRORPRINTF("Cannot read manifest file [%s]", szManifestPath);
00771         goto ERROR_EXIT;
00772     }
00773     else { CL_LOGPRINTF("manifest opened ok"); }
00774 
00775     // validate manifest file
00776     //rc = ermXmlValidateManifest(pCtx);
00777     rc = ermXmlValidateManifest(pCtx);
00778     if (rc != RET_OK)
00779     {
00780         CL_ERRORPRINTF("manifest file [%s] NOT validated", szManifestPath);
00781         goto ERROR_EXIT;
00782     }
00783     else { CL_LOGPRINTF("manifest validated ok"); }
00784 
00785 
00786     // get selection-list node
00787     xpathObj = ermXmlSelectNodes(pCtx, XMLNODE_SELECTION_LIST);
00788     if (xpathObj == NULL)
00789     {
00790         CL_WARNPRINTF("No selection-list in [%s]", szManifestPath);
00791         goto ERROR_EXIT;
00792     }
00793     else { CL_LOGPRINTF("selection list found"); }
00794 
00795     //     store root node of the selection-list tree
00796     nodeRoot = xpathObj->nodesetval->nodeTab[0];
00797     selectionList->nodeRoot = nodeRoot;
00798     //     free temporary data
00799     xmlXPathFreeObject(xpathObj);
00800     xpathObj = NULL;
00801 
00802     //     get selection nodes
00803     selectionNodes = ermXmlGetChildNodeSet(nodeRoot, "selection");
00804     if (selectionNodes->nodeNr == 0)
00805     {
00806         CL_ERRORPRINTF("Empty selection-list in [%s]", szManifestPath);
00807         selectionList->num_selections = 0;
00808         goto ERROR_EXIT;
00809     }
00810     selNum = selectionNodes->nodeNr;
00811     selectionList->num_selections = selNum;
00812     selectionList->selections     = g_new0(mdsSelection_t, selNum);
00813 
00814     p_node    = selectionNodes->nodeTab;
00815     selection = (mdsSelection_t*) selectionList->selections;  // const_cast
00816     for (selIdx = 0 ; selIdx < selNum ; selIdx++, p_node++, selection++)
00817     {
00818         fetchSelectionDetails(*p_node, selection);
00819     }
00820 
00821     // sort the selections
00822     qsort( (void*)selectionList->selections,
00823             selectionList->num_selections,
00824             sizeof(selectionList->selections[0]),
00825             selectionCompareFunc );
00826 
00827 ERROR_EXIT:
00828     // add copy/move selection when not found in manifest
00829     if (selectionList)
00830     {
00831         addSelectionCopyMove(selectionList);
00832     }
00833 
00834     // free temporary memory and return the list of selections
00835     if (selectionNodes)  { xmlXPathFreeNodeSet(selectionNodes); }
00836     if (xpathObj)        { xmlXPathFreeObject(xpathObj);        }
00837     return selectionList;
00838 }

Here is the call graph for this function:

void erClXmlFreeSelectionList ( const mdsSelectionList_t selectionList  ) 

Free data structure for selections

Parameters:
selectionList - as returned by erClXmlFetchSelectionList
Returns:
--

Definition at line 1255 of file erMdsXml.c.

01256 {
01257     CL_LOGPRINTF("entry");
01258 
01259     erManifest*               pCtx      = (erManifest*) &(selectionList->manifest);  // const_cast
01260     const mdsSelection_t*     selection = NULL;
01261     const mdsSelectionItem_t* item      = NULL;
01262 
01263     int  selNum;   // number of selections
01264     int  selIdx;   // selection index
01265     int  itemNum;  // number of items
01266     int  itemIdx;  // item index
01267 
01268     if (selectionList)
01269     {
01270         if (selectionList->selections)
01271         {
01272             // for each selection in selectionList
01273             selNum    = selectionList->num_selections;
01274             selection = selectionList->selections;
01275             for (selIdx = 0 ; selIdx < selNum ; selIdx++, selection++)
01276             {
01277                 if (selection->items)
01278                 {
01279                     // for each item in selection
01280                     itemNum = selection->num_items;
01281                     item    = selection->items;
01282                     for (itemIdx = 0 ; itemIdx < itemNum ; itemIdx++, item++)
01283                     {
01284                         if (item->name) { xmlFree(item->name); }
01285                         if (item->id)   { xmlFree(item->id);   }
01286                     }
01287 
01288                     g_free((void*)(selection->items));  // const_cast
01289                 }
01290 
01291                 if (selection->display_as)  { xmlFree(selection->display_as);  }
01292                 if (selection->title)       { xmlFree(selection->title);       }
01293                 if (selection->instruction) { xmlFree(selection->instruction); }
01294                 if (selection->id)          { xmlFree(selection->id);          }
01295             }
01296 
01297             g_free((void*)(selectionList->selections));  // const_cast
01298         }
01299 
01300         ermXmlClose(pCtx);
01301         g_free((void*)selectionList);  // const_cast
01302     }
01303 }

Here is the call graph for this function:

int erClXmlGetSelectionListItemState ( const mdsSelectionList_t selectionList,
const char *  selectionId,
const char *  itemId,
gboolean *  state 
)

Get current value (state) of specified selection.item

Parameters:
selectionList - as returned by erClXmlFetchSelectionList
selectionId - id= string of the requested selection
itemId - id= string of the requested item
state - ptr to location where to store current state value
Returns:
RET_OK or RET_ERR

Definition at line 1347 of file erMdsXml.c.

01351 {
01352     gboolean  found = FALSE;
01353 
01354     const mdsSelection_t*     selection;
01355     int                       sel_idx;
01356     const mdsSelectionItem_t* item;
01357     int                       item_idx;
01358 
01359     // check selection list
01360     if (selectionList == NULL  ||  selectionList->selections == NULL)
01361     {
01362         CL_ERRORPRINTF( "Invalid selectionList [%p] selections [%p]",
01363                         selectionList,
01364                         selectionList ? selectionList->selections : NULL );
01365         return RET_ERR;
01366     }
01367     
01368     // find selection "copy or move"
01369     selection = selectionList->selections;
01370     for (sel_idx = 0 ; sel_idx < selectionList->num_selections ; sel_idx++, selection++)
01371     {
01372         if (strcmp(selection->id, selectionId) == 0)
01373         {
01374             // selection found: find item "move"
01375             item = selection->items;
01376             for (item_idx = 0 ; item_idx < selection->num_items ; item_idx++, item++)
01377             {
01378                 if (strcmp(item->id, itemId) == 0)
01379                 {
01380                     // item found: use as return value
01381                     found = TRUE;
01382                     if (item->state)
01383                     {
01384                         *state = TRUE;
01385                     }
01386                     else
01387                     {
01388                         *state = FALSE;
01389                     }
01390 
01391                     // exit for item_idx
01392                     item_idx = selection->num_items;
01393                 }
01394             }
01395 
01396             // exit for sel_idx
01397             sel_idx = selectionList->num_selections;
01398         }
01399     }
01400 
01401     if (found)
01402     {
01403         CL_LOGPRINTF("Found: selection [%s] item [%s] state [%d]", selectionId, itemId, *state);
01404         return RET_OK;
01405     }
01406     else
01407     {
01408         CL_WARNPRINTF("Not found: selection [%s] item [%s] state [%d]", selectionId, itemId, *state);
01409         return RET_ERR;
01410     }
01411 }

int erClXmlParseManifest ( char *  szContainerPath,
clDisplayItem_t displayItem 
)

Definition at line 439 of file erMdsXml.c.

00440 {
00441     int      ret = -1;  // return value: 0 = ok, -1 = error
00442 
00443     xmlDoc  *doc            = NULL;
00444     xmlNode *rootElement    = NULL;
00445     xmlNode *cur            = NULL;
00446     xmlNode *symlinkElement = NULL;
00447     xmlChar *targetPath     = NULL;
00448     xmlChar *key;
00449 
00450 
00451     int n = strlen(szContainerPath) + 1 + strlen(MANIFEST_FILENAME) + 1;
00452     char *szFilename = alloca(n);
00453     g_assert(szFilename != NULL);
00454     snprintf(szFilename, n, "%s/" MANIFEST_FILENAME, szContainerPath);
00455     
00456     LIBXML_TEST_VERSION doc = xmlParseFile(szFilename);
00457 
00458     if (doc == NULL)
00459     {
00460         CL_ERRORPRINTF("Document not parsed successfully");
00461         return ret;
00462     }
00463 
00464     /* Get the root element node */
00465     rootElement = xmlDocGetRootElement(doc);
00466 
00467     // Check whether we have a document with the correct root (i.e. package)
00468     if (xmlStrcmp(rootElement->name, (const xmlChar *) "package"))
00469     {
00470         CL_ERRORPRINTF("Document of the wrong type, root node != package");
00471         xmlFreeDoc(doc);
00472         return ret;
00473     }
00474 
00475     
00476     // Check whether this manifest actually is a symlink
00477     symlinkElement = ermXmlGetChildNode(rootElement, "symlink");
00478     if (symlinkElement)
00479     {
00480         // check whether target must be extended with locale
00481         displayItem->fit = mdsFitManifestSymlink;
00482         key = xmlGetProp(symlinkElement, "add-locale");
00483         if (key)
00484         {
00485             if (xmlStrcmp(key, "true") == 0)
00486             {
00487                 displayItem->fit = mdsFitManifestSymlinkLocale;
00488             }
00489             xmlFree(key);
00490         }
00491 
00492         // get target details
00493         targetPath = xmlNodeGetContent(symlinkElement);
00494         szFilename = getVerifiedPath(targetPath, szContainerPath);
00495         CL_WARNPRINTF("symlink [%s] [%s] --> [%s]", szContainerPath, targetPath, szFilename);
00496         if (szFilename)
00497         {
00498             strcpy(displayItem->szFilename, szFilename);
00499             free(szFilename);
00500         }
00501         else
00502         {
00503             CL_ERRORPRINTF("directory [%s] [%s] is incorrect", szContainerPath, targetPath);
00504             // display as a folder without manifest
00505             strcpy(displayItem->szFilename, szContainerPath);
00506             displayItem->fit = mdsFitFolder;
00507         }
00508     }
00509     else
00510     {
00511         cur = rootElement->xmlChildrenNode;
00512         while (cur != NULL)
00513         {
00514             if ((!xmlStrcmp(cur->name, (const xmlChar *) "metadata")))
00515             {
00516                 CL_LOGPRINTF("Found node metadata");
00517                 parseMetadata(doc, cur, displayItem, szContainerPath);
00518             }
00519 
00520             if ((!xmlStrcmp(cur->name, (const xmlChar *) "storage")))
00521             {
00522                 CL_LOGPRINTF("Found node storage");
00523                 parseStoragedata(doc, cur, displayItem, szContainerPath);
00524                 //update the type of container, since this is a special type of container
00525                 displayItem->fit = mdsFitStorage;
00526             }
00527 
00528             if ((!xmlStrcmp(cur->name, (const xmlChar *) "application")))
00529             {
00530                 CL_LOGPRINTF("Found node application");
00531                 parseApplicationdata(doc, cur, displayItem, szContainerPath);
00532                 //update the type of container, since this is a special type of container
00533                 displayItem->fit = mdsFitApplication;
00534             }
00535 
00536             if ((!xmlStrcmp(cur->name, (const xmlChar *) "directory")))
00537             {
00538                 CL_LOGPRINTF("Found node directory");
00539                 parseDirectorydata(doc, cur, displayItem, szContainerPath);
00540                 //update the type of container, since this is a special type of container
00541                 displayItem->fit = mdsFitManifestDirectory;
00542             }
00543             cur = cur->next;
00544         }
00545     }
00546 
00547     /* free the document */
00548     xmlFreeDoc(doc);
00549 
00550     /* Free the global variables that may have been allocated by the parser */
00551     xmlCleanupParser();
00552 
00553     return 0;
00554 }

Here is the call graph for this function:

int erClXmlSaveSelectionList ( const mdsSelectionList_t selectionList  ) 

Save list of selections to manifest file

Parameters:
selectionList - as returned by erClXmlFetchSelectionList
Returns:
RET_OK or RET_ERR

Definition at line 1163 of file erMdsXml.c.

01164 {
01165     int rc;
01166     int ret = RET_ERR;
01167 
01168     CL_LOGPRINTF("entry");
01169 
01170     if (selectionList == NULL)
01171     {
01172         CL_ERRORPRINTF("no selectionList");
01173         return RET_ERR;
01174     }
01175     if (selectionList->num_selections > 0  &&  selectionList->selections == NULL)
01176     {
01177         CL_ERRORPRINTF("no selectionList->selections");
01178         return RET_ERR;
01179     }
01180 
01181     int  selNum;   // number of selections
01182     int  selIdx;   // selection index
01183     int  itemNum;  // number of items
01184     int  itemIdx;  // item index
01185 
01186     erManifest*               pCtx          = (erManifest*) &(selectionList->manifest);  // const_cast
01187     xmlNodePtr                nodeRoot      = selectionList->nodeRoot;
01188     xmlNodePtr                nodeSelection = NULL;
01189     xmlNodePtr                nodeItemList  = NULL;
01190     xmlNodePtr                node          = NULL;
01191     xmlNodePtr                child         = NULL;
01192     const mdsSelection_t*     selection     = NULL;
01193     const mdsSelectionItem_t* item          = NULL;
01194 
01195     // for each selection in selectionList
01196     selNum    = selectionList->num_selections;
01197     selection = selectionList->selections;
01198     for (selIdx = 0 ; selIdx < selNum ; selIdx++, selection++)
01199     {
01200         nodeSelection = ermXmlGetChildNodeWithAttr(nodeRoot, "selection", "id", selection->id);
01201         if (nodeSelection == NULL)
01202         {
01203             CL_ERRORPRINTF("Node selection id=[%s] not found", selection->id);
01204             continue;  // next selection
01205         }
01206 
01207         nodeItemList = ermXmlGetChildNode(nodeSelection, "selection-item-list");
01208         if (nodeItemList == NULL)
01209         {
01210             CL_WARNPRINTF("Node selection-item-list id=[%s] not found", selection->id);
01211             continue;  // next selection
01212         }
01213 
01214         // for each item in selection
01215         itemNum = selection->num_items;
01216         item    = selection->items;
01217         for (itemIdx = 0 ; itemIdx < itemNum ; itemIdx++, item++)
01218         {
01219             node = ermXmlGetChildNodeWithAttr(nodeItemList, "selection-item", "id", item->id);
01220             if (node)
01221             {
01222                 // copy state to xml tree
01223                 child = ermXmlGetChildNode(node, "state");
01224                 if (child)
01225                 {
01226                     xmlNodeSetContent(child, item->state ? "true" : "false");
01227                     CL_LOGPRINTF("item id=[%s] state set to [%d] [%s]", item->id, item->state, item->state ? "true" : "false");
01228                 }
01229                 else
01230                 {
01231                     CL_ERRORPRINTF("Attribute node id=[%s] has no child 'state'", item->id);
01232                 }
01233             }
01234             else
01235             {
01236                 CL_ERRORPRINTF("Node selection-item id=[%s] not found", item->id);
01237             }
01238         }
01239     }
01240 
01241     // save xml tree to manifest file
01242     rc = ermXmlSave(pCtx);
01243     if (rc == RET_OK)
01244     {
01245         ret = RET_OK;
01246     }
01247     else
01248     {
01249         CL_ERRORPRINTF("error while saving manifest file");
01250     }
01251 
01252     return ret;
01253 }

Here is the call graph for this function:

gboolean erClXmlSetFieldSize ( const gchar *  szContainer,
int  size 
)

Definition at line 701 of file erMdsXml.c.

00702 {
00703     CL_LOGPRINTF("entry: manifest [%s], size [%d]", szContainer, size);
00704     
00705     g_return_val_if_fail((szContainer != NULL), FALSE);
00706 
00707     erManifest manifest;
00708     int        nLength;
00709     char       szSize[ERMDS_MAX_FILENAME_SIZE];
00710     gboolean   retval = FALSE;
00711     
00712     // open manifest file and update it
00713     if (RET_OK == ermXmlOpenManifest(szContainer, &manifest))
00714     {
00715         nLength = g_snprintf(szSize, ERMDS_MAX_FILENAME_SIZE, "%d", size);
00716         CL_LOGPRINTF("size = %s", szSize);
00717 
00718         // update size
00719         if (RET_OK == ermXmlExist(&manifest, "/package/metadata/y-metadata/ItemSize"))
00720         {
00721             ermXmlSetString( &manifest,
00722                              "/package/metadata/y-metadata/ItemSize",
00723                              szSize );
00724         }
00725         else
00726         {
00727             ermXmlNewString( &manifest,
00728                              "/package/metadata/y-metadata",
00729                              "ItemSize",
00730                              szSize );
00731         }
00732         
00733         // save manifest
00734         ermXmlSaveAndClose(&manifest);
00735 
00736         retval = TRUE;
00737     }
00738     else
00739     {
00740         CL_ERRORPRINTF("Could not open manifest file in [%s]", szContainer);
00741     }
00742     
00743     return retval;
00744 }

Here is the call graph for this function:

int erClXmlSetSelectionItem ( const mdsSelectionList_t selectionList,
const guint  selectionIndex,
const guint  itemIndex,
const gboolean  state 
)

Set specified in item in selection list to true/false

Parameters:
selectionList - as returned by erClXmlFetchSelectionList
selection_index - requested selection as index in mdsSelection_t
item_index - requested item as index in mdsSelection_t[].items
state - new state of this item
Returns:
RET_OK or RET_ERR

Definition at line 1305 of file erMdsXml.c.

01309 {
01310     // check selection list
01311     if (selectionList == NULL  ||  selectionList->selections == NULL)
01312     {
01313         CL_ERRORPRINTF( "Invalid selectionList [%p] selections [%p]",
01314                         selectionList,
01315                         selectionList ? selectionList->selections : NULL );
01316         return RET_ERR;
01317     }
01318     if (selectionIndex >= selectionList->num_selections)
01319     {
01320         CL_ERRORPRINTF( "Invalid selectionIndex [%u] num_selections [%u]",
01321                         selectionIndex,
01322                         selectionList->num_selections );
01323         return RET_ERR;
01324     }
01325     
01326     // find selection
01327     mdsSelection_t* selection = (mdsSelection_t*) &(selectionList->selections[selectionIndex]);  // const_cast
01328 
01329     // check selection
01330     if (itemIndex >= selection->num_items)
01331     {
01332         CL_ERRORPRINTF( "Invalid itemIndex [%u] num_items [%u]",
01333                         itemIndex,
01334                         selection->num_items );
01335         return RET_ERR;
01336     }
01337 
01338     // get item
01339     mdsSelectionItem_t* item = (mdsSelectionItem_t*) &(selection->items[itemIndex]);  // const_cast
01340 
01341     // set item state
01342     item->state = state;
01343 
01344     return RET_OK;
01345 }

int erMdsContentScan ( GArray *  dirArray,
GArray **  contentItemArray 
)

Scan an array of directories for content items that match search criteria.

Parameters:
dirArray An array of directories that will be scanned
contentItemArray Will contain retrieved content items. Pass NULL when you want the function to allocate memory
Returns:
one of the following errorcodes: ERMDS_CONTENT_SCAN_OK, ERMDS_CONTENT_SCAN_FAILED, ERMDS_CONTENT_SCAN_TOO_MANY_ITEMS

Definition at line 183 of file erMdsFs.c.

00184 {
00185     gint    nDir;
00186     guint   initialArraySize = ERMDS_INITIAL_CONTENT_SCAN_ARRAY_SIZE;
00187     DIR    *dirp;
00188     struct dirent *direntp;
00189     mdsFsItem_t fsItem;
00190     int     ret = ERMDS_CONTENT_SCAN_OK;
00191 
00192     CL_LOGPRINTF("entry");
00193 
00194     // Only create a new array when necessary:
00195     if (*contentItemArray == NULL)
00196     {
00197         CL_LOGPRINTF("Creating a new contentItemArray");
00198         // Create a new array for initialArraySize items to store mdsFsItem_t values.
00199         // Don't zero-terminate or clear to 0's.
00200         *contentItemArray = g_array_sized_new(FALSE, FALSE, sizeof(mdsFsItem_t), initialArraySize);
00201     }
00202 
00203     CL_LOGPRINTF("dirArray->len = %d", dirArray->len);
00204 
00205     // Loop over all directories 
00206     for (nDir = 0; nDir < dirArray->len; nDir++)
00207     {
00208         // This works because mdsDirectory_t contains the filename as first member
00209         char   *szDir = (char *) &g_array_index(dirArray, mdsDirectory_t, nDir);
00210 
00211         if ((dirp = opendir(szDir)) == NULL)
00212         {
00213             // This is not an error condition
00214             CL_WARNPRINTF("Could not open directory %s (error %s).", szDir, strerror(errno));
00215         }
00216         else
00217         {
00218             while ((direntp = readdir(dirp)) != NULL)
00219             {
00220                 // Hide '.' and '..' entries and names starting with a dot
00221                 // Hide file/dir names starting with an underscore
00222                 // Hide 'manifest.xml' files
00223                 if ((direntp->d_name[0] != (int) '.') && (direntp->d_name[0] != (int) '_')
00224                         && (strcasecmp(MANIFEST_FILENAME, direntp->d_name) != 0))
00225                 {
00226                     gint    nPathLength;
00227 
00228                     CL_LOGPRINTF("%s", direntp->d_name);
00229 
00230                     // Check on buffer overflow
00231                     nPathLength =
00232                         g_snprintf(fsItem.szFilename, ERMDS_MAX_FILENAME_SIZE, "%s/%s", szDir, direntp->d_name);
00233                     fsItem.sortField = NULL; 
00234                     fsItem.priority = 0;
00235 
00236                     if (nPathLength < ERMDS_MAX_FILENAME_SIZE)
00237                     {
00238                         // Determine the file item type: File / Container / Folder
00239                         // fprintf(stderr, "(%d)", nPathLength);
00240                         int gft = erClGetFileType(fsItem.szFilename);
00241                         switch (gft)
00242                         {
00243                             case GFT_FILE:
00244                                 fsItem.fit = mdsFitFile;
00245                                 break;
00246 
00247                             case GFT_DIR:
00248                                 {
00249                                     char        szManifestPath[ERMDS_MAX_FILENAME_SIZE];
00250                                     struct stat statbuf;
00251 
00252                                     // If the directory contains a manifest file we have a container
00253                                     g_snprintf( szManifestPath, sizeof(szManifestPath),
00254                                                               "%s/" MANIFEST_FILENAME,
00255                                                               fsItem.szFilename       );
00256                                     // Does the manifest file exist?
00257                                     if (stat(szManifestPath, &statbuf) == 0)
00258                                     {
00259                                         if (S_ISREG(statbuf.st_mode) != 0)
00260                                         {
00261                                             fsItem.fit = mdsFitContainer;
00262                                         }
00263                                         else
00264                                         {
00265                                             CL_WARNPRINTF("%s is not a regular file, default to folder type",
00266                                                           szManifestPath);
00267                                             fsItem.fit = mdsFitFolder;
00268                                         }
00269                                     }
00270                                     else
00271                                     {
00272                                         fsItem.fit = mdsFitFolder;
00273                                     }
00274                                     
00275                                     // Mobipocket HACK, sort it always on top
00276                                     if (is_mobipocket_folder(fsItem.szFilename, nPathLength))
00277                                     {
00278                                         CL_LOGPRINTF("Found Mobipocket: %s", fsItem.szFilename);
00279                                         fsItem.priority = MOBIPOCKET_FOLDER_SORT_PRIORITY;
00280                                     }
00281                                 }
00282                                 break;
00283 
00284                             case GFT_SYMLINK:
00285                                 fsItem.fit = mdsFitSymlink;
00286                                 break;
00287                                 
00288                             case GFT_NOSUCHFILE:
00289                             case GFT_IGNORE:
00290                             default:
00291                                 continue; // while ((direntp = readdir(dirp)) != NULL)
00292                         }
00293 
00294                         if ((*contentItemArray)->len < ERMDS_MAX_CONTENT_SCAN_ARRAY_SIZE)
00295                         {
00296                             g_array_append_val(*contentItemArray, fsItem);
00297                         }
00298                         else
00299                         {
00300                             ret = ERMDS_CONTENT_SCAN_TOO_MANY_ITEMS;
00301                             break;
00302                         }
00303                     }
00304                     else
00305                     {
00306                         CL_ERRORPRINTF("Filename %s/%s too long. (nPathLength (%d) > %d)", szDir, direntp->d_name,
00307                                        nPathLength, ERMDS_MAX_FILENAME_SIZE);
00308                     }
00309                 }
00310             }                   // while ((direntp = readdir(dirp)) != NULL)
00311             closedir(dirp);
00312         }
00313         if (ret == ERMDS_CONTENT_SCAN_TOO_MANY_ITEMS)
00314         {
00315             return ret;
00316         }
00317     }                           // for (nDir = 0; nDir < dirArray->len; nDir++)
00318     return ret;
00319 }

Here is the call graph for this function:

int erMdsContentSort ( GArray *  contentItemArray,
mdsSortStruct_t sort 
)

Sort the array passed as an argument according to the sort criterium.

Parameters:
contentItemArray - Contain items to be sorted
sort -
Returns:
one of the following errorcodes: ERMDS_CONTENT_SORT_OK, ERMDS_CONTENT_SORT_FAILED

Definition at line 323 of file erMdsFs.c.

00324 {
00325     int     ret;
00326     
00327     CL_LOGPRINTF("entry");
00328 
00329     switch (sort->ft)
00330     {
00331         case mdsFieldFsName:
00332             g_array_sort_with_data(contentItemArray, mdsFieldFsNameComparison, (gpointer) sort);
00333             ret = ERMDS_CONTENT_SORT_OK;
00334             break;
00335 
00336         case mdsFieldAuthor:
00337         case mdsFieldDate:
00338         case mdsFieldDescription:
00339         case mdsFieldFile:
00340         case mdsFieldTitle:
00341         case mdsFieldExtName:
00342         case mdsFieldSize:
00343             mdsContentPreSort(contentItemArray, sort);
00344             g_array_sort_with_data(contentItemArray, mdsFieldGenericComparison, (gpointer) sort);
00345             mdsContentPostSort(contentItemArray);
00346             ret = ERMDS_CONTENT_SORT_OK;
00347             break;
00348 
00349         default:
00350             CL_ERRORPRINTF("No support for sorting of type %d", (int) sort->ft);
00351             ret = ERMDS_CONTENT_SORT_NOT_IMPLEMENTED;
00352     }
00353     return ret;
00354 }

Here is the call graph for this function:


Generated on Sun Dec 14 17:12:50 2008 by  doxygen 1.5.6