From: <dg...@su...> - 2009-01-19 17:40:35
|
Author: bellmich Date: Mon Jan 19 18:39:33 2009 New Revision: 173 URL: http://libwbxml.opensync.org/changeset/173 Log: fixed the datetime support for Wireless Village 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 Mon Jan 19 17:06:49 2009 (r172) +++ wbxml2/trunk/src/wbxml_encoder.c Mon Jan 19 18:39:33 2009 (r173) @@ -3155,9 +3155,9 @@ i++; } - WBXML_DEBUG((WBXML_CONV, "Starting WV datatime conversion ...")); + WBXML_DEBUG((WBXML_CONV, "Starting WV datetime conversion ...")); - /* Set Year - 10000000000 too long */ + /* Set Year */ component = wbxml_buffer_duplicate(tmp); if (!component) { error = WBXML_ERROR_NOT_ENOUGH_MEMORY; @@ -3166,7 +3166,7 @@ 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 bits */ + octets[5] = (WB_UTINY) ((year & 0xfc0) >> 6); /* 6 bits */ octets[4] = (WB_UTINY) (year & 0x3f); /* 6 bits */ /* Set Month */ @@ -3180,7 +3180,7 @@ 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 bits */ + octets[4] += (WB_UTINY) ((month & 0xc) >> 2); /* 2 bits */ octets[3] = (WB_UTINY) (month & 0x3); /* 2 bits */ /* Set Day */ @@ -3207,8 +3207,8 @@ 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 & 0x1); /* 1 bit */ - octets[2] = (WB_UTINY) (hour & 0x1e); /* 4 bits */ + octets[3] += (WB_UTINY) ((hour & 0x10) >> 4); /* 1 bit */ + octets[2] = (WB_UTINY) (hour & 0xf); /* 4 bits */ /* Set Minute */ component = wbxml_buffer_duplicate(tmp); @@ -3221,7 +3221,7 @@ 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); /* 4 bits */ + octets[2] += (WB_UTINY) ((minute & 0x3c) >> 2); /* 4 bits */ octets[1] = (WB_UTINY) (minute & 0x3); /* 2 bits */ /* Set Second */ @@ -3233,12 +3233,14 @@ 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] <<=4; + octets[1] <<=6; octets[1] += (WB_UTINY) (second & 0x3f); /* 6 bits */ /* Set Time Zone */ octets[0] = 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])); + /* Encode it to Opaque */ ret = wbxml_encode_opaque_data(encoder, octets, 6); Modified: wbxml2/trunk/src/wbxml_parser.c ============================================================================== --- wbxml2/trunk/src/wbxml_parser.c Mon Jan 19 17:06:49 2009 (r172) +++ wbxml2/trunk/src/wbxml_parser.c Mon Jan 19 18:39:33 2009 (r173) @@ -2771,39 +2771,39 @@ data_ptr = wbxml_buffer_get_cstr(*data); /* Get Year */ - the_value = (WB_ULONG) ((data_ptr[0] << 6) | ((data_ptr[1] >> 2) && 0x3F)); + the_value = (WB_ULONG) (((data_ptr[5] & 0x3F) << 6) + ((data_ptr[4] >> 2) & 0x3F)); sprintf(the_year, "%u", the_value); /* Get Month */ - the_value = (WB_ULONG) (((data_ptr[1] && 0x03) << 2) | ((data_ptr[2] >> 6) && 0x3F)); - sprintf(the_month, "%u", the_value); + the_value = (WB_ULONG) (((data_ptr[4] & 0x03) << 2) | ((data_ptr[3] >> 6) & 0x03)); + sprintf(the_month, "%02u", the_value); /* Get Day */ - the_value = (WB_ULONG) ((data_ptr[2] >> 1) && 0x1F); - sprintf(the_date, "%u", the_value); + the_value = (WB_ULONG) ((data_ptr[3] >> 1) & 0x1F); + sprintf(the_date, "%02u", the_value); /* Get Hour */ - the_value = (WB_ULONG) (((data_ptr[2] && 0x01) << 4) | ((data_ptr[3] >> 4) && 0x0F)); - sprintf(the_hour, "%u", the_value); + the_value = (WB_ULONG) (((data_ptr[3] & 0x01) << 4) | ((data_ptr[2] >> 4) & 0x0F)); + sprintf(the_hour, "%02u", the_value); /* Get Minute */ - the_value = (WB_ULONG) (((data_ptr[3] && 0x0F) << 2) | ((data_ptr[4] >> 6) && 0x03)); - sprintf(the_minute, "%u", the_value); + the_value = (WB_ULONG) (((data_ptr[2] & 0x0F) << 2) | ((data_ptr[1] >> 6) & 0x03)); + sprintf(the_minute, "%02u", the_value); /* Get Second */ - the_value = (WB_ULONG) (data_ptr[4] && 0x3F); - sprintf(the_second, "%u", the_value); + the_value = (WB_ULONG) (data_ptr[1] & 0x3F); + sprintf(the_second, "%02u", the_value); /* Get Time Zone */ - if (data_ptr[5] == 'Z') { + if (data_ptr[0] == 0) { sprintf((WB_TINY *) result, "%s%s%sT%s%s%sZ", - the_year, the_month, the_date, the_hour, the_minute, the_second); + the_year, the_month, the_date, the_hour, the_minute, the_value ? the_second : ""); } else { sprintf((WB_TINY *) result, "%s%s%sT%s%s%s", - the_year, the_month, the_date, the_hour, the_minute, the_second); + the_year, the_month, the_date, the_hour, the_minute, the_value ? the_second : ""); } /* Reset buffer */ |