Back to index

lightning-sunbird  0.9+nobinonly
Functions
mimefilt.cpp File Reference
#include "mimemsg.h"
#include "prglobal.h"
#include "key.h"
#include "cert.h"
#include "secrng.h"
#include "secmod.h"
#include "pk11func.h"
#include "nsMimeStringResources.h"

Go to the source code of this file.

Functions

ERROR!This is a unix only file
for the mimefilt standalone
program This does not go into
libmime static a char * 
test_file_type (const char *filename, void *stream_closure)
static char * test_type_icon (const char *type, void *stream_closure)
static int test_output_fn (char *buf, PRInt32 size, void *closure)
static int test_output_init_fn (const char *type, const char *charset, const char *name, const char *x_mac_type, const char *x_mac_creator, void *stream_closure)
static voidtest_image_begin (const char *image_url, const char *content_type, void *stream_closure)
static void test_image_end (void *image_closure, int status)
static char * test_image_make_image_html (void *image_data)
static int test_image_write_buffer (const char *buf, PRInt32 size, void *image_closure)
static char * test_passwd_prompt (PK11SlotInfo *slot, void *wincx)
int test (FILE *in, FILE *out, const char *url, PRBool fancy_headers_p, PRBool html_p, PRBool outline_p, PRBool dexlate_p, PRBool variable_width_plaintext_p)
static char * test_cdb_name_cb (void *arg, int vers)
static char * test_kdb_name_cb (void *arg, int vers)
void SEC_Init (void)
int main (int argc, char **argv)
 The Xalan testcases app.

Function Documentation

int main ( int  argc,
char **  argv 
)

The Xalan testcases app.

Definition at line 362 of file mimefilt.cpp.

{
  PRInt32 i = 1;
  char *url = "";
  PRBool fancy_p = PR_TRUE;
  PRBool html_p = PR_TRUE;
  PRBool outline_p = PR_FALSE;
  PRBool dexlate_p = PR_FALSE;
  char filename[1000];
  CERTCertDBHandle *cdb_handle;
  SECKEYKeyDBHandle *kdb_handle;

  PR_Init("mimefilt", 24, 1, 0);

  cdb_handle = (CERTCertDBHandle *)  calloc(1, sizeof(*cdb_handle));

  if (SECSuccess != CERT_OpenCertDB(cdb_handle, PR_FALSE, test_cdb_name_cb, NULL))
       CERT_OpenVolatileCertDB(cdb_handle);
  CERT_SetDefaultCertDB(cdb_handle);

  RNG_RNGInit();

  kdb_handle = SECKEY_OpenKeyDB(PR_FALSE, test_kdb_name_cb, NULL);
  SECKEY_SetDefaultKeyDB(kdb_handle);

  PK11_SetPasswordFunc(test_passwd_prompt);

  sprintf(filename, "%s/.netscape/secmodule.db", getenv("HOME"));
  SECMOD_init(filename);

  SEC_Init();


  if (i < argc)
       {
         if (argv[i][0] == '-')
              url = nsCRT::strdup("");
         else
              url = argv[i++];
       }

  if (url &&
         (PL_strstr(url, "?part=") ||
          PL_strstr(url, "&part=")))
       html_p = PR_FALSE;

  while (i < argc)
       {
         if (!nsCRT::strcmp(argv[i], "-fancy"))
              fancy_p = PR_TRUE;
         else if (!nsCRT::strcmp(argv[i], "-no-fancy"))
              fancy_p = PR_FALSE;
         else if (!nsCRT::strcmp(argv[i], "-html"))
              html_p = PR_TRUE;
         else if (!nsCRT::strcmp(argv[i], "-raw"))
              html_p = PR_FALSE;
         else if (!nsCRT::strcmp(argv[i], "-outline"))
              outline_p = PR_TRUE;
         else if (!nsCRT::strcmp(argv[i], "-dexlate"))
              dexlate_p = PR_TRUE;
         else
              {
                fprintf(stderr,
                "usage: %s [ URL [ -fancy | -no-fancy | -html | -raw | -outline | -dexlate ]]\n"
                              "     < message/rfc822 > output\n",
                              (PL_strrchr(argv[0], '/') ?
                               PL_strrchr(argv[0], '/') + 1 :
                               argv[0]));
                i = 1;
                goto FAIL;
              }
         i++;
       }

  i = test(stdin, stdout, url, fancy_p, html_p, outline_p, dexlate_p, PR_TRUE);
  fprintf(stdout, "\n");
  fflush(stdout);

 FAIL:

  CERT_ClosePermCertDB(cdb_handle);
  SECKEY_CloseKeyDB(kdb_handle);

  exit(i);
}

Here is the call graph for this function:

Definition at line 43 of file secinit.c.

{
    /* PR_Init() must be called before SEC_Init() */
#if !defined(SERVER_BUILD)
    PORT_Assert(PR_Initialized() == PR_TRUE);
#endif
    if (sec_inited)
       return;

    sec_inited = 1;
}

Here is the caller graph for this function:

int test ( FILE in,
FILE out,
const char *  url,
PRBool  fancy_headers_p,
PRBool  html_p,
PRBool  outline_p,
PRBool  dexlate_p,
PRBool  variable_width_plaintext_p 
)

Definition at line 235 of file mimefilt.cpp.

{
  int status = 0;
  MimeObject *obj = 0;
  MimeDisplayOptions *opt = new MimeDisplayOptions;
//  memset(opt, 0, sizeof(*opt));

  if (dexlate_p) html_p = PR_FALSE;

  opt->fancy_headers_p = fancy_headers_p;
  opt->headers = MimeHeadersSome;
  opt->rot13_p = PR_FALSE;

  status = mime_parse_url_options(url, opt);
  if (status < 0)
       {
         PR_Free(opt);
         return MIME_OUT_OF_MEMORY;
       }

  opt->url                                = url;
  opt->write_html_p                = html_p;
  opt->dexlate_p                   = dexlate_p;
  opt->output_init_fn              = test_output_init_fn;
  opt->output_fn                   = test_output_fn;
  opt->charset_conversion_fn= 0;
  opt->rfc1522_conversion_p = PR_FALSE;
  opt->file_type_fn                = test_file_type;
  opt->stream_closure              = out;

  opt->image_begin                 = test_image_begin;
  opt->image_end                   = test_image_end;
  opt->make_image_html             = test_image_make_image_html;
  opt->image_write_buffer   = test_image_write_buffer;

  opt->variable_width_plaintext_p = variable_width_plaintext_p;

  obj = mime_new ((MimeObjectClass *)&mimeMessageClass,
                              (MimeHeaders *) NULL,
                              MESSAGE_RFC822);
  if (!obj)
       {
         PR_Free(opt);
         return MIME_OUT_OF_MEMORY;
       }
  obj->options = opt;

  status = obj->class->initialize(obj);
  if (status >= 0)
       status = obj->class->parse_begin(obj);
  if (status < 0)
       {
         PR_Free(opt);
         PR_Free(obj);
         return MIME_OUT_OF_MEMORY;
       }

  while (1)
       {
         char buf[255];
         int size = fread(buf, sizeof(*buf), sizeof(buf), stdin);
         if (size <= 0) break;
         status = obj->class->parse_buffer(buf, size, obj);
         if (status < 0)
              {
                mime_free(obj);
                PR_Free(opt);
                return status;
              }
       }

  status = obj->class->parse_eof(obj, PR_FALSE);
  if (status >= 0)
       status = obj->class->parse_end(obj, PR_FALSE);
  if (status < 0)
       {
         mime_free(obj);
         PR_Free(opt);
         return status;
       }

  if (outline_p)
       {
         fprintf(out, "\n\n"
                "###############################################################\n");
         obj->class->debug_print(obj, stderr, 0);
         fprintf(out,
                "###############################################################\n");
       }

  mime_free (obj);
  PR_Free(opt);
  return 0;
}

Here is the call graph for this function:

static char* test_cdb_name_cb ( void arg,
int  vers 
) [static]

Definition at line 338 of file mimefilt.cpp.

{
  static char f[1024];
  if (vers <= 4)
       sprintf(f, "%s/.netscape/cert.db", getenv("HOME"));
  else
       sprintf(f, "%s/.netscape/cert%d.db", getenv("HOME"), vers);
  return f;
}

Here is the caller graph for this function:

ERROR ! This is a unix only file for the mimefilt standalone program This does not go into libmime static a char* test_file_type ( const char *  filename,
void stream_closure 
) [static]

Definition at line 87 of file mimefilt.cpp.

{
  const char *suf = PL_strrchr(filename, '.');
  if (!suf)
       return 0;
  suf++;

  if (!nsCRT::strcasecmp(suf, "txt") ||
         !nsCRT::strcasecmp(suf, "text"))
       return nsCRT::strdup("text/plain");
  else if (!nsCRT::strcasecmp(suf, "htm") ||
                 !nsCRT::strcasecmp(suf, "html"))
       return nsCRT::strdup("text/html");
  else if (!nsCRT::strcasecmp(suf, "gif"))
       return nsCRT::strdup("image/gif");
  else if (!nsCRT::strcasecmp(suf, "jpg") ||
                 !nsCRT::strcasecmp(suf, "jpeg"))
       return nsCRT::strdup("image/jpeg");
  else if (!nsCRT::strcasecmp(suf, "pjpg") ||
                 !nsCRT::strcasecmp(suf, "pjpeg"))
       return nsCRT::strdup("image/pjpeg");
  else if (!nsCRT::strcasecmp(suf, "xbm"))
       return nsCRT::strdup("image/x-xbitmap");
  else if (!nsCRT::strcasecmp(suf, "xpm"))
       return nsCRT::strdup("image/x-xpixmap");
  else if (!nsCRT::strcasecmp(suf, "xwd"))
       return nsCRT::strdup("image/x-xwindowdump");
  else if (!nsCRT::strcasecmp(suf, "bmp"))
       return nsCRT::strdup("image/x-MS-bmp");
  else if (!nsCRT::strcasecmp(suf, "au"))
       return nsCRT::strdup("audio/basic");
  else if (!nsCRT::strcasecmp(suf, "aif") ||
                 !nsCRT::strcasecmp(suf, "aiff") ||
                 !nsCRT::strcasecmp(suf, "aifc"))
       return nsCRT::strdup("audio/x-aiff");
  else if (!nsCRT::strcasecmp(suf, "ps"))
       return nsCRT::strdup("application/postscript");
  else
       return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void* test_image_begin ( const char *  image_url,
const char *  content_type,
void stream_closure 
) [static]

Definition at line 178 of file mimefilt.cpp.

{
  return ((void *) nsCRT::strdup(image_url));
}

Here is the caller graph for this function:

static void test_image_end ( void image_closure,
int  status 
) [static]

Definition at line 185 of file mimefilt.cpp.

{
  char *url = (char *) image_closure;
  if (url) PR_Free(url);
}

Here is the caller graph for this function:

static char* test_image_make_image_html ( void image_data) [static]

Definition at line 192 of file mimefilt.cpp.

{
  char *url = (char *) image_data;
#if 0
  const char *prefix = "<P><CENTER><IMG SRC=\"";
  const char *suffix = "\"></CENTER><P>";
#else
  const char *prefix = ("<P><CENTER><TABLE BORDER=2 CELLPADDING=20"
                                          " BGCOLOR=WHITE>"
                                          "<TR><TD ALIGN=CENTER>"
                                          "an inlined image would have gone here for<BR>");
  const char *suffix = "</TD></TR></TABLE></CENTER><P>";
#endif
  PRUint32 buflen = strlen (prefix) + strlen (suffix) + strlen (url) + 20;
  char *buf = (char *) PR_MALLOC (buflen);
  if (!buf) return 0;
  *buf = 0;
  PL_strcatn (buf, buflen, prefix);
  PL_strcatn (buf, buflen, url);
  PL_strcatn (buf, buflen, suffix);
  return buf;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static int test_image_write_buffer ( const char *  buf,
PRInt32  size,
void image_closure 
) [static]

Definition at line 215 of file mimefilt.cpp.

{
  return 0;
}

Here is the caller graph for this function:

static char* test_kdb_name_cb ( void arg,
int  vers 
) [static]

Definition at line 349 of file mimefilt.cpp.

{
  static char f[1024];
  if (vers <= 2)
       sprintf(f, "%s/.netscape/key.db", getenv("HOME"));
  else
       sprintf(f, "%s/.netscape/key%d.db", getenv("HOME"), vers);
  return f;
}

Here is the caller graph for this function:

static int test_output_fn ( char *  buf,
PRInt32  size,
void closure 
) [static]

Definition at line 146 of file mimefilt.cpp.

{
  FILE *out = (FILE *) closure;
  if (out)
       return fwrite(buf, sizeof(*buf), size, out);
  else
       return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static int test_output_init_fn ( const char *  type,
const char *  charset,
const char *  name,
const char *  x_mac_type,
const char *  x_mac_creator,
void stream_closure 
) [static]

Definition at line 156 of file mimefilt.cpp.

{
  FILE *out = (FILE *) stream_closure;
  fprintf(out, "CONTENT-TYPE: %s", type);
  if (charset)
       fprintf(out, "; charset=\"%s\"", charset);
  if (name)
       fprintf(out, "; name=\"%s\"", name);
  if (x_mac_type || x_mac_creator)
       fprintf(out, "; x-mac-type=\"%s\"; x-mac-creator=\"%s\"",
                     x_mac_type ? x_mac_type : "",
                     x_mac_creator ? x_mac_type : "");
  fprintf(out, CRLF CRLF);
  return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static char* test_passwd_prompt ( PK11SlotInfo *  slot,
void wincx 
) [static]

Definition at line 221 of file mimefilt.cpp.

{
  char buf[2048], *s;
  fprintf(stdout, "#### Password required: ");
  s = fgets(buf, sizeof(buf)-1, stdin);
  if (!s) return s;
  if (s[nsCRT::strlen(s)-1] == '\r' ||
         s[nsCRT::strlen(s)-1] == '\n')
       s[nsCRT::strlen(s)-1] = '\0';
  return s;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static char* test_type_icon ( const char *  type,
void stream_closure 
) [static]

Definition at line 129 of file mimefilt.cpp.

{
  if (!nsCRT::strncasecmp(type, "text/", 5))
       return nsCRT::strdup("resource://gre/res/html/gopher-text.gif");
  if (!nsCRT::strncasecmp(type, "image/", 6))
       return nsCRT::strdup("resource://gre/res/html/gopher-image.gif");
  if (!nsCRT::strncasecmp(type, "audio/", 6))
       return nsCRT::strdup("resource://gre/res/html/gopher-sound.gif");
  if (!nsCRT::strncasecmp(type, "video/", 6))
       return nsCRT::strdup("resource://gre/res/html/gopher-movie.gif");
  if (!nsCRT::strncasecmp(type, "application/", 12))
       return nsCRT::strdup("resource://gre/res/html/gopher-binary.gif");

  return nsCRT::strdup("resource://gre/res/html/gopher-unknown.gif");
}

Here is the call graph for this function: