12 #include "../misc/coding/coding.h" 16 #include "../../helper/string.h" 54 for (i=0;i<(int)(strlen(text));i++) {
81 file = fopen(FileName,
"rb");
89 i = fread(File->
Buffer+File->
Used,1,1000,file);
106 if (stat(FileName,&fileinfo) == 0) {
108 dbgprintf(NULL,
"File info read correctly\n");
119 unsigned char Line[2000];
126 if (strlen(Line) == 0)
break;
127 if (!strncmp(Line,Name,strlen(Name))) {
129 while (Line[Pos] == 0x20) Pos++;
130 strcpy(Value,Line+Pos);
142 dbgprintf(NULL,
"Vendor: \"%s\"\n",Vendor);
150 dbgprintf(NULL,
"JAR file URL: \"%s\"\n",JAR);
155 dbgprintf(NULL,
"JAR size: \"%s\"\n",Size2);
156 (*Size) = atoi(Size2);
159 dbgprintf(NULL,
"Version: \"%s\"\n",Version);
167 if (File->
Used > 2) {
168 if (memcmp(File->
Buffer,
"BM",2)==0) {
170 }
else if (memcmp(File->
Buffer,
"GIF",3)==0) {
172 }
else if (File->
Buffer[0] == 0x00 && File->
Buffer[1] == 0x00) {
174 }
else if (memcmp(File->
Buffer+1,
"PNG",3)==0) {
176 }
else if (File->
Buffer[0] == 0xFF && File->
Buffer[1] == 0xD8) {
178 }
else if (memcmp(File->
Buffer,
"MThd",4)==0) {
180 }
else if (File->
Buffer[0] == 0x00 && File->
Buffer[1] == 0x02) {
192 va_start(argp, format);
193 result = vsnprintf(Buffer + (*Pos), buff_len - *Pos - 1, format, argp);
199 result = snprintf(Buffer + (*Pos), buff_len - *Pos - 1,
"%c%c", 13, 10);
213 va_start(argp, format);
214 result = vsnprintf(Buffer + (*Pos), buff_len - *Pos - 1, format, argp);
229 error =
VC_Store(Buffer, buff_len, Pos,
"%s:", Start);
230 if (error !=
ERR_NONE)
return error;
233 "%04d%02d%02dT%02d%02d%02d%s",
245 error =
VC_Store(Buffer, buff_len, Pos,
"%s:", Start);
246 if (error !=
ERR_NONE)
return error;
257 char year[5]=
"", month[3]=
"", day[3]=
"", hour[3]=
"", minute[3]=
"", second[3]=
"";
262 if (sscanf(Buffer,
"%d-%d-%d", &dt->
Year, &dt->
Month, &dt->
Day) == 3) {
266 if (strlen(Buffer) < 8) {
270 strncpy(year, Buffer, 4);
271 strncpy(month, Buffer+4, 2);
272 strncpy(day, Buffer+6, 2);
273 dt->
Year = atoi(year);
274 dt->
Month = atoi(month);
277 if (Buffer[8] ==
'T') {
278 if (strlen(Buffer + 9) < 6)
return FALSE;
280 strncpy(hour, Buffer+9, 2);
281 strncpy(minute, Buffer+11, 2);
282 strncpy(second, Buffer+13, 2);
283 dt->
Hour = atoi(hour);
284 dt->
Minute = atoi(minute);
285 dt->
Second = atoi(second);
290 if (Buffer[15] ==
'Z') dt->
Timezone = 0;
315 unsigned char buff[200];
321 if (!strncmp(Buffer,buff,strlen(buff))) {
322 int lstart = strlen(Start);
323 int lvalue = strlen(Buffer)-(lstart+1);
324 strncpy(buff,Buffer+lstart+1,lvalue);
325 strncpy(buff+lvalue,
"\0",1);
326 if (sscanf(buff,
"%i",Value)) {
327 dbgprintf(NULL,
"ReadVCalInt is \"%i\"\n",*Value);
338 unsigned char datestring[200];
342 strcat(fullstart, Start);
343 strcat(fullstart,
";VALUE=DATE");
347 *is_date_only =
TRUE;
352 *is_date_only =
FALSE;
371 buffer = (
char *)malloc(len * 8);
376 error =
VC_StoreLine(Buffer, buff_len, Pos,
"%s:%s", Start, buffer);
381 error =
VC_StoreLine(Buffer, buff_len, Pos,
"%s:%s", Start, buffer);
383 error =
VC_StoreLine(Buffer, buff_len, Pos,
"%s;CHARSET=UTF-8;ENCODING=QUOTED-PRINTABLE:%s", Start, buffer);
394 char *buffer=NULL, *pos=NULL, linebuffer[80]={0};
395 size_t len=0, current=0;
403 buffer = (
char *)malloc(length * 2);
412 len = strlen(buffer);
417 current =
MIN(len, 76);
418 strncpy(linebuffer, pos, current);
419 linebuffer[current] = 0;
420 error =
VC_StoreLine(Buffer, buff_len, Pos,
"%s%s", spacer, linebuffer);
438 static unsigned char tmp[1000];
439 unsigned char *start;
442 while (Buff[*pos] != 0 || Buff[*pos + 1] != 0) {
443 if (Buff[*pos] == 0 && Buff[*pos + 1] ==
';') {
446 Buff[*pos + 1] =
';';
452 if (start == Buff || (start[0] == 0 && start[1] == 0))
return NULL;
471 char **tokens = NULL;
472 char *charset = NULL;
473 char *begin, *pos, *end, *end2;
475 size_t numtokens, token;
487 for (i = 0; i < len; i++) {
488 if (Start[i] ==
';') {
494 line = strdup(Start);
499 tokens = (
char **)malloc(
sizeof(
char *) * numtokens);
500 if (tokens == NULL) {
508 for (i = 0; i < len; i++) {
509 if (line[i] ==
';') {
510 tokens[token++] = begin;
511 begin = line + i + 1;
516 tokens[token] = begin;
520 len = strlen(tokens[0]);
521 if (strncasecmp(pos, tokens[0], len) != 0) {
529 if (location != NULL) {
534 while (*pos !=
':') {
538 dbgprintf(NULL,
"Could not parse! (stopped at string: %s)\n", pos);
542 for (token = 0; token < numtokens; token++) {
543 len = strlen(tokens[token]);
548 if (strncasecmp(pos, tokens[token], len) == 0) {
549 dbgprintf(NULL,
"Found %s\n", tokens[token]);
553 tokens[token][0] = 0;
559 if (strncasecmp(pos,
"ENCODING=QUOTED-PRINTABLE", 25) == 0) {
560 quoted_printable =
TRUE;
564 }
else if (strncasecmp(pos,
"CHARSET=", 8) == 0) {
568 end = strchr(pos,
':');
569 end2 = strchr(pos,
';');
570 if (end == NULL && end2 == NULL) {
571 dbgprintf(NULL,
"Could not read charset!\n");
573 }
else if (end == NULL) {
575 }
else if (end2 != NULL && end2 < end) {
579 charset = strdup(pos);
580 if (charset == NULL) {
584 charset[end - pos] = 0;
588 }
else if (strncasecmp(pos,
"TZID=", 5) == 0) {
593 end = strchr(pos,
':');
594 end2 = strchr(pos,
';');
595 if (end == NULL && end2 == NULL) {
596 dbgprintf(NULL,
"Could not read timezone!\n");
598 }
else if (end == NULL) {
600 }
else if (end2 != NULL && end2 < end) {
605 }
else if (strncasecmp(pos,
"TYPE=", 5) == 0) {
610 while (*pos !=
':' && *pos !=
';') {
614 for (token = 0; token < numtokens; token++) {
615 len = strlen(tokens[token]);
620 if (strncasecmp(pos, tokens[token], len) == 0) {
621 dbgprintf(NULL,
"Found %s\n", tokens[token]);
625 tokens[token][0] = 0;
632 if (strncasecmp(pos,
"PREF", 4) == 0) {
636 }
else if (strncasecmp(pos,
"WORK", 4) == 0) {
640 if (location != NULL) {
643 }
else if (strncasecmp(pos,
"HOME", 4) == 0) {
647 if (location != NULL) {
651 dbgprintf(NULL,
"%s not found! (%s)\n", Start, pos);
656 if (*pos ==
';' || *pos ==
':') {
657 dbgprintf(NULL,
"End of TYPE= string\n");
659 }
else if (*pos ==
',') {
663 dbgprintf(NULL,
"Could not parse TYPE=! (stopped at string: %s)\n", pos);
668 }
else if (strncasecmp(pos,
"PREF", 4) == 0) {
672 }
else if (location && strncasecmp(pos,
"WORK", 4) == 0) {
677 }
else if (location && strncasecmp(pos,
"HOME", 4) == 0) {
684 dbgprintf(NULL,
"%s not found!\n", Start);
695 for (token = 0; token < numtokens; token++) {
696 if (strlen(tokens[token]) > 0) {
697 dbgprintf(NULL,
"All tokens did not match!\n");
703 if (charset == NULL) {
704 if (quoted_printable) {
718 if (strcasecmp(charset,
"UTF-8") == 0||
719 strcasecmp(charset,
"\"UTF-8\"") == 0
721 if (quoted_printable) {
726 }
else if (strcasecmp(charset,
"UTF-7") == 0||
727 strcasecmp(charset,
"\"UTF-7\"") == 0
729 if (quoted_printable) {
730 dbgprintf(NULL,
"Unsupported charset: %s\n", charset);
736 dbgprintf(NULL,
"Unsupported charset: %s\n", charset);
743 for (i = 0; i < len; i++) {
744 if (Value[(2 * i)] == 0 && Value[(2 * i) + 1] ==
'\\') {
746 if (Value[(2 * j)] == 0 && (
747 Value[(2 * j) + 1] ==
'n' ||
748 Value[(2 * j) + 1] ==
'N')
750 Value[(2 * i) + 1] =
'\n';
751 }
else if (Value[(2 * j)] == 0 && (
752 Value[(2 * j) + 1] ==
'r' ||
753 Value[(2 * j) + 1] ==
'R')
755 Value[(2 * i) + 1] =
'\r';
756 }
else if (Value[(2 * j)] == 0 && Value[(2 * j) + 1] ==
'\\') {
757 Value[(2 * i) + 1] =
'\\';
758 }
else if (Value[(2 * j)] == 0 && Value[(2 * j) + 1] ==
';') {
759 Value[(2 * i) + 1] =
';';
760 }
else if (Value[(2 * j)] == 0 && Value[(2 * j) + 1] ==
',') {
761 Value[(2 * i) + 1] =
',';
767 memmove(Value + (2 * j), Value + (2 * j) + 2, 2 * (len + 1 - j));
char * DecodeUnicodeConsole(const unsigned char *src)
GSM_ChargeState ChargeState
char * DecodeUnicodeString(const unsigned char *src)
unsigned char * VCALGetTextPart(unsigned char *Buff, int *pos)
void CopyUnicodeString(unsigned char *Dest, const unsigned char *Source)
static struct keys_table_position Keys[]
char * OSDate(GSM_DateTime dt)
void DecodeISO88591QuotedPrintable(unsigned char *dest, const unsigned char *src, size_t len)
GSM_Error VC_StoreDateTime(char *Buffer, const size_t buff_len, size_t *Pos, const GSM_DateTime *Date, const char *Start)
void DecodeUTF7(unsigned char *dest, const unsigned char *src, size_t len)
GSM_Error VC_StoreText(char *Buffer, const size_t buff_len, size_t *Pos, const unsigned char *Text, const char *Start, const gboolean UTF8)
gboolean EncodeUTF8QuotedPrintable(char *dest, const unsigned char *src)
void EncodeBASE64(const unsigned char *Input, char *Output, const size_t Length)
size_t UnicodeLength(const unsigned char *str)
void DecodeISO88591(unsigned char *dest, const char *src, size_t len)
gboolean ReadVCALDate(char *Buffer, const char *Start, GSM_DateTime *Date, gboolean *is_date_only)
#define PRINTF_STYLE(f, a)
GSM_Error VC_StoreLine(char *Buffer, const size_t buff_len, size_t *Pos, const char *format,...)
gboolean ReadVCALDateTime(const char *Buffer, GSM_DateTime *dt)
void GSM_ClearBatteryCharge(GSM_BatteryCharge *bat)
GSM_Error VC_Store(char *Buffer, const size_t buff_len, size_t *Pos, const char *format,...)
static void GSM_JADFindLine(GSM_File *File, const char *Name, char *Value)
void Fill_GSM_DateTime(GSM_DateTime *Date, time_t timet)
gboolean ReadVCALInt(char *Buffer, const char *Start, int *Value)
void DecodeUTF8QuotedPrintable(unsigned char *dest, const char *src, size_t len)
GSM_Error VC_StoreBase64(char *Buffer, const size_t buff_len, size_t *Pos, const unsigned char *data, const size_t length)
void DecodeUTF8(unsigned char *dest, const char *src, size_t len)
gboolean CheckTime(GSM_DateTime *date)
GSM_Error GSM_ReadFile(const char *FileName, GSM_File *File)
gboolean ReadVCALText(char *Buffer, const char *Start, unsigned char *Value, const gboolean UTF8, GSM_EntryLocation *location)
time_t Fill_Time_T(GSM_DateTime DT)
void GSM_IdentifyFileFormat(GSM_File *File)
gboolean CheckDate(GSM_DateTime *date)
GSM_Error MyGetLine(char *Buffer, size_t *Pos, char *OutBuffer, size_t MaxLen, size_t MaxOutLen, gboolean MergeLines)
GSM_Error GSM_JADFindData(GSM_File *File, char *Vendor, char *Name, char *JAR, char *Version, int *Size)
GSM_Error VC_StoreDate(char *Buffer, const size_t buff_len, size_t *Pos, const GSM_DateTime *Date, const char *Start)
GSM_BatteryType BatteryType
GSM_Error MakeKeySequence(char *text, GSM_KeyCode *KeyCode, size_t *Length)