Esempio n. 1
0
CConvertCSIDStreamOut::CConvertCSIDStreamOut(int16 oldCSID, int16 newCSID, IStreamOut* pStream){
    m_oldCSID = oldCSID;
    m_newCSID = newCSID;
    m_bNullConversion = oldCSID == newCSID;
    m_pStream = pStream;
    if ( ! m_bNullConversion ){
        m_Converter = INTL_CreateCharCodeConverter();
        if ( ! INTL_GetCharCodeConverter(oldCSID, newCSID, m_Converter) ){
            INTL_DestroyCharCodeConverter(m_Converter);
            m_bNullConversion = TRUE;
        }
    }
}
Esempio n. 2
0
PRIVATE int
net_AutoCharCodeConv (NET_StreamClass *stream, const char *s, int32 l)
{
	NetStreamData*nsd=stream->data_object;
	int16	doc_csid;
	unsigned char	*tobuf = NULL;
	int				rv;
	CCCFunc cvtfunc;

	cvtfunc = INTL_GetCCCCvtfunc(nsd->obj);

/* for debugging -- erik */
#if 0
	{
		static FILE *f = NULL;

		if (!f)
		{
			f = fopen("/tmp/zzz", "w");
		}

		if (f && s && (l > 0))
		{
			(void) fwrite(s, 1, l, f);
		}
	}
#endif /* 0 */

	if (cvtfunc != NULL)
		tobuf = (unsigned char *)cvtfunc(nsd->obj, (unsigned char *)s, l);
	else
	{
		/* Look at the first block and see if we determine
		 * what the charset is from that block.
		 */

		/*  Somehow NET_PlainTextConverter() put a "<plaintext>" in the
			first block. Try to bypass that block
			We need this so we can detect UCS2 for the NT UCS2 plantext
		*/
		if((l == 11) && (strncmp(s, "<plaintext>", 11)==0))
		{
			return((*nsd->next_stream->put_block)(nsd->next_stream,s,l));
		} 
		/* check for unicode (ucs2) */
		doc_csid = DetectUCS2(nsd->obj, (unsigned char *)s, l);
	 	if(doc_csid == CS_DEFAULT)
		{
			doc_csid = PeekMetaCharsetTag((char *)s, l) ;
			if (doc_csid == CS_ASCII) /* the header said ascii. */
			{
				nsd->current_stream->put_block = (MKStreamWriteFunc) net_NoCharCodeConv;
				return((*nsd->next_stream->put_block)(nsd->next_stream,s,l));
			}
		}

		/* We looked at the first block but did not determine
		 * what the charset is.  Install the default converter
		 * now.  It could be a standard or an auto-detecting converter.
		 */
		if (doc_csid != CS_DEFAULT)
		{
			(void) INTL_GetCharCodeConverter(doc_csid, 0, nsd->obj);
			INTL_CallCCCReportAutoDetect(nsd->obj, doc_csid);
		}
		else
			(void) INTL_GetCharCodeConverter(INTL_GetCCCDefaultCSID(nsd->obj),0,nsd->obj);
		cvtfunc = INTL_GetCCCCvtfunc(nsd->obj);

		/* If no conversion needed, change put_block module for successive
		 * data blocks.  For current data block, return unmodified buffer.
		 */
		if (cvtfunc == NULL) 
		{
			return((*nsd->next_stream->put_block)(nsd->next_stream,s,l));
		}

		/* For initial block, must call converter directly.  Success calls
		 * to the converter will be called directly from net_CharCodeConv()
		 */
	}

	if (tobuf == NULL)
		tobuf = (unsigned char *)cvtfunc(nsd->obj, (unsigned char *)s, l);

	if (tobuf) {
		rv = (*nsd->next_stream->put_block) (nsd->next_stream,
			(const char *)tobuf, INTL_GetCCCLen(nsd->obj));
		if (tobuf != (unsigned char*)s)
			XP_FREE(tobuf);
    	return(rv);
	} else {
		return(INTL_GetCCCRetval(nsd->obj));
	}
}