Back to index

php5  5.3.10
Functions | Variables
mbfilter_base64.h File Reference
#include "mbfilter.h"
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

int mbfl_filt_conv_base64enc (int c, mbfl_convert_filter *filter)
int mbfl_filt_conv_base64enc_flush (mbfl_convert_filter *filter)
int mbfl_filt_conv_base64dec (int c, mbfl_convert_filter *filter)
int mbfl_filt_conv_base64dec_flush (mbfl_convert_filter *filter)

Variables

const mbfl_encoding mbfl_encoding_base64

Function Documentation

int mbfl_filt_conv_base64dec ( int  c,
mbfl_convert_filter *  filter 
)

Definition at line 149 of file mbfilter_base64.c.

{
       int n;

       if (c == 0x0d || c == 0x0a || c == 0x20 || c == 0x09 || c == 0x3d) {  /* CR or LF or SPACE or HTAB or '=' */
              return c;
       }

       n = 0;
       if (c >= 0x41 && c <= 0x5a) {             /* A - Z */
              n = c - 65;
       } else if (c >= 0x61 && c <= 0x7a) {      /* a - z */
              n = c - 71;
       } else if (c >= 0x30 && c <= 0x39) {      /* 0 - 9 */
              n = c + 4;
       } else if (c == 0x2b) {                   /* '+' */
              n = 62;
       } else if (c == 0x2f) {                   /* '/' */
              n = 63;
       }
       n &= 0x3f;

       switch (filter->status) {
       case 0:
              filter->status = 1;
              filter->cache = n << 18;
              break;
       case 1:
              filter->status = 2;
              filter->cache |= n << 12;
              break;
       case 2:
              filter->status = 3;
              filter->cache |= n << 6;
              break;
       default:
              filter->status = 0;
              n |= filter->cache;
              CK((*filter->output_function)((n >> 16) & 0xff, filter->data));
              CK((*filter->output_function)((n >> 8) & 0xff, filter->data));
              CK((*filter->output_function)(n & 0xff, filter->data));
              break;
       }

       return c;
}
int mbfl_filt_conv_base64dec_flush ( mbfl_convert_filter *  filter)

Definition at line 196 of file mbfilter_base64.c.

{
       int status, cache;

       status = filter->status;
       cache = filter->cache;
       filter->status = 0;
       filter->cache = 0;
       /* flush fragments */
       if (status >= 2) {
              CK((*filter->output_function)((cache >> 16) & 0xff, filter->data));
              if (status >= 3) {
                     CK((*filter->output_function)((cache >> 8) & 0xff, filter->data));
              }
       }
       return 0;
}
int mbfl_filt_conv_base64enc ( int  c,
mbfl_convert_filter *  filter 
)

Definition at line 84 of file mbfilter_base64.c.

{
       int n;

       n = (filter->status & 0xff);
       if (n == 0) {
              filter->status++;
              filter->cache = (c & 0xff) << 16;
       } else if (n == 1) {
              filter->status++;
              filter->cache |= (c & 0xff) << 8;
       } else {
              filter->status &= ~0xff;
              if ((filter->status & MBFL_BASE64_STS_MIME_HEADER) == 0) {
                     n = (filter->status & 0xff00) >> 8;
                     if (n > 72) {
                            CK((*filter->output_function)(0x0d, filter->data));            /* CR */
                            CK((*filter->output_function)(0x0a, filter->data));            /* LF */
                            filter->status &= ~0xff00;
                     }
                     filter->status += 0x400;
              }
              n = filter->cache | (c & 0xff);
              CK((*filter->output_function)(mbfl_base64_table[(n >> 18) & 0x3f], filter->data));
              CK((*filter->output_function)(mbfl_base64_table[(n >> 12) & 0x3f], filter->data));
              CK((*filter->output_function)(mbfl_base64_table[(n >> 6) & 0x3f], filter->data));
              CK((*filter->output_function)(mbfl_base64_table[n & 0x3f], filter->data));
       }

       return c;
}
int mbfl_filt_conv_base64enc_flush ( mbfl_convert_filter *  filter)

Definition at line 116 of file mbfilter_base64.c.

{
       int status, cache, len;

       status = filter->status & 0xff;
       cache = filter->cache;
       len = (filter->status & 0xff00) >> 8;
       filter->status &= ~0xffff;
       filter->cache = 0;
       /* flush fragments */
       if (status >= 1) {
              if ((filter->status & MBFL_BASE64_STS_MIME_HEADER) == 0) {
                     if (len > 72){
                            CK((*filter->output_function)(0x0d, filter->data));            /* CR */
                            CK((*filter->output_function)(0x0a, filter->data));            /* LF */
                     }
              }
              CK((*filter->output_function)(mbfl_base64_table[(cache >> 18) & 0x3f], filter->data));
              CK((*filter->output_function)(mbfl_base64_table[(cache >> 12) & 0x3f], filter->data));
              if (status == 1) {
                     CK((*filter->output_function)(0x3d, filter->data));            /* '=' */
                     CK((*filter->output_function)(0x3d, filter->data));            /* '=' */
              } else {
                     CK((*filter->output_function)(mbfl_base64_table[(cache >> 6) & 0x3f], filter->data));
                     CK((*filter->output_function)(0x3d, filter->data));            /* '=' */
              }
       }
       return 0;
}

Variable Documentation

Definition at line 38 of file mbfilter_base64.c.