CPersist Class Reference

Collaboration diagram for CPersist:

Collaboration graph
[legend]

List of all members.

Public Member Functions

 CPersist ()
 ~CPersist ()

Static Public Member Functions

static void SetBrowser (Ereader *p)
static EreaderGetBrowser ()
static char * GetPageLastRead (const char *input)
static void StorePageLastRead (const char *url)
static void SetManifestPathName (const char *pathName)
static void InstallTermHandler ()
static void UninstallTermHandler ()
static gboolean FileExist (const char *p)

Static Private Member Functions

static void OnTerminated (int sig)
static void PreparePath ()

Static Private Attributes

static Ereaders_pBrowser = NULL
static const int MAX_PATH = 1024
static char s_url [MAX_PATH]
static char s_inputUrl [MAX_PATH]
static char s_ManifestPathName [MAX_PATH]


Detailed Description

Definition at line 55 of file browser.cpp.


Constructor & Destructor Documentation

CPersist::CPersist (  )  [inline]

Definition at line 67 of file browser.cpp.

00067 {}

CPersist::~CPersist (  )  [inline]

Definition at line 68 of file browser.cpp.

00068 {}


Member Function Documentation

void CPersist::OnTerminated ( int  sig  )  [static, private]

Definition at line 111 of file browser.cpp.

00112 {
00113     // save into manifest file
00114     destroy_ereader(s_pBrowser);
00115     s_pBrowser = NULL;
00116     exit(0);
00117 }

Here is the call graph for this function:

static void CPersist::PreparePath (  )  [static, private]

static void CPersist::SetBrowser ( Ereader p  )  [inline, static]

Definition at line 70 of file browser.cpp.

00070 { s_pBrowser = p; }

static Ereader* CPersist::GetBrowser (  )  [inline, static]

Definition at line 71 of file browser.cpp.

00071 { return s_pBrowser; }

char * CPersist::GetPageLastRead ( const char *  input  )  [static]

Definition at line 186 of file browser.cpp.

00187 {
00188     BR_LOGPRINTF("input %s", input);
00189 
00190     // save input url first
00191     strncpy(s_inputUrl, input, MAX_PATH);
00192 
00193     // get url last visisted from manifest file
00194     char * url = NULL;
00195     erManifest manifest;
00196     memset(s_url, 0, MAX_PATH);
00197     if (RET_OK == ermXmlOpenFile(s_ManifestPathName, &manifest))
00198     {
00199         // usually the manifest file is existing
00200         if (RET_OK == ermXmlGetString(&manifest, "/package/last-location/document", s_url, MAX_PATH))
00201         {
00202             url = &s_url[0];
00203         }
00204         ermXmlClose(&manifest);
00205     }
00206     
00207     // check url is valid or not
00208     BR_LOGPRINTF("url from manifest %s", url);
00209     if (NULL == url) 
00210     {
00211         BR_LOGPRINTF("Could not retrieve url from manifest file %s!", s_ManifestPathName);
00212         return (char *)input;
00213     }
00214     
00215     // convert to path and check file exist, for those manifest using absolute path
00216     int prefix = strlen("file://");
00217     char tmp[MAX_PATH]  = {0};
00218     strcpy(tmp, "file://");
00219     char *path = mozilla_uri_to_path(url);
00220     if (path && FileExist(path))
00221     {
00222         // absolute path
00223         strncpy(&s_url[0], path, MAX_PATH);
00224         free(path);
00225         return &s_url[0];
00226     }
00227     else
00228     {
00229         // release 
00230         if (path) 
00231         {
00232             free(path);
00233         }
00234     
00235         // relative path, change to absolute path
00236         strcpy(tmp + prefix, s_ManifestPathName);
00237         char * pos = strrchr(tmp + prefix, '/');
00238         ++pos;
00239         strcpy(pos, url);
00240         pos += strlen(url); *pos = 0;
00241         strncpy(s_url, tmp , strlen(tmp));
00242     }
00243     
00244     // check again now
00245     BR_LOGPRINTF("check again the input %s", s_url);
00246     if (FileExist(s_url + prefix))
00247     {
00248         BR_LOGPRINTF("url result %s", s_url);
00249         return s_url;
00250     }
00251     return NULL;
00252 }

Here is the call graph for this function:

void CPersist::StorePageLastRead ( const char *  url  )  [static]

Definition at line 129 of file browser.cpp.

00130 {
00131     // get rid of the whole prefix, only use relative path
00132     // find common sub string in this two strings 
00133     // and reverse find the /
00134     BR_LOGPRINTF("Input url %s\n", url);
00135     char * path = mozilla_uri_to_path(url);
00136     char * mem  = path;
00137     if (path == NULL)
00138     {
00139         BR_LOGPRINTF("No local path %s", url);
00140         // Use inputUrl as last known location, instead of
00141         // an invalid one
00142         path = strdup(s_inputUrl);
00143     }
00144     else
00145     {
00146         BR_LOGPRINTF("Output path %s\n", path);
00147         char * tmp = &s_ManifestPathName[0];
00148         while (path && tmp && *path == *tmp)
00149         {
00150             ++path; ++tmp;
00151         }
00152         if (path)
00153         { 
00154             while (*path != '/')
00155             {
00156                 --path;
00157             }
00158             path++;
00159         }
00160     }
00161     BR_LOGPRINTF("Last location in relative path %s\n", path);
00162     erManifest manifest;
00163     if (RET_OK == ermXmlOpenFile(s_ManifestPathName, &manifest))
00164     {
00165         // usually the manifest file is existing
00166         if (RET_OK != ermXmlExist(&manifest, "/package/last-location/document"))
00167         {
00168             ermXmlNewString(&manifest, "/package", "last-location", "");
00169             ermXmlNewString(&manifest, "/package/last-location", "document", "");
00170         }
00171         ermXmlSetString(&manifest, "/package/last-location/document", path);
00172         ermXmlSaveAndClose(&manifest);
00173     }
00174     if (mem)
00175     {
00176         free(mem);
00177     }
00178 }

Here is the call graph for this function:

void CPersist::SetManifestPathName ( const char *  pathName  )  [static]

Definition at line 85 of file browser.cpp.

00086 {
00087     if (pathName)
00088     {
00089         strncpy(s_ManifestPathName, pathName, MAX_PATH);
00090     }        
00091 }

void CPersist::InstallTermHandler (  )  [static]

Definition at line 93 of file browser.cpp.

00094 {
00095     // catch the SIGTERM signal
00096     struct sigaction on_term;
00097     memset(&on_term, 0x00, sizeof(on_term));
00098     on_term.sa_handler = OnTerminated;
00099     sigaction(SIGTERM, &on_term, NULL);
00100 }

Here is the call graph for this function:

void CPersist::UninstallTermHandler (  )  [static]

Definition at line 102 of file browser.cpp.

00103 {
00104     // uninstall the SIGTERM signal
00105     struct sigaction on_term;
00106     memset(&on_term, 0x00, sizeof(on_term));
00107     on_term.sa_handler = SIG_DFL;
00108     sigaction(SIGTERM, &on_term, NULL);
00109 }

gboolean CPersist::FileExist ( const char *  p  )  [static]

Definition at line 119 of file browser.cpp.

00120 {
00121     struct stat statbuf;
00122     if (0 != stat(pathName, &statbuf))
00123     {
00124         return FALSE;
00125     }
00126     return TRUE;
00127 }


Member Data Documentation

Ereader * CPersist::s_pBrowser = NULL [static, private]

Definition at line 58 of file browser.cpp.

const int CPersist::MAX_PATH = 1024 [static, private]

Definition at line 59 of file browser.cpp.

char CPersist::s_url [static, private]

Definition at line 60 of file browser.cpp.

char CPersist::s_inputUrl [static, private]

Definition at line 61 of file browser.cpp.

char CPersist::s_ManifestPathName [static, private]

Definition at line 62 of file browser.cpp.


The documentation for this class was generated from the following file:

Generated on Sun Dec 14 17:14:58 2008 by  doxygen 1.5.6