author | zecke <zecke> | 2003-08-29 18:02:09 (UTC) |
---|---|---|
committer | zecke <zecke> | 2003-08-29 18:02:09 (UTC) |
commit | 885c645ee48ae53467e244521c011c73bc106afb (patch) (unidiff) | |
tree | 9024be25b2503788d3aa77b7a86b89e543cdd865 /library/backend/vcc.y | |
parent | ed6da2303a8fabec50991365914f0e4d20a21ea6 (diff) | |
download | opie-885c645ee48ae53467e244521c011c73bc106afb.zip opie-885c645ee48ae53467e244521c011c73bc106afb.tar.gz opie-885c645ee48ae53467e244521c011c73bc106afb.tar.bz2 |
Fixes for base64 decoding and encoding of vCard
-rw-r--r-- | library/backend/vcc.y | 29 |
1 files changed, 14 insertions, 15 deletions
diff --git a/library/backend/vcc.y b/library/backend/vcc.y index 4c79368..bec2955 100644 --- a/library/backend/vcc.y +++ b/library/backend/vcc.y | |||
@@ -440,9 +440,9 @@ static void enterProps(const char *s) | |||
440 | } | 440 | } |
441 | 441 | ||
442 | static void enterAttr(const char *s1, const char *s2) | 442 | static void enterAttr(const char *s1, const char *s2) |
443 | { | 443 | { |
444 | const char *p1, *p2; | 444 | const char *p1, *p2=0; |
445 | p1 = lookupProp_(s1); | 445 | p1 = lookupProp_(s1); |
446 | if (s2) { | 446 | if (s2) { |
447 | VObject *a; | 447 | VObject *a; |
448 | p2 = lookupProp_(s2); | 448 | p2 = lookupProp_(s2); |
@@ -812,9 +812,9 @@ static void finiLex() { | |||
812 | /*-----------------------------------*/ | 812 | /*-----------------------------------*/ |
813 | /* This parses and converts the base64 format for binary encoding into | 813 | /* This parses and converts the base64 format for binary encoding into |
814 | * a decoded buffer (allocated with new). See RFC 1521. | 814 | * a decoded buffer (allocated with new). See RFC 1521. |
815 | */ | 815 | */ |
816 | static char * lexGetDataFromBase64() | 816 | static int lexGetDataFromBase64() |
817 | { | 817 | { |
818 | unsigned long bytesLen = 0, bytesMax = 0; | 818 | unsigned long bytesLen = 0, bytesMax = 0; |
819 | int quadIx = 0, pad = 0; | 819 | int quadIx = 0, pad = 0; |
820 | unsigned long trip = 0; | 820 | unsigned long trip = 0; |
@@ -825,8 +825,9 @@ static char * lexGetDataFromBase64() | |||
825 | 825 | ||
826 | DBG_(("db: lexGetDataFromBase64\n")); | 826 | DBG_(("db: lexGetDataFromBase64\n")); |
827 | while (1) { | 827 | while (1) { |
828 | c = lexGetc(); | 828 | c = lexGetc(); |
829 | lexSkipWhite(); | ||
829 | if (c == '\n') { | 830 | if (c == '\n') { |
830 | ++mime_lineNum; | 831 | ++mime_lineNum; |
831 | if (lexLookahead() == '\n') { | 832 | if (lexLookahead() == '\n') { |
832 | /* a '\n' character by itself means end of data */ | 833 | /* a '\n' character by itself means end of data */ |
@@ -847,26 +848,27 @@ static char * lexGetDataFromBase64() | |||
847 | b = 63; | 848 | b = 63; |
848 | else if (c == '=') { | 849 | else if (c == '=') { |
849 | b = 0; | 850 | b = 0; |
850 | pad++; | 851 | pad++; |
851 | } else if ((c == ' ') || (c == '\t')) { | ||
852 | continue; | ||
853 | } else { /* error condition */ | 852 | } else { /* error condition */ |
854 | if (bytes) free(bytes); | 853 | if (bytes) free(bytes); |
855 | else if (oldBytes) free(oldBytes); | 854 | else if (oldBytes) free(oldBytes); |
856 | // error recovery: skip until 2 adjacent newlines. | 855 | // error recovery: skip until 2 adjacent newlines. |
857 | DBG_(("db: invalid character 0x%x '%c'\n", c,c)); | 856 | DBG_(("db: invalid character 0x%x '%c'\n", c,c)); |
858 | if (c != EOF) { | 857 | if (c != EOF) { |
859 | c = lexGetc(); | 858 | c = lexGetc(); |
860 | while (c != EOF) { | 859 | while (c != EOF) { |
861 | if (c == '\n' && lexLookahead() == '\n') { | 860 | if (c == '\n') { |
862 | ++mime_lineNum; | 861 | lexSkipWhite(); |
863 | break; | 862 | if(lexLookahead() == '\n') { |
863 | ++mime_lineNum; | ||
864 | break; | ||
865 | } | ||
864 | } | 866 | } |
865 | c = lexGetc(); | 867 | c = lexGetc(); |
866 | } | 868 | } |
867 | } | 869 | } |
868 | return NULL; | 870 | return c != EOF; |
869 | } | 871 | } |
870 | trip = (trip << 6) | b; | 872 | trip = (trip << 6) | b; |
871 | if (++quadIx == 4) { | 873 | if (++quadIx == 4) { |
872 | unsigned char outBytes[3]; | 874 | unsigned char outBytes[3]; |
@@ -910,9 +912,9 @@ static char * lexGetDataFromBase64() | |||
910 | else if (oldBytes) { | 912 | else if (oldBytes) { |
911 | setValueWithSize(curProp,oldBytes,(unsigned int)bytesLen); | 913 | setValueWithSize(curProp,oldBytes,(unsigned int)bytesLen); |
912 | free(oldBytes); | 914 | free(oldBytes); |
913 | } | 915 | } |
914 | return 0; | 916 | return bytesLen; |
915 | } | 917 | } |
916 | 918 | ||
917 | static int match_begin_end_name(int end) { | 919 | static int match_begin_end_name(int end) { |
918 | int token; | 920 | int token; |
@@ -941,9 +943,9 @@ static char* lexGetQuotedPrintable() | |||
941 | lexSkipWhite(); | 943 | lexSkipWhite(); |
942 | c = lexLookahead(); | 944 | c = lexLookahead(); |
943 | lexClearToken(); | 945 | lexClearToken(); |
944 | 946 | ||
945 | while (c != EOF && c != ';') { | 947 | while (c != EOF && (c != ';' || !fieldedProp)) { |
946 | if (c == '\n') { | 948 | if (c == '\n') { |
947 | // break, leave '\n' on remaining chars. | 949 | // break, leave '\n' on remaining chars. |
948 | break; | 950 | break; |
949 | } else if (c == '=') { | 951 | } else if (c == '=') { |
@@ -1031,13 +1033,10 @@ static int yylex() { | |||
1031 | char *p = 0; | 1033 | char *p = 0; |
1032 | lexPushLookaheadc(c); | 1034 | lexPushLookaheadc(c); |
1033 | if (lexWithinMode(L_BASE64)) { | 1035 | if (lexWithinMode(L_BASE64)) { |
1034 | /* get each char and convert to bin on the fly... */ | 1036 | /* get each char and convert to bin on the fly... */ |
1035 | p = lexGetDataFromBase64(); | 1037 | yylval.str = NULL; |
1036 | #if 0 | 1038 | return lexGetDataFromBase64() ? STRING : 0; |
1037 | yylval.str = p; | ||
1038 | return STRING; | ||
1039 | #endif | ||
1040 | } | 1039 | } |
1041 | else if (lexWithinMode(L_QUOTED_PRINTABLE)) { | 1040 | else if (lexWithinMode(L_QUOTED_PRINTABLE)) { |
1042 | p = lexGetQuotedPrintable(); | 1041 | p = lexGetQuotedPrintable(); |
1043 | } | 1042 | } |