From: <svn...@op...> - 2009-03-05 14:20:59
|
Author: bellmich Date: Thu Mar 5 15:20:53 2009 New Revision: 194 URL: http://libwbxml.opensync.org/changeset/194 Log: corrected the byte order of the WV datetime encoding Modified: wbxml2/trunk/src/wbxml_encoder.c wbxml2/trunk/src/wbxml_parser.c Modified: wbxml2/trunk/src/wbxml_encoder.c ============================================================================== --- wbxml2/trunk/src/wbxml_encoder.c Thu Mar 5 15:16:21 2009 (r193) +++ wbxml2/trunk/src/wbxml_encoder.c Thu Mar 5 15:20:53 2009 (r194) @@ -3179,8 +3179,8 @@ wbxml_buffer_delete(component, 4, 10); unsigned int year = strtoull((const char *)wbxml_buffer_get_cstr(component), NULL, 10); wbxml_buffer_destroy(component); - octets[5] = (WB_UTINY) ((year & 0xfc0) >> 6); /* 6 bits */ - octets[4] = (WB_UTINY) (year & 0x3f); /* 6 bits */ + octets[0] = (WB_UTINY) ((year & 0xfc0) >> 6); /* 6 bits */ + octets[1] = (WB_UTINY) (year & 0x3f); /* 6 bits */ /* Set Month */ component = wbxml_buffer_duplicate(tmp); @@ -3192,9 +3192,9 @@ wbxml_buffer_delete(component, 2, 8); unsigned int month = strtoull((const char *)wbxml_buffer_get_cstr(component), NULL, 10); wbxml_buffer_destroy(component); - octets[4] <<= 2; - octets[4] += (WB_UTINY) ((month & 0xc) >> 2); /* 2 bits */ - octets[3] = (WB_UTINY) (month & 0x3); /* 2 bits */ + octets[1] <<= 2; + octets[1] += (WB_UTINY) ((month & 0xc) >> 2); /* 2 bits */ + octets[2] = (WB_UTINY) (month & 0x3); /* 2 bits */ /* Set Day */ component = wbxml_buffer_duplicate(tmp); @@ -3206,8 +3206,8 @@ wbxml_buffer_delete(component, 2, 6); unsigned int day = strtoull((const char *)wbxml_buffer_get_cstr(component), NULL, 10); wbxml_buffer_destroy(component); - octets[3] <<= 5; - octets[3] += (WB_UTINY) (day & 0x1f); /* 5 bits */ + octets[2] <<= 5; + octets[2] += (WB_UTINY) (day & 0x1f); /* 5 bits */ /* Set Hour */ component = wbxml_buffer_duplicate(tmp); @@ -3219,9 +3219,9 @@ wbxml_buffer_delete(component, 2, 4); unsigned int hour = strtoull((const char *)wbxml_buffer_get_cstr(component), NULL, 10); wbxml_buffer_destroy(component); - octets[3] <<=1; - octets[3] += (WB_UTINY) ((hour & 0x10) >> 4); /* 1 bit */ - octets[2] = (WB_UTINY) (hour & 0xf); /* 4 bits */ + octets[2] <<=1; + octets[2] += (WB_UTINY) ((hour & 0x10) >> 4); /* 1 bit */ + octets[3] = (WB_UTINY) (hour & 0xf); /* 4 bits */ /* Set Minute */ component = wbxml_buffer_duplicate(tmp); @@ -3233,9 +3233,9 @@ wbxml_buffer_delete(component, 2, 2); unsigned int minute = strtoull((const char *)wbxml_buffer_get_cstr(component), NULL, 10); wbxml_buffer_destroy(component); - octets[2] <<=4; - octets[2] += (WB_UTINY) ((minute & 0x3c) >> 2); /* 4 bits */ - octets[1] = (WB_UTINY) (minute & 0x3); /* 2 bits */ + octets[3] <<=4; + octets[3] += (WB_UTINY) ((minute & 0x3c) >> 2); /* 4 bits */ + octets[4] = (WB_UTINY) (minute & 0x3); /* 2 bits */ /* Set Second */ component = wbxml_buffer_duplicate(tmp); @@ -3246,11 +3246,11 @@ wbxml_buffer_delete(component, 0, 12); unsigned int second = strtoull((const char *)wbxml_buffer_get_cstr(component), NULL, 10); wbxml_buffer_destroy(component); - octets[1] <<=6; - octets[1] += (WB_UTINY) (second & 0x3f); /* 6 bits */ + octets[4] <<=6; + octets[4] += (WB_UTINY) (second & 0x3f); /* 6 bits */ /* Set Time Zone */ - octets[0] = 0; + octets[5] = 0; WBXML_DEBUG((WBXML_CONV, "WV datetime: %x %x %x %x %x %x", octets[5], octets[4], octets[3], octets[2], octets[1], octets[0])); Modified: wbxml2/trunk/src/wbxml_parser.c ============================================================================== --- wbxml2/trunk/src/wbxml_parser.c Thu Mar 5 15:16:21 2009 (r193) +++ wbxml2/trunk/src/wbxml_parser.c Thu Mar 5 15:20:53 2009 (r194) @@ -2772,40 +2772,40 @@ data_ptr = wbxml_buffer_get_cstr(*data); /* Get Year */ - the_value = (WB_ULONG) (((data_ptr[5] & 0x3F) << 6) + ((data_ptr[4] >> 2) & 0x3F)); + the_value = (WB_ULONG) (((data_ptr[0] & 0x3F) << 6) + ((data_ptr[1] >> 2) & 0x3F)); sprintf(the_year, "%u", the_value); /* Get Month */ - the_value = (WB_ULONG) (((data_ptr[4] & 0x03) << 2) | ((data_ptr[3] >> 6) & 0x03)); + the_value = (WB_ULONG) (((data_ptr[1] & 0x03) << 2) | ((data_ptr[2] >> 6) & 0x03)); sprintf(the_month, "%02u", the_value); /* Get Day */ - the_value = (WB_ULONG) ((data_ptr[3] >> 1) & 0x1F); + the_value = (WB_ULONG) ((data_ptr[2] >> 1) & 0x1F); sprintf(the_date, "%02u", the_value); /* Get Hour */ - the_value = (WB_ULONG) (((data_ptr[3] & 0x01) << 4) | ((data_ptr[2] >> 4) & 0x0F)); + the_value = (WB_ULONG) (((data_ptr[2] & 0x01) << 4) | ((data_ptr[3] >> 4) & 0x0F)); sprintf(the_hour, "%02u", the_value); /* Get Minute */ - the_value = (WB_ULONG) (((data_ptr[2] & 0x0F) << 2) | ((data_ptr[1] >> 6) & 0x03)); + the_value = (WB_ULONG) (((data_ptr[3] & 0x0F) << 2) | ((data_ptr[4] >> 6) & 0x03)); sprintf(the_minute, "%02u", the_value); /* Get Second */ - the_value = (WB_ULONG) (data_ptr[1] & 0x3F); + the_value = (WB_ULONG) (data_ptr[4] & 0x3F); sprintf(the_second, "%02u", the_value); /* Get Time Zone */ - if (data_ptr[0] == 0) { + if (data_ptr[5] == 0) { /* This is a bug in the WBXML document. * If timezone UTC aka Zulu is used then a 'Z' must be set. */ sprintf((WB_TINY *) result, "%s%s%sT%s%s%sZ", the_year, the_month, the_date, the_hour, the_minute, the_value ? the_second : ""); - } else if (data_ptr[0] < 'A' || - data_ptr[0] > 'Z' || - data_ptr[0] == 'J') + } else if (data_ptr[5] < 'A' || + data_ptr[5] > 'Z' || + data_ptr[5] == 'J') { /* This is a bug in the WBXML document. * The timezone byte is set and wrong. @@ -2819,7 +2819,7 @@ else { sprintf((WB_TINY *) result, "%s%s%sT%s%s%s%c", - the_year, the_month, the_date, the_hour, the_minute, the_value ? the_second : "", data_ptr[0]); + the_year, the_month, the_date, the_hour, the_minute, the_value ? the_second : "", data_ptr[5]); } /* Reset buffer */ |