char *url_decode(char *s) { int i = 0; char *res = s; while (*s) { /* `%' take the 2 following numbers and convert them from hexa to dec */ if (*s == '%') { /* case the string end with a `%' */ if (! *(++s)) break ; /* first hexadecimal char here */ res[i] = hexa_value(*(s++)) * 16; res[i] += hexa_value(*s); } else res[i] = *s; i++; s++; } res[i] = '\0'; return res; }
T1_Get_Private_Dict( T1_Parser parser, PSAux_Service psaux ) { FT_Stream stream = parser->stream; FT_Memory memory = parser->root.memory; FT_Error error = 0; FT_Long size; if ( parser->in_pfb ) { /* in the case of the PFB format, the private dictionary can be */ /* made of several segments. We thus first read the number of */ /* segments to compute the total size of the private dictionary */ /* then re-read them into memory. */ FT_Long start_pos = FT_STREAM_POS(); FT_UShort tag; parser->private_len = 0; for (;;) { error = read_pfb_tag( stream, &tag, &size ); if ( error ) goto Fail; if ( tag != 0x8002U ) break; parser->private_len += size; if ( FT_STREAM_SKIP( size ) ) goto Fail; } /* Check that we have a private dictionary there */ /* and allocate private dictionary buffer */ if ( parser->private_len == 0 ) { FT_ERROR(( "T1_Get_Private_Dict:" )); FT_ERROR(( " invalid private dictionary section\n" )); error = T1_Err_Invalid_File_Format; goto Fail; } if ( FT_STREAM_SEEK( start_pos ) || FT_ALLOC( parser->private_dict, parser->private_len ) ) goto Fail; parser->private_len = 0; for (;;) { error = read_pfb_tag( stream, &tag, &size ); if ( error || tag != 0x8002U ) { error = T1_Err_Ok; break; } if ( FT_STREAM_READ( parser->private_dict + parser->private_len, size ) ) goto Fail; parser->private_len += size; } } else { /* we have already `loaded' the whole PFA font file into memory; */ /* if this is a memory resource, allocate a new block to hold */ /* the private dict. Otherwise, simply overwrite into the base */ /* dictionary block in the heap. */ /* first of all, look at the `eexec' keyword */ FT_Byte* cur = parser->base_dict; FT_Byte* limit = cur + parser->base_len; FT_Byte c; for (;;) { c = cur[0]; if ( c == 'e' && cur + 9 < limit ) /* 9 = 5 letters for `eexec' + */ /* newline + 4 chars */ { if ( cur[1] == 'e' && cur[2] == 'x' && cur[3] == 'e' && cur[4] == 'c' ) { cur += 6; /* we skip the newling after the `eexec' */ /* XXX: Some fonts use DOS-linefeeds, i.e. \r\n; we need to */ /* skip the extra \n if we find it */ if ( cur[0] == '\n' ) cur++; break; } } cur++; if ( cur >= limit ) { FT_ERROR(( "T1_Get_Private_Dict:" )); FT_ERROR(( " could not find `eexec' keyword\n" )); error = T1_Err_Invalid_File_Format; goto Exit; } } /* now determine where to write the _encrypted_ binary private */ /* dictionary. We overwrite the base dictionary for disk-based */ /* resources and allocate a new block otherwise */ size = (FT_Long)( parser->base_len - ( cur - parser->base_dict ) ); if ( parser->in_memory ) { /* note that we allocate one more byte to put a terminating `0' */ if ( FT_ALLOC( parser->private_dict, size + 1 ) ) goto Fail; parser->private_len = size; } else { parser->single_block = 1; parser->private_dict = parser->base_dict; parser->private_len = size; parser->base_dict = 0; parser->base_len = 0; } /* now determine whether the private dictionary is encoded in binary */ /* or hexadecimal ASCII format -- decode it accordingly */ /* we need to access the next 4 bytes (after the final \r following */ /* the `eexec' keyword); if they all are hexadecimal digits, then */ /* we have a case of ASCII storage */ if ( ( hexa_value( cur[0] ) | hexa_value( cur[1] ) | hexa_value( cur[2] ) | hexa_value( cur[3] ) ) < 0 ) /* binary encoding -- `simply' copy the private dict */ FT_MEM_COPY( parser->private_dict, cur, size ); else { /* ASCII hexadecimal encoding */ FT_Byte* write; FT_Int count; write = parser->private_dict; count = 0; for ( ;cur < limit; cur++ ) { int hex1; /* check for newline */ if ( cur[0] == '\r' || cur[0] == '\n' ) continue; /* exit if we have a non-hexadecimal digit that isn't a newline */ hex1 = hexa_value( cur[0] ); if ( hex1 < 0 || cur + 1 >= limit ) break; /* otherwise, store byte */ *write++ = (FT_Byte)( ( hex1 << 4 ) | hexa_value( cur[1] ) ); count++; cur++; } /* put a safeguard */ parser->private_len = write - parser->private_dict; *write++ = 0; } } /* we now decrypt the encoded binary private dictionary */ psaux->t1_decrypt( parser->private_dict, parser->private_len, 55665U ); parser->root.base = parser->private_dict; parser->root.cursor = parser->private_dict; parser->root.limit = parser->root.cursor + parser->private_len; Fail: Exit: return error; }