author | eilers <eilers> | 2002-12-09 15:32:16 (UTC) |
---|---|---|
committer | eilers <eilers> | 2002-12-09 15:32:16 (UTC) |
commit | 9aa2442f6ea4e0d58fa7888995ebad04b3692049 (patch) (unidiff) | |
tree | f0a4340cf9178868e5c8d05df69a3d0d0fa12756 | |
parent | b0a600bf9dd32b908d79c2cf1f12b8088dc2590d (diff) | |
download | opie-9aa2442f6ea4e0d58fa7888995ebad04b3692049.zip opie-9aa2442f6ea4e0d58fa7888995ebad04b3692049.tar.gz opie-9aa2442f6ea4e0d58fa7888995ebad04b3692049.tar.bz2 |
Temorarely bug workaround ( #490 ) until trolltech publishing a bugfix !
-rw-r--r-- | library/backend/vobject.cpp | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/library/backend/vobject.cpp b/library/backend/vobject.cpp index 2f22c20..2c5b577 100644 --- a/library/backend/vobject.cpp +++ b/library/backend/vobject.cpp | |||
@@ -968,190 +968,216 @@ static int writeBase64(OFile *fp, unsigned char *s, long len) | |||
968 | long cur = 0; | 968 | long cur = 0; |
969 | int i, numQuads = 0; | 969 | int i, numQuads = 0; |
970 | unsigned long trip; | 970 | unsigned long trip; |
971 | unsigned char b; | 971 | unsigned char b; |
972 | char quad[5]; | 972 | char quad[5]; |
973 | #define MAXQUADS 16 | 973 | #define MAXQUADS 16 |
974 | 974 | ||
975 | quad[4] = 0; | 975 | quad[4] = 0; |
976 | 976 | ||
977 | while (cur < len) { | 977 | while (cur < len) { |
978 | // collect the triplet of bytes into 'trip' | 978 | // collect the triplet of bytes into 'trip' |
979 | trip = 0; | 979 | trip = 0; |
980 | for (i = 0; i < 3; i++) { | 980 | for (i = 0; i < 3; i++) { |
981 | b = (cur < len) ? *(s + cur) : 0; | 981 | b = (cur < len) ? *(s + cur) : 0; |
982 | cur++; | 982 | cur++; |
983 | trip = trip << 8 | b; | 983 | trip = trip << 8 | b; |
984 | } | 984 | } |
985 | // fill in 'quad' with the appropriate four characters | 985 | // fill in 'quad' with the appropriate four characters |
986 | for (i = 3; i >= 0; i--) { | 986 | for (i = 3; i >= 0; i--) { |
987 | b = (unsigned char)(trip & 0x3F); | 987 | b = (unsigned char)(trip & 0x3F); |
988 | trip = trip >> 6; | 988 | trip = trip >> 6; |
989 | if ((3 - i) < (cur - len)) | 989 | if ((3 - i) < (cur - len)) |
990 | quad[i] = '='; // pad char | 990 | quad[i] = '='; // pad char |
991 | else if (b < 26) quad[i] = (char)b + 'A'; | 991 | else if (b < 26) quad[i] = (char)b + 'A'; |
992 | else if (b < 52) quad[i] = (char)(b - 26) + 'a'; | 992 | else if (b < 52) quad[i] = (char)(b - 26) + 'a'; |
993 | else if (b < 62) quad[i] = (char)(b - 52) + '0'; | 993 | else if (b < 62) quad[i] = (char)(b - 52) + '0'; |
994 | else if (b == 62) quad[i] = '+'; | 994 | else if (b == 62) quad[i] = '+'; |
995 | else quad[i] = '/'; | 995 | else quad[i] = '/'; |
996 | } | 996 | } |
997 | // now output 'quad' with appropriate whitespace and line ending | 997 | // now output 'quad' with appropriate whitespace and line ending |
998 | appendsOFile(fp, (numQuads == 0 ? " " : "")); | 998 | appendsOFile(fp, (numQuads == 0 ? " " : "")); |
999 | appendsOFile(fp, quad); | 999 | appendsOFile(fp, quad); |
1000 | appendsOFile(fp, ((cur >= len)?"\n" :(numQuads==MAXQUADS-1?"\n" : ""))); | 1000 | appendsOFile(fp, ((cur >= len)?"\n" :(numQuads==MAXQUADS-1?"\n" : ""))); |
1001 | numQuads = (numQuads + 1) % MAXQUADS; | 1001 | numQuads = (numQuads + 1) % MAXQUADS; |
1002 | } | 1002 | } |
1003 | appendcOFile(fp,'\n'); | 1003 | appendcOFile(fp,'\n'); |
1004 | 1004 | ||
1005 | return 1; | 1005 | return 1; |
1006 | } | 1006 | } |
1007 | 1007 | ||
1008 | static const char *replaceChar(unsigned char c) | 1008 | static const char *replaceChar(unsigned char c) |
1009 | { | 1009 | { |
1010 | if (c == '\n') { | 1010 | if (c == '\n') { |
1011 | return "=0A=\n"; | 1011 | return "=0A=\n"; |
1012 | } else if ( | 1012 | } else if ( |
1013 | (c >= 'A' && c <= 'Z') | 1013 | (c >= 'A' && c <= 'Z') |
1014 | || | 1014 | || |
1015 | (c >= 'a' && c <= 'z') | 1015 | (c >= 'a' && c <= 'z') |
1016 | || | 1016 | || |
1017 | (c >= '0' && c <= '9') | 1017 | (c >= '0' && c <= '9') |
1018 | || | 1018 | || |
1019 | (c >= '\'' && c <= ')') | 1019 | (c >= '\'' && c <= ')') |
1020 | || | 1020 | || |
1021 | (c >= '+' && c <= '-') | 1021 | (c >= '+' && c <= '-') |
1022 | || | 1022 | || |
1023 | (c == '/') | 1023 | (c == '/') |
1024 | || | 1024 | || |
1025 | (c == '?') | 1025 | (c == '?') |
1026 | || | 1026 | || |
1027 | (c == ' ')) | 1027 | (c == ' ')) |
1028 | { | 1028 | { |
1029 | return 0; | 1029 | return 0; |
1030 | } | 1030 | } |
1031 | 1031 | ||
1032 | #warning "Bug-Workaround must be fixed !" | ||
1033 | // IF THIS FUNCTION RETURNES TRUE, THE DATA IS EXPORTED | ||
1034 | // AS QUOTED PRINTABLE. | ||
1035 | // BUT THE PARSER IS UNABLE TO IMPORT THIS, THEREFORE | ||
1036 | // I DECIDED TO DISABLE IT UNTIL TROLLTECH FIXES THIS BUG | ||
1037 | // SEE ALSO includesUnprintable(VObject *o) | ||
1038 | // (se) | ||
1039 | |||
1040 | return 0; | ||
1041 | |||
1042 | #if 0 | ||
1032 | static char trans[4]; | 1043 | static char trans[4]; |
1033 | trans[0] = '='; | 1044 | trans[0] = '='; |
1034 | trans[3] = '\0'; | 1045 | trans[3] = '\0'; |
1035 | int rem = c % 16; | 1046 | int rem = c % 16; |
1036 | int div = c / 16; | 1047 | int div = c / 16; |
1037 | 1048 | ||
1038 | if (div < 10) | 1049 | if (div < 10) |
1039 | trans[1] = '0' + div; | 1050 | trans[1] = '0' + div; |
1040 | else | 1051 | else |
1041 | trans[1] = 'A' + (div - 10); | 1052 | trans[1] = 'A' + (div - 10); |
1042 | 1053 | ||
1043 | if (rem < 10) | 1054 | if (rem < 10) |
1044 | trans[2] = '0' + rem; | 1055 | trans[2] = '0' + rem; |
1045 | else | 1056 | else |
1046 | trans[2] = 'A' + (rem - 10); | 1057 | trans[2] = 'A' + (rem - 10); |
1047 | 1058 | ||
1048 | return trans; | 1059 | return trans; |
1060 | #endif | ||
1049 | } | 1061 | } |
1050 | 1062 | ||
1051 | static void writeQPString(OFile *fp, const char *s) | 1063 | static void writeQPString(OFile *fp, const char *s) |
1052 | { | 1064 | { |
1053 | /* | 1065 | /* |
1054 | only A-Z, 0-9 and | 1066 | only A-Z, 0-9 and |
1055 | "'" (ASCII code 39) | 1067 | "'" (ASCII code 39) |
1056 | "(" (ASCII code 40) | 1068 | "(" (ASCII code 40) |
1057 | ")" (ASCII code 41) | 1069 | ")" (ASCII code 41) |
1058 | "+" (ASCII code 43) | 1070 | "+" (ASCII code 43) |
1059 | "," (ASCII code 44) | 1071 | "," (ASCII code 44) |
1060 | "-" (ASCII code 45) | 1072 | "-" (ASCII code 45) |
1061 | "/" (ASCII code 47) | 1073 | "/" (ASCII code 47) |
1062 | "?" (ASCII code 63) | 1074 | "?" (ASCII code 63) |
1063 | 1075 | ||
1064 | should remain un-encoded. | 1076 | should remain un-encoded. |
1065 | '=' needs to be encoded as it is the escape character. | 1077 | '=' needs to be encoded as it is the escape character. |
1066 | ';' needs to be as it is a field separator. | 1078 | ';' needs to be as it is a field separator. |
1067 | 1079 | ||
1068 | */ | 1080 | */ |
1069 | const char *p = s; | 1081 | const char *p = s; |
1070 | while (*p) { | 1082 | while (*p) { |
1071 | const char *rep = replaceChar(*p); | 1083 | const char *rep = replaceChar(*p); |
1072 | if (rep) | 1084 | if (rep) |
1073 | appendsOFile(fp, rep); | 1085 | appendsOFile(fp, rep); |
1074 | else | 1086 | else |
1075 | appendcOFile(fp, *p); | 1087 | appendcOFile(fp, *p); |
1076 | p++; | 1088 | p++; |
1077 | } | 1089 | } |
1078 | } | 1090 | } |
1079 | 1091 | ||
1080 | static bool includesUnprintable(VObject *o) | 1092 | static bool includesUnprintable(VObject *o) |
1081 | { | 1093 | { |
1094 | |||
1095 | #if 0 | ||
1096 | |||
1097 | // IF THIS FUNCTION RETURNES TRUE, THE DATA IS EXPORTED | ||
1098 | // AS QUOTED PRINTABLE. | ||
1099 | // BUT THE PARSER IS UNABLE TO IMPORT THIS, THEREFORE | ||
1100 | // I DECIDED TO DISABLE IT UNTIL TROLLTECH FIXES THIS BUG | ||
1101 | // SEE ALSO *replaceChar(unsigned char c) | ||
1102 | // (se) | ||
1103 | |||
1082 | if (o) { | 1104 | if (o) { |
1083 | if (VALUE_TYPE(o) == VCVT_STRINGZ) { | 1105 | if (VALUE_TYPE(o) == VCVT_STRINGZ) { |
1084 | const char *p = STRINGZ_VALUE_OF(o); | 1106 | const char *p = STRINGZ_VALUE_OF(o); |
1085 | if (p) { | 1107 | if (p) { |
1086 | while (*p) { | 1108 | while (*p) { |
1087 | if (replaceChar(*p)) | 1109 | if (replaceChar(*p)) |
1088 | return TRUE; | 1110 | return TRUE; |
1089 | p++; | 1111 | p++; |
1090 | } | 1112 | } |
1091 | } | 1113 | } |
1092 | } | 1114 | } |
1093 | } | 1115 | } |
1116 | |||
1117 | #endif | ||
1118 | #warning "Bug-Workaround must be fixed !" | ||
1119 | |||
1094 | return FALSE; | 1120 | return FALSE; |
1095 | } | 1121 | } |
1096 | 1122 | ||
1097 | static void writeVObject_(OFile *fp, VObject *o); | 1123 | static void writeVObject_(OFile *fp, VObject *o); |
1098 | 1124 | ||
1099 | static void writeValue(OFile *fp, VObject *o, unsigned long size) | 1125 | static void writeValue(OFile *fp, VObject *o, unsigned long size) |
1100 | { | 1126 | { |
1101 | if (o == 0) return; | 1127 | if (o == 0) return; |
1102 | switch (VALUE_TYPE(o)) { | 1128 | switch (VALUE_TYPE(o)) { |
1103 | case VCVT_STRINGZ: { | 1129 | case VCVT_STRINGZ: { |
1104 | writeQPString(fp, STRINGZ_VALUE_OF(o)); | 1130 | writeQPString(fp, STRINGZ_VALUE_OF(o)); |
1105 | break; | 1131 | break; |
1106 | } | 1132 | } |
1107 | case VCVT_UINT: { | 1133 | case VCVT_UINT: { |
1108 | char buf[16]; | 1134 | char buf[16]; |
1109 | sprintf(buf,"%u", INTEGER_VALUE_OF(o)); | 1135 | sprintf(buf,"%u", INTEGER_VALUE_OF(o)); |
1110 | appendsOFile(fp,buf); | 1136 | appendsOFile(fp,buf); |
1111 | break; | 1137 | break; |
1112 | } | 1138 | } |
1113 | case VCVT_ULONG: { | 1139 | case VCVT_ULONG: { |
1114 | char buf[16]; | 1140 | char buf[16]; |
1115 | sprintf(buf,"%lu", LONG_VALUE_OF(o)); | 1141 | sprintf(buf,"%lu", LONG_VALUE_OF(o)); |
1116 | appendsOFile(fp,buf); | 1142 | appendsOFile(fp,buf); |
1117 | break; | 1143 | break; |
1118 | } | 1144 | } |
1119 | case VCVT_RAW: { | 1145 | case VCVT_RAW: { |
1120 | appendcOFile(fp,'\n'); | 1146 | appendcOFile(fp,'\n'); |
1121 | writeBase64(fp,(unsigned char*)(ANY_VALUE_OF(o)),size); | 1147 | writeBase64(fp,(unsigned char*)(ANY_VALUE_OF(o)),size); |
1122 | break; | 1148 | break; |
1123 | } | 1149 | } |
1124 | case VCVT_VOBJECT: | 1150 | case VCVT_VOBJECT: |
1125 | appendcOFile(fp,'\n'); | 1151 | appendcOFile(fp,'\n'); |
1126 | writeVObject_(fp,VOBJECT_VALUE_OF(o)); | 1152 | writeVObject_(fp,VOBJECT_VALUE_OF(o)); |
1127 | break; | 1153 | break; |
1128 | } | 1154 | } |
1129 | } | 1155 | } |
1130 | 1156 | ||
1131 | static void writeAttrValue(OFile *fp, VObject *o) | 1157 | static void writeAttrValue(OFile *fp, VObject *o) |
1132 | { | 1158 | { |
1133 | if (NAME_OF(o)) { | 1159 | if (NAME_OF(o)) { |
1134 | struct PreDefProp *pi; | 1160 | struct PreDefProp *pi; |
1135 | pi = lookupPropInfo(NAME_OF(o)); | 1161 | pi = lookupPropInfo(NAME_OF(o)); |
1136 | if (pi && ((pi->flags & PD_INTERNAL) != 0)) return; | 1162 | if (pi && ((pi->flags & PD_INTERNAL) != 0)) return; |
1137 | if ( includesUnprintable(o) ) { | 1163 | if ( includesUnprintable(o) ) { |
1138 | appendsOFile(fp, ";" VCEncodingProp "=" VCQuotedPrintableProp); | 1164 | appendsOFile(fp, ";" VCEncodingProp "=" VCQuotedPrintableProp); |
1139 | appendsOFile(fp, ";" VCCharSetProp "=" "UTF-8"); | 1165 | appendsOFile(fp, ";" VCCharSetProp "=" "UTF-8"); |
1140 | } | 1166 | } |
1141 | appendcOFile(fp,';'); | 1167 | appendcOFile(fp,';'); |
1142 | appendsOFile(fp,NAME_OF(o)); | 1168 | appendsOFile(fp,NAME_OF(o)); |
1143 | } | 1169 | } |
1144 | else | 1170 | else |
1145 | appendcOFile(fp,';'); | 1171 | appendcOFile(fp,';'); |
1146 | if (VALUE_TYPE(o)) { | 1172 | if (VALUE_TYPE(o)) { |
1147 | appendcOFile(fp,'='); | 1173 | appendcOFile(fp,'='); |
1148 | writeValue(fp,o,0); | 1174 | writeValue(fp,o,0); |
1149 | } | 1175 | } |
1150 | } | 1176 | } |
1151 | 1177 | ||
1152 | static void writeGroup(OFile *fp, VObject *o) | 1178 | static void writeGroup(OFile *fp, VObject *o) |
1153 | { | 1179 | { |
1154 | char buf1[256]; | 1180 | char buf1[256]; |
1155 | char buf2[256]; | 1181 | char buf2[256]; |
1156 | strcpy(buf1,NAME_OF(o)); | 1182 | strcpy(buf1,NAME_OF(o)); |
1157 | while ((o=isAPropertyOf(o,VCGroupingProp)) != 0) { | 1183 | while ((o=isAPropertyOf(o,VCGroupingProp)) != 0) { |