serializer.h File Reference

Header for data-to-disk component. More...

#include "pair.h"

Include dependency graph for serializer.h:

Include dependency graph

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

Included by dependency graph

Go to the source code of this file.

Data Structures

struct  serialnode_t
 Associates a class name with a handler function. More...
struct  serial_t
 root of handler associations More...

Defines

#define FERROR   error
 default error handler
#define PREFIX   "tmp/"
 default work directory

Enumerations

enum  eserial { CLASSES = 1 }
 serializer constants More...
enum  eserialerr {
  ERROK, ERRGENERAL, ERRDIGEST, ERRPROCESS,
  ERRMATH, ERRMATHWRITE, ERRMAGICK, ERRMAGICKREAD,
  ERRMAGICKTRIM, ERRMAGICKWRITE, ERRDVIPNG, ERRDVIPNGWRITE,
  ERRDVIPNGOUTPUT
}
 Houses central error constants whose adherent strings (see error ) are communicated to the browser. More...
enum  epcerror { PCOPEN, PCCLOSE }
 Corresponds to open and close error display. More...

Functions

int serialize (char *, pair_t *)
 Creates hash digest of source and siphons either to specific or generic renderer.
int digest (char *, char **)
 Hashes source into digest form (MD5).
void error (int)
 Parses eserialerr and displays to browser wrapped in span.


Detailed Description

Header for data-to-disk component.

Definition in file serializer.h.


Define Documentation

#define FERROR   error
 

default error handler

Definition at line 9 of file serializer.h.

#define PREFIX   "tmp/"
 

default work directory

Definition at line 11 of file serializer.h.

Referenced by math().


Enumeration Type Documentation

enum epcerror
 

Corresponds to open and close error display.

Enumeration values:
PCOPEN  open tag
PCCLOSE  close tag

Definition at line 52 of file serializer.h.

00052               {
00053   PCOPEN,                       
00054   PCCLOSE                       
00055 };

enum eserial
 

serializer constants

Enumeration values:
CLASSES  distinct classes, whose first is default

Definition at line 14 of file serializer.h.

00014              {
00015   CLASSES = 1                   
00016 };

enum eserialerr
 

Houses central error constants whose adherent strings (see error ) are communicated to the browser.

Enumeration values:
ERROK  no error
ERRGENERAL  internal, generic error
ERRDIGEST  error producing hash
ERRPROCESS  error opening process with popen
ERRMATH  generic LaTeX error
ERRMATHWRITE  error writing LaTeX product
ERRMAGICK  ImageMagick initialization error
ERRMAGICKREAD  error reading image
ERRMAGICKTRIM  error paring image
ERRMAGICKWRITE  error serializing image
ERRDVIPNG  error initializing dvipng
ERRDVIPNGWRITE  error writing product
ERRDVIPNGOUTPUT  error displaying product

Definition at line 35 of file serializer.h.

00035                 {
00036   ERROK,                        
00037   ERRGENERAL,                   
00038   ERRDIGEST,                    
00039   ERRPROCESS,                   
00040   ERRMATH,                      
00041   ERRMATHWRITE,                 
00042   ERRMAGICK,                    
00043   ERRMAGICKREAD,                
00044   ERRMAGICKTRIM,                
00045   ERRMAGICKWRITE,               
00046   ERRDVIPNG,                    
00047   ERRDVIPNGWRITE,               
00048   ERRDVIPNGOUTPUT               
00049 };


Function Documentation

int digest char *  pcin,
char **  ppcdigest
 

Hashes source into digest form (MD5).

Parameters:
pcin digestible
ppcdigest digest receivable, initialized with NONE
Returns:
status according to eserialerr .

Definition at line 56 of file serializer.c.

References ERRDIGEST, and EVAL.

Referenced by serialize().

00057 {
00058   EVP_MD_CTX mdctx;
00059   unsigned char md_value[EVP_MAX_MD_SIZE];
00060   unsigned int md_len, u;
00061   int iret = ERROK;
00062   char ac[3];
00063 
00064   EVP_DigestInit(&mdctx, EVP_md5());
00065   EVP_DigestUpdate(&mdctx, pcin, strlen(pcin));
00066   EVP_DigestFinal(&mdctx, md_value, &md_len);
00067   EVAL((*ppcdigest = (char *) realloc(*ppcdigest, md_len * sizeof(char) * 2 + sizeof('\0'))) == NULL, ERRDIGEST);
00068   strcpy(*ppcdigest, "");
00069   for (u = 0; u < md_len; u++) {
00070     sprintf(ac, "%02x", *(md_value + u));
00071     strcat(*ppcdigest, ac);
00072   }
00073 
00074  cleanup:
00075   return iret;
00076 }

void error int  i  ) 
 

Parses eserialerr and displays to browser wrapped in span.

Parameters:
i eserialerr

Definition at line 80 of file serializer.c.

References PCCLOSE, and PCOPEN.

00081 {
00082   const char *apcerr[] = { "<span class=\"latexerror\">[phptex: ", ".]</span>" };
00083   const char *apc[] = {
00084     "OK",
00085     "Internal error",
00086     "Digest error",
00087     "Error communicating with process",
00088     "Invalid directives",
00089     "Could not write LaTeX base",
00090     "Internal ImageMagick error",
00091     "ImageMagick read error",
00092     "ImageMagick pare error",
00093     "ImageMagick write error",
00094     "Error invoking `dvipng'",
00095     "dvipng functions not",
00096     "dvipng produced no output"
00097   };
00098   printf("%s%s%s", apcerr[PCOPEN], apc[i], apcerr[PCCLOSE]);
00099 }

int serialize char *  pcin,
pair_t ppa
 

Creates hash digest of source and siphons either to specific or generic renderer.

Parameters:
pcin renderand [sic] source
ppa parameter pairs, whose first is {class, content}; whose remaining: in-tag specificates
Returns:
status according to eserialerr .

Definition at line 29 of file serializer.c.

References serial_t::asen, digest(), serial_t::i, IEVAL, math(), NONE, pcdigest(), pairnode_t::pckey, serialnode_t::pf, ppa, and pair_t::ppan.

Referenced by translate().

00030 {
00031   int i, ierr, iret = EXIT_SUCCESS;
00032   const serial_t se = { CLASSES, {
00033     { "math", math }
00034   }};
00035   char NONE(*pcdigest);
00036   IEVAL(digest(pcin, &pcdigest), ierr);
00037 
00038   for (i = 0; i < se.i; i++) {
00039     if (strcmp(ppa->ppan->pckey, (se.asen + i)->pc) == 0) {
00040       IEVAL((se.asen + i)->pf(pcin, pcdigest, ppa), ierr);
00041       goto cleanup;
00042     }
00043   }
00044   /* default case */
00045   IEVAL(se.asen->pf(pcin, pcdigest, ppa), ierr);
00046 
00047  cleanup:
00048   free(pcdigest);
00049   return iret;
00050 }

Here is the call graph for this function:


Generated on Tue Dec 7 06:38:25 2004 for CSCI101:ProjectLatex by  doxygen 1.3.9.1