… | |
… | |
33 | * things like all the structures as globals. |
33 | * things like all the structures as globals. |
34 | */ |
34 | */ |
35 | |
35 | |
36 | #include <global.h> |
36 | #include <global.h> |
37 | #include <sproto.h> |
37 | #include <sproto.h> |
|
|
38 | |
|
|
39 | #include "crc.h" |
38 | |
40 | |
39 | #define MAX_FACE_SETS 20 /**< Maximum number of image sets the program will handle */ |
41 | #define MAX_FACE_SETS 20 /**< Maximum number of image sets the program will handle */ |
40 | |
42 | |
41 | /** Information about one image */ |
43 | /** Information about one image */ |
42 | typedef struct FaceInfo |
44 | typedef struct FaceInfo |
… | |
… | |
280 | LOG (llevError, "read_client_images: Image num %d not in 0..%d\n%s", num, nrofpixmaps, buf); |
282 | LOG (llevError, "read_client_images: Image num %d not in 0..%d\n%s", num, nrofpixmaps, buf); |
281 | abort (); |
283 | abort (); |
282 | } |
284 | } |
283 | |
285 | |
284 | /* Skip accross the number data */ |
286 | /* Skip accross the number data */ |
285 | for (cp = buf + 6; *cp != ' '; cp++); |
287 | for (cp = buf + 6; *cp != ' '; cp++) |
|
|
288 | ; |
|
|
289 | |
286 | len = atoi (cp); |
290 | len = atoi (cp); |
287 | if (len == 0 || len > MAX_IMAGE_SIZE) |
291 | if (len == 0 || len > MAX_IMAGE_SIZE) |
288 | { |
292 | { |
289 | LOG (llevError, "read_client_images: length not valid: %d > %d \n%s", len, MAX_IMAGE_SIZE, buf); |
293 | LOG (llevError, "read_client_images: length not valid: %d > %d \n%s", len, MAX_IMAGE_SIZE, buf); |
290 | abort (); |
294 | abort (); |
… | |
… | |
299 | { |
303 | { |
300 | LOG (llevError, "read_client_images: Did not read desired amount of data, wanted %d, got %d\n%s", len, i, buf); |
304 | LOG (llevError, "read_client_images: Did not read desired amount of data, wanted %d, got %d\n%s", len, i, buf); |
301 | abort (); |
305 | abort (); |
302 | } |
306 | } |
303 | |
307 | |
304 | facesets[fileno].faces[num].checksum = 0; |
308 | crc32 chksum; |
|
|
309 | |
305 | for (i = 0; i < len; i++) |
310 | for (i = 0; i < len; i++) |
306 | { |
311 | chksum (facesets[fileno].faces[num].data[i]); |
307 | rotate_right (facesets[fileno].faces[num].checksum); |
312 | |
308 | facesets[fileno].faces[num].checksum += facesets[fileno].faces[num].data[i]; |
|
|
309 | facesets[fileno].faces[num].checksum &= 0xffffffff; |
313 | facesets[fileno].faces[num].checksum = chksum; |
310 | } |
|
|
311 | } |
314 | } |
312 | |
315 | |
313 | close_and_delete (infile, compressed); |
316 | close_and_delete (infile, compressed); |
314 | } /* For fileno < MAX_FACE_SETS */ |
317 | } /* For fileno < MAX_FACE_SETS */ |
315 | } |
318 | } |
… | |
… | |
438 | */ |
441 | */ |
439 | void |
442 | void |
440 | send_image_sums (client *ns, char *params) |
443 | send_image_sums (client *ns, char *params) |
441 | { |
444 | { |
442 | int start, stop; |
445 | int start, stop; |
443 | char *cp, buf[MAX_BUF]; |
446 | char *cp; |
444 | |
447 | |
445 | packet sl; |
448 | packet sl; |
446 | |
449 | |
447 | start = atoi (params); |
450 | start = atoi (params); |
448 | for (cp = params; *cp != '\0'; cp++) |
451 | for (cp = params; *cp != '\0'; cp++) |
… | |
… | |
463 | for (int i = start; i <= stop; i++) |
466 | for (int i = start; i <= stop; i++) |
464 | { |
467 | { |
465 | ns->faces_sent[i] |= NS_FACESENT_FACE; |
468 | ns->faces_sent[i] |= NS_FACESENT_FACE; |
466 | |
469 | |
467 | int qq = get_face_fallback (ns->faceset, i); |
470 | int qq = get_face_fallback (ns->faceset, i); |
|
|
471 | |
|
|
472 | if (sl.room () < 2 + 4 + 1 + new_faces[i].name.length () + 1) |
|
|
473 | break; |
468 | |
474 | |
469 | sl << uint16 (i) |
475 | sl << uint16 (i) |
470 | << uint32 (facesets[qq].faces[i].checksum) |
476 | << uint32 (facesets[qq].faces[i].checksum) |
471 | << uint8 (qq) |
477 | << uint8 (qq) |
472 | << data8 (&new_faces[i].name, new_faces[i].name.length () + 1); |
478 | << data8 (&new_faces[i].name, new_faces[i].name.length () + 1); |
… | |
… | |
475 | /* It would make more sense to catch this pre-emptively in the code above. |
481 | /* It would make more sense to catch this pre-emptively in the code above. |
476 | * however, if this really happens, we probably just want to cut down the |
482 | * however, if this really happens, we probably just want to cut down the |
477 | * size to less than 1000, since that is what we claim the protocol would |
483 | * size to less than 1000, since that is what we claim the protocol would |
478 | * support. |
484 | * support. |
479 | */ |
485 | */ |
|
|
486 | //TODO: taken care of above, should simply abort or make sure the above code is correct |
480 | if (sl.length () >= MAXSOCKBUF) |
487 | if (sl.length () >= MAXSOCKBUF) |
481 | { |
488 | { |
482 | LOG (llevError, "send_image_send: buffer overrun, %d > %d\n", sl.length (), MAXSOCKBUF); |
489 | LOG (llevError, "send_image_send: buffer overrun, %d > %d\n", sl.length (), MAXSOCKBUF); |
483 | abort (); |
490 | abort (); |
484 | } |
491 | } |