Back to index

php5  5.3.10
Functions | Variables
mbfl_convert.c File Reference
#include "mbfl_encoding.h"
#include "mbfl_allocators.h"
#include "mbfl_filter_output.h"
#include "mbfilter_pass.h"
#include "mbfilter_8bit.h"
#include "mbfilter_wchar.h"
#include "filters/mbfilter_euc_cn.h"
#include "filters/mbfilter_hz.h"
#include "filters/mbfilter_euc_tw.h"
#include "filters/mbfilter_big5.h"
#include "filters/mbfilter_uhc.h"
#include "filters/mbfilter_euc_kr.h"
#include "filters/mbfilter_iso2022_kr.h"
#include "filters/mbfilter_sjis.h"
#include "filters/mbfilter_sjis_open.h"
#include "filters/mbfilter_cp51932.h"
#include "filters/mbfilter_jis.h"
#include "filters/mbfilter_iso2022_jp_ms.h"
#include "filters/mbfilter_euc_jp.h"
#include "filters/mbfilter_euc_jp_win.h"
#include "filters/mbfilter_ascii.h"
#include "filters/mbfilter_koi8r.h"
#include "filters/mbfilter_koi8u.h"
#include "filters/mbfilter_cp866.h"
#include "filters/mbfilter_cp932.h"
#include "filters/mbfilter_cp936.h"
#include "filters/mbfilter_cp1251.h"
#include "filters/mbfilter_cp1252.h"
#include "filters/mbfilter_cp1254.h"
#include "filters/mbfilter_cp5022x.h"
#include "filters/mbfilter_iso8859_1.h"
#include "filters/mbfilter_iso8859_2.h"
#include "filters/mbfilter_iso8859_3.h"
#include "filters/mbfilter_iso8859_4.h"
#include "filters/mbfilter_iso8859_5.h"
#include "filters/mbfilter_iso8859_6.h"
#include "filters/mbfilter_iso8859_7.h"
#include "filters/mbfilter_iso8859_8.h"
#include "filters/mbfilter_iso8859_9.h"
#include "filters/mbfilter_iso8859_10.h"
#include "filters/mbfilter_iso8859_13.h"
#include "filters/mbfilter_iso8859_14.h"
#include "filters/mbfilter_iso8859_15.h"
#include "filters/mbfilter_base64.h"
#include "filters/mbfilter_qprint.h"
#include "filters/mbfilter_uuencode.h"
#include "filters/mbfilter_7bit.h"
#include "filters/mbfilter_utf7.h"
#include "filters/mbfilter_utf7imap.h"
#include "filters/mbfilter_utf8.h"
#include "filters/mbfilter_utf16.h"
#include "filters/mbfilter_utf32.h"
#include "filters/mbfilter_byte2.h"
#include "filters/mbfilter_byte4.h"
#include "filters/mbfilter_ucs4.h"
#include "filters/mbfilter_ucs2.h"
#include "filters/mbfilter_htmlent.h"
#include "filters/mbfilter_armscii8.h"
#include "filters/mbfilter_cp850.h"

Go to the source code of this file.

Functions

static int mbfl_convert_filter_common_init (mbfl_convert_filter *filter, enum mbfl_no_encoding from, enum mbfl_no_encoding to, const struct mbfl_convert_vtbl *vtbl, int(*output_function)(int, void *), int(*flush_function)(void *), void *data)
mbfl_convert_filter * mbfl_convert_filter_new (enum mbfl_no_encoding from, enum mbfl_no_encoding to, int(*output_function)(int, void *), int(*flush_function)(void *), void *data)
mbfl_convert_filter * mbfl_convert_filter_new2 (const struct mbfl_convert_vtbl *vtbl, int(*output_function)(int, void *), int(*flush_function)(void *), void *data)
void mbfl_convert_filter_delete (mbfl_convert_filter *filter)
int mbfl_convert_filter_feed (int c, mbfl_convert_filter *filter)
int mbfl_convert_filter_flush (mbfl_convert_filter *filter)
void mbfl_convert_filter_reset (mbfl_convert_filter *filter, enum mbfl_no_encoding from, enum mbfl_no_encoding to)
void mbfl_convert_filter_copy (mbfl_convert_filter *src, mbfl_convert_filter *dest)
int mbfl_convert_filter_devcat (mbfl_convert_filter *filter, mbfl_memory_device *src)
int mbfl_convert_filter_strcat (mbfl_convert_filter *filter, const unsigned char *p)
int mbfl_filt_conv_illegal_output (int c, mbfl_convert_filter *filter)
struct mbfl_convert_vtblmbfl_convert_filter_get_vtbl (enum mbfl_no_encoding from, enum mbfl_no_encoding to)
void mbfl_filt_conv_common_ctor (mbfl_convert_filter *filter)
int mbfl_filt_conv_common_flush (mbfl_convert_filter *filter)
void mbfl_filt_conv_common_dtor (mbfl_convert_filter *filter)

Variables

static char mbfl_hexchar_table []
struct mbfl_convert_vtblmbfl_convert_filter_list []

Function Documentation

static int mbfl_convert_filter_common_init ( mbfl_convert_filter *  filter,
enum mbfl_no_encoding  from,
enum mbfl_no_encoding  to,
const struct mbfl_convert_vtbl vtbl,
int(*)(int, void *)  output_function,
int(*)(void *)  flush_function,
void *  data 
) [static]

Definition at line 246 of file mbfl_convert.c.

{
       /* encoding structure */
       if ((filter->from = mbfl_no2encoding(from)) == NULL) {
              return 1;
       }

       if ((filter->to = mbfl_no2encoding(to)) == NULL) {
              return 1;
       }

       if (output_function != NULL) {
              filter->output_function = output_function;
       } else {
              filter->output_function = mbfl_filter_output_null;
       }

       filter->flush_function = flush_function;
       filter->data = data;
       filter->illegal_mode = MBFL_OUTPUTFILTER_ILLEGAL_MODE_CHAR;
       filter->illegal_substchar = 0x3f;         /* '?' */
       filter->num_illegalchar = 0;
       filter->filter_ctor = vtbl->filter_ctor;
       filter->filter_dtor = vtbl->filter_dtor;
       filter->filter_function = vtbl->filter_function;
       filter->filter_flush = vtbl->filter_flush;
       filter->filter_copy = vtbl->filter_copy;

       (*filter->filter_ctor)(filter);

       return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void mbfl_convert_filter_copy ( mbfl_convert_filter *  src,
mbfl_convert_filter *  dest 
)

Definition at line 388 of file mbfl_convert.c.

{
       if (src->filter_copy != NULL) {
              src->filter_copy(src, dest);
              return;
       }

       *dest = *src;
}

Here is the caller graph for this function:

void mbfl_convert_filter_delete ( mbfl_convert_filter *  filter)

Definition at line 348 of file mbfl_convert.c.

{
       if (filter) {
              (*filter->filter_dtor)(filter);
              mbfl_free((void*)filter);
       }
}

Here is the caller graph for this function:

int mbfl_convert_filter_devcat ( mbfl_convert_filter *  filter,
mbfl_memory_device src 
)

Definition at line 400 of file mbfl_convert.c.

{
       int n;
       unsigned char *p;

       p = src->buffer;
       n = src->pos;
       while (n > 0) {
              if ((*filter->filter_function)(*p++, filter) < 0) {
                     return -1;
              }
              n--;
       }

       return n;
}

Here is the caller graph for this function:

int mbfl_convert_filter_feed ( int  c,
mbfl_convert_filter *  filter 
)

Definition at line 357 of file mbfl_convert.c.

{
       return (*filter->filter_function)(c, filter);
}
int mbfl_convert_filter_flush ( mbfl_convert_filter *  filter)

Definition at line 363 of file mbfl_convert.c.

{
       (*filter->filter_flush)(filter);
       return (filter->flush_function ? (*filter->flush_function)(filter->data) : 0);
}

Here is the caller graph for this function:

Definition at line 534 of file mbfl_convert.c.

{
       const struct mbfl_convert_vtbl *vtbl;
       int i;

       if (to == mbfl_no_encoding_base64 ||
           to == mbfl_no_encoding_qprint ||
           to == mbfl_no_encoding_7bit) {
              from = mbfl_no_encoding_8bit;
       } else if (from == mbfl_no_encoding_base64 ||
                        from == mbfl_no_encoding_qprint ||
                        from == mbfl_no_encoding_uuencode) {
              to = mbfl_no_encoding_8bit;
       }

       i = 0;
       while ((vtbl = mbfl_convert_filter_list[i++]) != NULL){
              if (vtbl->from == from && vtbl->to == to) {
                     return vtbl;
              }
       }

       return NULL;
}

Here is the caller graph for this function:

mbfl_convert_filter* mbfl_convert_filter_new ( enum mbfl_no_encoding  from,
enum mbfl_no_encoding  to,
int(*)(int, void *)  output_function,
int(*)(void *)  flush_function,
void *  data 
)

Definition at line 288 of file mbfl_convert.c.

{
       mbfl_convert_filter * filter;
       const struct mbfl_convert_vtbl *vtbl;

       vtbl = mbfl_convert_filter_get_vtbl(from, to);

       if (vtbl == NULL) {
              vtbl = &vtbl_pass;
       }

       /* allocate */
       filter = (mbfl_convert_filter *)mbfl_malloc(sizeof(mbfl_convert_filter));
       if (filter == NULL) {
              return NULL;
       }

       if (mbfl_convert_filter_common_init(filter, from, to, vtbl,
                     output_function, flush_function, data)) {
              mbfl_free(filter);
              return NULL;
       }

       return filter;
}

Here is the call graph for this function:

Here is the caller graph for this function:

mbfl_convert_filter* mbfl_convert_filter_new2 ( const struct mbfl_convert_vtbl vtbl,
int(*)(int, void *)  output_function,
int(*)(void *)  flush_function,
void *  data 
)

Definition at line 320 of file mbfl_convert.c.

{
       mbfl_convert_filter * filter;

       if (vtbl == NULL) {
              vtbl = &vtbl_pass;
       }

       /* allocate */
       filter = (mbfl_convert_filter *)mbfl_malloc(sizeof(mbfl_convert_filter));
       if (filter == NULL) {
              return NULL;
       }

       if (mbfl_convert_filter_common_init(filter, vtbl->from, vtbl->to, vtbl,
                     output_function, flush_function, data)) {
              mbfl_free(filter);
              return NULL;
       }

       return filter;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void mbfl_convert_filter_reset ( mbfl_convert_filter *  filter,
enum mbfl_no_encoding  from,
enum mbfl_no_encoding  to 
)

Definition at line 369 of file mbfl_convert.c.

{
       const struct mbfl_convert_vtbl *vtbl;

       /* destruct old filter */
       (*filter->filter_dtor)(filter);

       vtbl = mbfl_convert_filter_get_vtbl(from, to);

       if (vtbl == NULL) {
              vtbl = &vtbl_pass;
       }

       mbfl_convert_filter_common_init(filter, from, to, vtbl,
                     filter->output_function, filter->flush_function, filter->data);
}

Here is the call graph for this function:

Here is the caller graph for this function:

int mbfl_convert_filter_strcat ( mbfl_convert_filter *  filter,
const unsigned char *  p 
)

Definition at line 417 of file mbfl_convert.c.

{
       int c;

       while ((c = *p++) != '\0') {
              if ((*filter->filter_function)(c, filter) < 0) {
                     return -1;
              }
       }

       return 0;
}

Here is the caller graph for this function:

void mbfl_filt_conv_common_ctor ( mbfl_convert_filter *  filter)

Definition at line 562 of file mbfl_convert.c.

{
       filter->status = 0;
       filter->cache = 0;
}

Here is the caller graph for this function:

void mbfl_filt_conv_common_dtor ( mbfl_convert_filter *  filter)

Definition at line 579 of file mbfl_convert.c.

{
       filter->status = 0;
       filter->cache = 0;
}

Here is the caller graph for this function:

int mbfl_filt_conv_common_flush ( mbfl_convert_filter *  filter)

Definition at line 568 of file mbfl_convert.c.

{
       filter->status = 0;
       filter->cache = 0;

       if (filter->flush_function != NULL) {
              (*filter->flush_function)(filter->data);
       }
       return 0;
}
int mbfl_filt_conv_illegal_output ( int  c,
mbfl_convert_filter *  filter 
)

Definition at line 432 of file mbfl_convert.c.

{
       int mode_backup, ret, n, m, r;

       ret = 0;
       mode_backup = filter->illegal_mode;
       filter->illegal_mode = MBFL_OUTPUTFILTER_ILLEGAL_MODE_NONE;
       switch (mode_backup) {
       case MBFL_OUTPUTFILTER_ILLEGAL_MODE_CHAR:
              ret = (*filter->filter_function)(filter->illegal_substchar, filter);
              break;
       case MBFL_OUTPUTFILTER_ILLEGAL_MODE_LONG:
              if (c >= 0) {
                     if (c < MBFL_WCSGROUP_UCS4MAX) {   /* unicode */
                            ret = mbfl_convert_filter_strcat(filter, (const unsigned char *)"U+");
                     } else {
                            if (c < MBFL_WCSGROUP_WCHARMAX) {
                                   m = c & ~MBFL_WCSPLANE_MASK;
                                   switch (m) {
                                   case MBFL_WCSPLANE_JIS0208:
                                          ret = mbfl_convert_filter_strcat(filter, (const unsigned char *)"JIS+");
                                          break;
                                   case MBFL_WCSPLANE_JIS0212:
                                          ret = mbfl_convert_filter_strcat(filter, (const unsigned char *)"JIS2+");
                                          break;
                                   case MBFL_WCSPLANE_WINCP932:
                                          ret = mbfl_convert_filter_strcat(filter, (const unsigned char *)"W932+");
                                          break;
                                   case MBFL_WCSPLANE_8859_1:
                                          ret = mbfl_convert_filter_strcat(filter, (const unsigned char *)"I8859_1+");
                                          break;
                                   default:
                                          ret = mbfl_convert_filter_strcat(filter, (const unsigned char *)"?+");
                                          break;
                                   }
                                   c &= MBFL_WCSPLANE_MASK;
                            } else {
                                   ret = mbfl_convert_filter_strcat(filter, (const unsigned char *)"BAD+");
                                   c &= MBFL_WCSGROUP_MASK;
                            }
                     }
                     if (ret >= 0) {
                            m = 0;
                            r = 28;
                            while (r >= 0) {
                                   n = (c >> r) & 0xf;
                                   if (n || m) {
                                          m = 1;
                                          ret = (*filter->filter_function)(mbfl_hexchar_table[n], filter);
                                          if (ret < 0) {
                                                 break;
                                          }
                                   }
                                   r -= 4;
                            }
                            if (m == 0 && ret >= 0) {
                                   ret = (*filter->filter_function)(mbfl_hexchar_table[0], filter);
                            }
                     }
              }
              break;
       case MBFL_OUTPUTFILTER_ILLEGAL_MODE_ENTITY:
              if (c >= 0) {
                     if (c < MBFL_WCSGROUP_UCS4MAX) {   /* unicode */
                            ret = mbfl_convert_filter_strcat(filter, (const unsigned char *)"&#x");
                            if (ret < 0)
                                   break;

                            m = 0;
                            r = 28;
                            while (r >= 0) {
                                   n = (c >> r) & 0xf;
                                   if (n || m) {
                                          m = 1;
                                          ret = (*filter->filter_function)(mbfl_hexchar_table[n], filter);
                                          if (ret < 0) {
                                                 break;
                                          }
                                   }
                                   r -= 4;
                            }
                            if (ret < 0) {
                                   break;
                            }
                            if (m == 0) {
                                   ret = (*filter->filter_function)(mbfl_hexchar_table[0], filter);
                            }
                            ret = mbfl_convert_filter_strcat(filter, (const unsigned char *)";");
                     } else {
                            ret = (*filter->filter_function)(filter->illegal_substchar, filter);
                     }
              }
              break;
       default:
              break;
       }
       filter->illegal_mode = mode_backup;
       filter->num_illegalchar++;

       return ret;
}

Here is the call graph for this function:


Variable Documentation

Definition at line 105 of file mbfl_convert.c.

char mbfl_hexchar_table[] [static]
Initial value:
 {
       0x30,0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39,0x41,0x42,0x43,0x44,0x45,0x46
}

Definition at line 101 of file mbfl_convert.c.