[ Avaa Bypassed ]




Upload:

Command:

hmhc3928@18.220.94.189: ~ $
/*
 * "streamable kanji code filter and converter"
 * Copyright (c) 1998-2002 HappySize, Inc. All rights reserved.
 *
 * LICENSE NOTICES
 *
 * This file is part of "streamable kanji code filter and converter",
 * which is distributed under the terms of GNU Lesser General Public 
 * License (version 2) as published by the Free Software Foundation.
 *
 * This software is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with "streamable kanji code filter and converter";
 * if not, write to the Free Software Foundation, Inc., 59 Temple Place,
 * Suite 330, Boston, MA  02111-1307  USA
 *
 * The author of this part: Marcus Boerger <helly@php.net>
 *
 */
/*
 * The source code included in this files was separated from mbfilter.c
 * by moriyoshi koizumi <moriyoshi@php.net> on 4 dec 2002.
 * 
 */

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

#ifdef HAVE_STRING_H
#include <string.h>
#endif

#ifdef HAVE_STRINGS_H
#include <strings.h>
#endif

#include "mbfilter.h"
#include "mbfilter_htmlent.h"
#include "html_entities.h"

static const int htmlentitifieds[256] = {
  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 2, 0,
  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1
};

static const char *mbfl_encoding_html_ent_aliases[] = {"HTML", "html", NULL};

const mbfl_encoding mbfl_encoding_html_ent = {
	mbfl_no_encoding_html_ent,
	"HTML-ENTITIES",
	"HTML-ENTITIES",
	(const char *(*)[])&mbfl_encoding_html_ent_aliases,
	NULL,
	MBFL_ENCTYPE_ENC_STRM | MBFL_ENCTYPE_GL_UNSAFE
};

const struct mbfl_convert_vtbl vtbl_wchar_html = {
	mbfl_no_encoding_wchar,
	mbfl_no_encoding_html_ent,
	mbfl_filt_conv_common_ctor,
	mbfl_filt_conv_common_dtor,
	mbfl_filt_conv_html_enc,
	mbfl_filt_conv_html_enc_flush
};

const struct mbfl_convert_vtbl vtbl_html_wchar = {
	mbfl_no_encoding_html_ent,
	mbfl_no_encoding_wchar,
	mbfl_filt_conv_html_dec_ctor,
	mbfl_filt_conv_html_dec_dtor,
	mbfl_filt_conv_html_dec,
	mbfl_filt_conv_html_dec_flush };


#define CK(statement)	do { if ((statement) < 0) return (-1); } while (0)

/*
 * any => HTML
 */
int mbfl_filt_conv_html_enc(int c, mbfl_convert_filter *filter)
{
	int tmp[64];
	int i;
	unsigned int uc;
	const mbfl_html_entity_entry *e;

	if (c < sizeof(htmlentitifieds) / sizeof(htmlentitifieds[0]) &&
				htmlentitifieds[c] != 1) {
		CK((*filter->output_function)(c, filter->data));
	} else {
 		CK((*filter->output_function)('&', filter->data));
		for (i = 0; (e = &mbfl_html_entity_list[i])->name != NULL; i++) {
			if (c == e->code) {
				char *p;
				
				for (p = e->name; *p != '\0'; p++) {
					CK((*filter->output_function)((int)*p, filter->data));
				}
				goto last;
			}
		}

		{
			int *p = tmp + sizeof(tmp) / sizeof(tmp[0]);

			CK((*filter->output_function)('#', filter->data));

			uc = (unsigned int)c;

			*(--p) = '\0';
			do {
				*(--p) = "0123456789"[uc % 10];
				uc /= 10;
			} while (uc);

			for (; *p != '\0'; p++) {
				CK((*filter->output_function)(*p, filter->data));
			}
		}
	last:
		CK((*filter->output_function)(';', filter->data));
	}
	return c;
}

int mbfl_filt_conv_html_enc_flush(mbfl_convert_filter *filter)
{
	filter->status = 0;
	filter->opaque = NULL;

	if (filter->flush_function != NULL) {
		(*filter->flush_function)(filter->data);
	}

	return 0;
}

/*
 * HTML => any
 */
#define html_enc_buffer_size	16
static const char html_entity_chars[] = "#0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";

void mbfl_filt_conv_html_dec_ctor(mbfl_convert_filter *filter)
{
	filter->status = 0;
	filter->opaque = mbfl_malloc(html_enc_buffer_size+1);
}
	
void mbfl_filt_conv_html_dec_dtor(mbfl_convert_filter *filter)
{
	filter->status = 0;
	if (filter->opaque)
	{
		mbfl_free((void*)filter->opaque);
	}
	filter->opaque = NULL;
}

int mbfl_filt_conv_html_dec(int c, mbfl_convert_filter *filter)
{
	int  pos, ent = 0;
	mbfl_html_entity_entry *entity;
	char *buffer = (char*)filter->opaque;

	if (!filter->status) {
		if (c == '&' ) {
			filter->status = 1;
			buffer[0] = '&';
		} else {
			CK((*filter->output_function)(c, filter->data));
		}
	} else {
		if (c == ';') {
			if (buffer[1]=='#') {
				if (filter->status > 2 && (buffer[2] == 'x' || buffer[2] == 'X')) {
					if (filter->status > 3) {
						/* numeric entity */
						for (pos=3; pos<filter->status; pos++) {
							int v =  buffer[pos];
							if (v >= '0' && v <= '9') {
								v = v - '0';
							} else if (v >= 'A' && v <= 'F') {
								v = v - 'A' + 10;
							} else if (v >= 'a' && v <= 'f') {
								v = v - 'a' + 10;
							} else {
								ent = -1;
								break;
							}
							ent = ent * 16 + v;
						}
					} else {
						ent = -1;
					}
				} else {
					/* numeric entity */
					if (filter->status > 2) {
						for (pos=2; pos<filter->status; pos++) {
							int v = buffer[pos];
							if (v >= '0' && v <= '9') {
								v = v - '0';
							} else {
								ent = -1;
								break;
							}
							ent = ent*10 + v;
						}
					} else {
						ent = -1;
					}
				}
				if (ent >= 0 && ent < 0x110000) {
					CK((*filter->output_function)(ent, filter->data));
				} else {
					for (pos = 0; pos < filter->status; pos++) {
						CK((*filter->output_function)(buffer[pos], filter->data));
					}
					CK((*filter->output_function)(c, filter->data));
				}
				filter->status = 0;
				/*php_error_docref("ref.mbstring" TSRMLS_CC, E_NOTICE, "mbstring decoded '%s'=%d", buffer, ent);*/
			} else {
				/* named entity */
				buffer[filter->status] = 0;
				entity = (mbfl_html_entity_entry *)mbfl_html_entity_list;
				while (entity->name) {
					if (!strcmp(buffer+1, entity->name))	{
						ent = entity->code;
						break;
					}
					entity++;
				}
				if (ent) {
					/* decoded */
					CK((*filter->output_function)(ent, filter->data));
					filter->status = 0;
					/*php_error_docref("ref.mbstring" TSRMLS_CC, E_NOTICE,"mbstring decoded '%s'=%d", buffer, ent);*/
				} else { 
					/* failure */
					buffer[filter->status++] = ';';
					buffer[filter->status] = 0;
					/* php_error_docref("ref.mbstring" TSRMLS_CC, E_WARNING, "mbstring cannot decode '%s'", buffer); */
					mbfl_filt_conv_html_dec_flush(filter);
				}
			}
		} else {
			/* add character */
			buffer[filter->status++] = c;
			/* add character and check */
			if (!strchr(html_entity_chars, c) || filter->status+1==html_enc_buffer_size || (c=='#' && filter->status>2))
			{
				/* illegal character or end of buffer */
				if (c=='&')
					filter->status--;
				buffer[filter->status] = 0;
				/* php_error_docref("ref.mbstring" TSRMLS_CC, E_WARNING, "mbstring cannot decode '%s'", buffer)l */
				mbfl_filt_conv_html_dec_flush(filter);
				if (c=='&')
				{
					buffer[filter->status++] = '&';
				}
			}
		}
	}
	return c;
}

int mbfl_filt_conv_html_dec_flush(mbfl_convert_filter *filter)
{
	int status, pos = 0;
	unsigned char *buffer;
	int err = 0;

	buffer = (unsigned char*)filter->opaque;
	status = filter->status;
	filter->status = 0;

	/* flush fragments */
	while (status--) {
		int e = (*filter->output_function)(buffer[pos++], filter->data);
		if (e != 0)
			err = e;
	}

	if (filter->flush_function != NULL) {
		(*filter->flush_function)(filter->data);
	}

	return err;
}



Filemanager

Name Type Size Permission Actions
cp932_table.h File 3.96 KB 0644
emoji2uni.h File 41.06 KB 0644
html_entities.c File 6.73 KB 0644
html_entities.h File 1.29 KB 0644
mbfilter_7bit.c File 2.06 KB 0644
mbfilter_7bit.h File 1.46 KB 0644
mbfilter_armscii8.c File 3.55 KB 0644
mbfilter_armscii8.h File 1.47 KB 0644
mbfilter_ascii.c File 3 KB 0644
mbfilter_ascii.h File 1.54 KB 0644
mbfilter_base64.c File 5.95 KB 0644
mbfilter_base64.h File 1.6 KB 0644
mbfilter_big5.c File 9.1 KB 0644
mbfilter_big5.h File 1.72 KB 0644
mbfilter_byte2.c File 3.38 KB 0644
mbfilter_byte2.h File 1.78 KB 0644
mbfilter_byte4.c File 4.04 KB 0644
mbfilter_byte4.h File 1.76 KB 0644
mbfilter_cp1251.c File 3.5 KB 0644
mbfilter_cp1251.h File 1.52 KB 0644
mbfilter_cp1252.c File 3.57 KB 0644
mbfilter_cp1252.h File 1.52 KB 0644
mbfilter_cp1254.c File 3.8 KB 0644
mbfilter_cp1254.h File 1.52 KB 0644
mbfilter_cp5022x.c File 33.99 KB 0644
mbfilter_cp5022x.h File 2.74 KB 0644
mbfilter_cp51932.c File 9.7 KB 0644
mbfilter_cp51932.h File 1.5 KB 0644
mbfilter_cp850.c File 3.34 KB 0644
mbfilter_cp850.h File 1.4 KB 0644
mbfilter_cp866.c File 3.43 KB 0644
mbfilter_cp866.h File 1.49 KB 0644
mbfilter_cp932.c File 9.59 KB 0644
mbfilter_cp932.h File 1.48 KB 0644
mbfilter_cp936.c File 8.74 KB 0644
mbfilter_cp936.h File 1.49 KB 0644
mbfilter_euc_cn.c File 6.31 KB 0644
mbfilter_euc_cn.h File 1.49 KB 0644
mbfilter_euc_jp.c File 8.83 KB 0644
mbfilter_euc_jp.h File 1.49 KB 0644
mbfilter_euc_jp_2004.c File 2.2 KB 0644
mbfilter_euc_jp_2004.h File 1.52 KB 0644
mbfilter_euc_jp_win.c File 11.94 KB 0644
mbfilter_euc_jp_win.h File 1.52 KB 0644
mbfilter_euc_kr.c File 6.71 KB 0644
mbfilter_euc_kr.h File 1.49 KB 0644
mbfilter_euc_tw.c File 8.79 KB 0644
mbfilter_euc_tw.h File 1.52 KB 0644
mbfilter_gb18030.c File 13.37 KB 0644
mbfilter_gb18030.h File 1.5 KB 0644
mbfilter_htmlent.c File 7.91 KB 0644
mbfilter_htmlent.h File 1.83 KB 0644
mbfilter_hz.c File 6.85 KB 0644
mbfilter_hz.h File 1.52 KB 0644
mbfilter_iso2022_jp_ms.c File 14.11 KB 0644
mbfilter_iso2022_jp_ms.h File 1.59 KB 0644
mbfilter_iso2022_kr.c File 8.67 KB 0644
mbfilter_iso2022_kr.h File 1.57 KB 0644
mbfilter_iso2022jp_2004.c File 3.86 KB 0644
mbfilter_iso2022jp_2004.h File 1.61 KB 0644
mbfilter_iso2022jp_mobile.c File 11.49 KB 0644
mbfilter_iso2022jp_mobile.h File 1.57 KB 0644
mbfilter_iso8859_1.c File 2.53 KB 0644
mbfilter_iso8859_1.h File 1.5 KB 0644
mbfilter_iso8859_10.c File 3.15 KB 0644
mbfilter_iso8859_10.h File 1.51 KB 0644
mbfilter_iso8859_13.c File 3.14 KB 0644
mbfilter_iso8859_13.h File 1.51 KB 0644
mbfilter_iso8859_14.c File 3.15 KB 0644
mbfilter_iso8859_14.h File 838 B 0644
mbfilter_iso8859_15.c File 3.14 KB 0644
mbfilter_iso8859_15.h File 838 B 0644
mbfilter_iso8859_16.c File 3.14 KB 0644
mbfilter_iso8859_16.h File 704 B 0644
mbfilter_iso8859_2.c File 3.13 KB 0644
mbfilter_iso8859_2.h File 1.5 KB 0644
mbfilter_iso8859_3.c File 3.13 KB 0644
mbfilter_iso8859_3.h File 1.5 KB 0644
mbfilter_iso8859_4.c File 3.13 KB 0644
mbfilter_iso8859_4.h File 1.48 KB 0644
mbfilter_iso8859_5.c File 3.13 KB 0644
mbfilter_iso8859_5.h File 1.5 KB 0644
mbfilter_iso8859_6.c File 3.13 KB 0644
mbfilter_iso8859_6.h File 1.5 KB 0644
mbfilter_iso8859_7.c File 3.13 KB 0644
mbfilter_iso8859_7.h File 1.5 KB 0644
mbfilter_iso8859_8.c File 3.13 KB 0644
mbfilter_iso8859_8.h File 1.5 KB 0644
mbfilter_iso8859_9.c File 3.13 KB 0644
mbfilter_iso8859_9.h File 1.5 KB 0644
mbfilter_jis.c File 17.03 KB 0644
mbfilter_jis.h File 1.82 KB 0644
mbfilter_koi8r.c File 3.41 KB 0644
mbfilter_koi8r.h File 1.59 KB 0644
mbfilter_koi8u.c File 3.31 KB 0644
mbfilter_koi8u.h File 1.48 KB 0644
mbfilter_qprint.c File 6.66 KB 0644
mbfilter_qprint.h File 1.55 KB 0644
mbfilter_sjis.c File 7.71 KB 0644
mbfilter_sjis.h File 1.5 KB 0644
mbfilter_sjis_2004.c File 19.5 KB 0644
mbfilter_sjis_2004.h File 1.6 KB 0644
mbfilter_sjis_mac.c File 16.3 KB 0644
mbfilter_sjis_mac.h File 1.51 KB 0644
mbfilter_sjis_mobile.c File 24.87 KB 0644
mbfilter_sjis_mobile.h File 2.84 KB 0644
mbfilter_sjis_open.c File 9.66 KB 0644
mbfilter_sjis_open.h File 1.52 KB 0644
mbfilter_tl_jisx0201_jisx0208.c File 9.5 KB 0644
mbfilter_tl_jisx0201_jisx0208.h File 2.89 KB 0644
mbfilter_ucs2.c File 5.2 KB 0644
mbfilter_ucs2.h File 1.94 KB 0644
mbfilter_ucs4.c File 6.17 KB 0644
mbfilter_ucs4.h File 1.92 KB 0644
mbfilter_uhc.c File 6.87 KB 0644
mbfilter_uhc.h File 1.47 KB 0644
mbfilter_utf16.c File 7.67 KB 0644
mbfilter_utf16.h File 1.93 KB 0644
mbfilter_utf32.c File 6.76 KB 0644
mbfilter_utf32.h File 1.93 KB 0644
mbfilter_utf7.c File 12.45 KB 0644
mbfilter_utf7.h File 1.54 KB 0644
mbfilter_utf7imap.c File 10.79 KB 0644
mbfilter_utf7imap.h File 1.52 KB 0644
mbfilter_utf8.c File 8.38 KB 0644
mbfilter_utf8.h File 1.52 KB 0644
mbfilter_utf8_mobile.c File 10.13 KB 0644
mbfilter_utf8_mobile.h File 2.21 KB 0644
mbfilter_uuencode.c File 3.97 KB 0644
mbfilter_uuencode.h File 1.29 KB 0644
sjis_mac2uni.h File 10.99 KB 0644
translit_kana_jisx0201_jisx0208.h File 2.89 KB 0644
unicode_prop.h File 5.84 KB 0644
unicode_table_armscii8.h File 2.33 KB 0644
unicode_table_big5.h File 281.68 KB 0644
unicode_table_cns11643.h File 364.48 KB 0644
unicode_table_cp1251.h File 2.4 KB 0644
unicode_table_cp1252.h File 1.59 KB 0644
unicode_table_cp1254.h File 2.4 KB 0644
unicode_table_cp850.h File 2.38 KB 0644
unicode_table_cp866.h File 2.37 KB 0644
unicode_table_cp932_ext.h File 8.29 KB 0644
unicode_table_cp936.h File 354.25 KB 0644
unicode_table_gb18030.h File 11.47 KB 0644
unicode_table_iso8859_10.h File 958 B 0644
unicode_table_iso8859_13.h File 958 B 0644
unicode_table_iso8859_14.h File 958 B 0644
unicode_table_iso8859_15.h File 958 B 0644
unicode_table_iso8859_16.h File 956 B 0644
unicode_table_iso8859_2.h File 955 B 0644
unicode_table_iso8859_3.h File 955 B 0644
unicode_table_iso8859_4.h File 955 B 0644
unicode_table_iso8859_5.h File 955 B 0644
unicode_table_iso8859_6.h File 955 B 0644
unicode_table_iso8859_7.h File 955 B 0644
unicode_table_iso8859_8.h File 955 B 0644
unicode_table_iso8859_9.h File 955 B 0644
unicode_table_jis.h File 301.96 KB 0644
unicode_table_jis2004.h File 263.02 KB 0644
unicode_table_koi8r.h File 2.36 KB 0644
unicode_table_koi8u.h File 7.29 KB 0644
unicode_table_uhc.h File 393.6 KB 0644