|
61 | 61 | import static com.zoffcc.applications.trifa.HelperGeneric.fourbytes_of_long_to_hex; |
62 | 62 | import static com.zoffcc.applications.trifa.HelperGeneric.io_file_copy; |
63 | 63 | import static com.zoffcc.applications.trifa.HelperGeneric.update_savedata_file_wrapper; |
| 64 | +import static com.zoffcc.applications.trifa.HelperGeneric.utf8_string_from_bytes_with_padding; |
64 | 65 | import static com.zoffcc.applications.trifa.HelperMsgNotification.change_msg_notification; |
65 | 66 | import static com.zoffcc.applications.trifa.MainActivity.PREF__conference_show_system_messages; |
66 | 67 | import static com.zoffcc.applications.trifa.MainActivity.android_tox_callback_conference_title_cb_method; |
|
86 | 87 | import static com.zoffcc.applications.trifa.TRIFAGlobals.MESSAGE_GROUP_HISTORY_SYNC_DOUBLE_INTERVAL_SECS; |
87 | 88 | import static com.zoffcc.applications.trifa.TRIFAGlobals.MESSAGE_SYNC_DOUBLE_INTERVAL_SECS; |
88 | 89 | import static com.zoffcc.applications.trifa.TRIFAGlobals.NOTIFICATION_EDIT_ACTION.NOTIFICATION_EDIT_ACTION_ADD; |
| 90 | +import static com.zoffcc.applications.trifa.TRIFAGlobals.TOX_NGC_HISTORY_SYNC_MAX_FILENAME_BYTES; |
89 | 91 | import static com.zoffcc.applications.trifa.TRIFAGlobals.TOX_NGC_HISTORY_SYNC_MAX_PEERNAME_BYTES; |
90 | 92 | import static com.zoffcc.applications.trifa.TRIFAGlobals.TOX_NGC_HISTORY_SYNC_MAX_SECONDS_BACK; |
91 | 93 | import static com.zoffcc.applications.trifa.TRIFAGlobals.TRIFA_FT_DIRECTION.TRIFA_FT_DIRECTION_INCOMING; |
@@ -1240,6 +1242,10 @@ static void send_group_image(final GroupMessage g) |
1240 | 1242 | // fill with null bytes up to 255 for the filename |
1241 | 1243 | data_buf.put((byte) 0x0); |
1242 | 1244 | } |
| 1245 | + |
| 1246 | + |
| 1247 | + |
| 1248 | + |
1243 | 1249 | // -- now fill the data from file -- |
1244 | 1250 | java.io.File img_file = new java.io.File(g.filename_fullpath); |
1245 | 1251 |
|
@@ -1563,46 +1569,15 @@ static void handle_incoming_group_file(long group_number, long peer_id, byte[] d |
1563 | 1569 | // TODO: fix me! |
1564 | 1570 | long timestamp = ((byte)data[8+32]<<3) + ((byte)data[8+32+1]<<2) + ((byte)data[8+32+2]<<1) + (byte)data[8+32+3]; |
1565 | 1571 |
|
1566 | | - ByteBuffer filename_bytes = ByteBuffer.allocateDirect(TOX_MAX_FILENAME_LENGTH); |
1567 | | - filename_bytes.put(data, 8 + 32 + 4, 255); |
1568 | | - filename_bytes.rewind(); |
1569 | 1572 | String filename = "image.jpg"; |
1570 | 1573 | try |
1571 | 1574 | { |
1572 | | - byte[] filename_byte_buf = new byte[255]; |
1573 | | - Arrays.fill(filename_byte_buf, (byte)0x0); |
1574 | | - filename_bytes.rewind(); |
1575 | | - filename_bytes.get(filename_byte_buf); |
1576 | | - |
1577 | | - int start_index = 0; |
1578 | | - int end_index = 254; |
1579 | | - for(int j=0;j<255;j++) |
1580 | | - { |
1581 | | - if (filename_byte_buf[j] == 0) |
1582 | | - { |
1583 | | - start_index = j+1; |
1584 | | - } |
1585 | | - else |
1586 | | - { |
1587 | | - break; |
1588 | | - } |
1589 | | - } |
1590 | | - |
1591 | | - for(int j=254;j>=0;j--) |
1592 | | - { |
1593 | | - if (filename_byte_buf[j] == 0) |
1594 | | - { |
1595 | | - end_index = j; |
1596 | | - } |
1597 | | - else |
1598 | | - { |
1599 | | - break; |
1600 | | - } |
1601 | | - } |
1602 | | - |
1603 | | - byte[] filename_byte_buf_stripped = Arrays.copyOfRange(filename_byte_buf,start_index,end_index); |
1604 | | - filename = new String(filename_byte_buf_stripped, StandardCharsets.UTF_8); |
1605 | | - //Log.i(TAG,"group_custom_packet_cb:filename str=" + filename); |
| 1575 | + ByteBuffer filename_bytes = ByteBuffer.allocateDirect(TOX_MAX_FILENAME_LENGTH); |
| 1576 | + filename_bytes.put(data, 8 + 32 + 4, TOX_MAX_FILENAME_LENGTH); |
| 1577 | + filename = utf8_string_from_bytes_with_padding(filename_bytes, |
| 1578 | + TOX_MAX_FILENAME_LENGTH, |
| 1579 | + "image.jpg"); |
| 1580 | + Log.i(TAG,"group_custom_packet_cb:filename str=" + filename); |
1606 | 1581 |
|
1607 | 1582 | //Log.i(TAG, "group_custom_packet_cb:filename:"+filename_bytes.arrayOffset()+" " |
1608 | 1583 | //+filename_bytes.limit()+" "+filename_bytes.array().length); |
@@ -2103,7 +2078,19 @@ private static void send_ngch_syncfile(final String group_identifier, final Stri |
2103 | 2078 | } |
2104 | 2079 | catch(Exception e) |
2105 | 2080 | { |
| 2081 | + e.printStackTrace(); |
| 2082 | + } |
| 2083 | + |
| 2084 | + try |
| 2085 | + { |
| 2086 | + Log.i(TAG,"send_ngch_syncmsg:send_ts_bytes:filename_bytes=" + |
| 2087 | + HelperGeneric.bytesToHex(filename_bytes, 0, filename_bytes.length)); |
| 2088 | + } |
| 2089 | + catch(Exception e) |
| 2090 | + { |
| 2091 | + e.printStackTrace(); |
2106 | 2092 | } |
| 2093 | + |
2107 | 2094 | data_buf.put(filename_bytes); |
2108 | 2095 | for (int k=0;k<(TOX_MAX_FILENAME_LENGTH - filename_bytes.length);k++) |
2109 | 2096 | { |
@@ -2229,46 +2216,17 @@ else if (timestamp < ((System.currentTimeMillis() / 1000) - (60 * 200))) |
2229 | 2216 | // Log.i(TAG, "handle_incoming_sync_group_message:message_id_tox hex=" + message_id_tox); |
2230 | 2217 | // |
2231 | 2218 | // |
2232 | | - ByteBuffer name_buffer = ByteBuffer.allocateDirect(TOX_NGC_HISTORY_SYNC_MAX_PEERNAME_BYTES); |
2233 | | - name_buffer.put(data, 8 + 4 + 32 + 4, TOX_NGC_HISTORY_SYNC_MAX_PEERNAME_BYTES); |
2234 | | - name_buffer.rewind(); |
2235 | | - String peer_name = "peer"; |
| 2219 | + |
2236 | 2220 | try |
2237 | 2221 | { |
2238 | | - byte[] name_byte_buf = new byte[TOX_NGC_HISTORY_SYNC_MAX_PEERNAME_BYTES]; |
2239 | | - Arrays.fill(name_byte_buf, (byte)0x0); |
2240 | | - name_buffer.rewind(); |
2241 | | - name_buffer.get(name_byte_buf); |
| 2222 | + ByteBuffer name_buffer = ByteBuffer.allocateDirect(TOX_NGC_HISTORY_SYNC_MAX_PEERNAME_BYTES); |
| 2223 | + name_buffer.put(data, 8 + 4 + 32 + 4, TOX_NGC_HISTORY_SYNC_MAX_PEERNAME_BYTES); |
| 2224 | + String peer_name = utf8_string_from_bytes_with_padding(name_buffer, |
| 2225 | + TOX_NGC_HISTORY_SYNC_MAX_PEERNAME_BYTES, |
| 2226 | + "peer"); |
| 2227 | + Log.i(TAG,"handle_incoming_sync_group_message:peer_name str=" + peer_name); |
2242 | 2228 |
|
2243 | | - int start_index = 0; |
2244 | | - int end_index = TOX_NGC_HISTORY_SYNC_MAX_PEERNAME_BYTES - 1; |
2245 | | - for(int j=0;j<TOX_NGC_HISTORY_SYNC_MAX_PEERNAME_BYTES;j++) |
2246 | | - { |
2247 | | - if (name_byte_buf[j] == 0) |
2248 | | - { |
2249 | | - start_index = j+1; |
2250 | | - } |
2251 | | - else |
2252 | | - { |
2253 | | - break; |
2254 | | - } |
2255 | | - } |
2256 | 2229 |
|
2257 | | - for(int j=(TOX_NGC_HISTORY_SYNC_MAX_PEERNAME_BYTES-1);j>=0;j--) |
2258 | | - { |
2259 | | - if (name_byte_buf[j] == 0) |
2260 | | - { |
2261 | | - end_index = j; |
2262 | | - } |
2263 | | - else |
2264 | | - { |
2265 | | - break; |
2266 | | - } |
2267 | | - } |
2268 | | - |
2269 | | - byte[] peername_byte_buf_stripped = Arrays.copyOfRange(name_byte_buf, start_index,end_index); |
2270 | | - peer_name = new String(peername_byte_buf_stripped, StandardCharsets.UTF_8); |
2271 | | - // Log.i(TAG,"handle_incoming_sync_group_message:peer_name str=" + peer_name); |
2272 | 2230 | // |
2273 | 2231 | final int header = 6+1+1+4+32+4+25; // 73 bytes |
2274 | 2232 | long text_size = length - header; |
@@ -2471,59 +2429,31 @@ else if (timestamp < ((System.currentTimeMillis() / 1000) - (60 * 200))) |
2471 | 2429 | // Log.i(TAG, "handle_incoming_sync_group_file:message_id_hash hex=" + message_id_hash); |
2472 | 2430 | // |
2473 | 2431 | // |
2474 | | - ByteBuffer name_buffer = ByteBuffer.allocateDirect(TOX_NGC_HISTORY_SYNC_MAX_PEERNAME_BYTES); |
2475 | | - name_buffer.put(data, 8 + 32 + 32 + 4, TOX_NGC_HISTORY_SYNC_MAX_PEERNAME_BYTES); |
2476 | | - name_buffer.rewind(); |
2477 | | - String peer_name = "peer"; |
2478 | 2432 | try |
2479 | 2433 | { |
2480 | | - byte[] name_byte_buf = new byte[TOX_NGC_HISTORY_SYNC_MAX_PEERNAME_BYTES]; |
2481 | | - Arrays.fill(name_byte_buf, (byte)0x0); |
2482 | | - name_buffer.rewind(); |
2483 | | - name_buffer.get(name_byte_buf); |
2484 | | - |
2485 | | - int start_index = 0; |
2486 | | - int end_index = TOX_NGC_HISTORY_SYNC_MAX_PEERNAME_BYTES - 1; |
2487 | | - for(int j=0;j<TOX_NGC_HISTORY_SYNC_MAX_PEERNAME_BYTES;j++) |
2488 | | - { |
2489 | | - if (name_byte_buf[j] == 0) |
2490 | | - { |
2491 | | - start_index = j+1; |
2492 | | - } |
2493 | | - else |
2494 | | - { |
2495 | | - break; |
2496 | | - } |
2497 | | - } |
2498 | | - |
2499 | | - for(int j=(TOX_NGC_HISTORY_SYNC_MAX_PEERNAME_BYTES-1);j>=0;j--) |
2500 | | - { |
2501 | | - if (name_byte_buf[j] == 0) |
2502 | | - { |
2503 | | - end_index = j; |
2504 | | - } |
2505 | | - else |
2506 | | - { |
2507 | | - break; |
2508 | | - } |
2509 | | - } |
2510 | | - |
2511 | | - byte[] peername_byte_buf_stripped = Arrays.copyOfRange(name_byte_buf, start_index,end_index); |
2512 | | - peer_name = new String(peername_byte_buf_stripped, StandardCharsets.UTF_8); |
2513 | | - // Log.i(TAG,"handle_incoming_sync_group_file:peer_name str=" + peer_name); |
| 2434 | + ByteBuffer name_buffer = ByteBuffer.allocateDirect(TOX_NGC_HISTORY_SYNC_MAX_PEERNAME_BYTES); |
| 2435 | + name_buffer.put(data, 8 + 32 + 32 + 4, TOX_NGC_HISTORY_SYNC_MAX_PEERNAME_BYTES); |
| 2436 | + final String peer_name = utf8_string_from_bytes_with_padding(name_buffer, |
| 2437 | + TOX_NGC_HISTORY_SYNC_MAX_PEERNAME_BYTES, |
| 2438 | + "peer"); |
| 2439 | + Log.i(TAG,"handle_incoming_sync_group_file:peer_name str=" + peer_name); |
2514 | 2440 | // |
2515 | 2441 | // |
2516 | 2442 | // |
2517 | | - // TODO: fixme, get real filename |
2518 | | - final String filename = "image.jpg"; |
| 2443 | + ByteBuffer filename_buffer = ByteBuffer.allocateDirect(TOX_NGC_HISTORY_SYNC_MAX_FILENAME_BYTES); |
| 2444 | + filename_buffer.put(data, 6 + 1 + 1 + 32 + 32 + 4 + 25, TOX_NGC_HISTORY_SYNC_MAX_FILENAME_BYTES); |
| 2445 | + final String filename = utf8_string_from_bytes_with_padding(filename_buffer, |
| 2446 | + TOX_NGC_HISTORY_SYNC_MAX_FILENAME_BYTES, |
| 2447 | + "image.jpg"); |
| 2448 | + Log.i(TAG, "handle_incoming_sync_group_file:filename=" + filename); |
2519 | 2449 | // |
2520 | 2450 | // |
2521 | 2451 | // |
2522 | 2452 | final int header = 6+1+1+32+32+4+25+255; |
2523 | 2453 | long filedata_size = length - header; |
2524 | 2454 | if ((filedata_size < 1) || (filedata_size > 37000)) |
2525 | 2455 | { |
2526 | | - // Log.i(TAG, "handle_incoming_sync_group_file: file size less than 1 byte or larger than 37000 bytes"); |
| 2456 | + Log.i(TAG, "handle_incoming_sync_group_file: file size less than 1 byte or larger than 37000 bytes"); |
2527 | 2457 | return; |
2528 | 2458 | } |
2529 | 2459 |
|
|
0 commit comments