… | |
… | |
362 | * face (and askface is the only place that should be setting it). Otherwise, |
362 | * face (and askface is the only place that should be setting it). Otherwise, |
363 | * we look at the facecache, and if set, send the image name. |
363 | * we look at the facecache, and if set, send the image name. |
364 | */ |
364 | */ |
365 | |
365 | |
366 | void |
366 | void |
367 | esrv_send_face (NewSocket * ns, short face_num, int nocache) |
367 | esrv_send_face (NewSocket *ns, short face_num, int nocache) |
368 | { |
368 | { |
369 | SockList sl; |
|
|
370 | char fallback; |
369 | char fallback; |
371 | |
370 | |
372 | if (face_num <= 0 || face_num >= nrofpixmaps) |
371 | if (face_num <= 0 || face_num >= nrofpixmaps) |
373 | { |
372 | { |
374 | LOG (llevError, "esrv_send_face (%d) out of bounds??\n", face_num); |
373 | LOG (llevError, "esrv_send_face (%d) out of bounds??\n", face_num); |
375 | return; |
374 | return; |
376 | } |
375 | } |
377 | |
376 | |
378 | sl.buf = (unsigned char *) malloc (MAXSOCKBUF); |
377 | SockList sl (MAXSOCKBUF); |
379 | fallback = get_face_fallback (ns->faceset, face_num); |
378 | fallback = get_face_fallback (ns->faceset, face_num); |
380 | |
379 | |
381 | if (facesets[fallback].faces[face_num].data == NULL) |
380 | if (facesets[fallback].faces[face_num].data == NULL) |
382 | { |
381 | { |
383 | LOG (llevError, "esrv_send_face: faces[%d].data == NULL\n", face_num); |
382 | LOG (llevError, "esrv_send_face: faces[%d].data == NULL\n", face_num); |
384 | return; |
383 | return; |
385 | } |
384 | } |
386 | |
385 | |
387 | if (ns->facecache && !nocache) |
386 | if (ns->facecache && !nocache) |
388 | { |
387 | { |
|
|
388 | sl << (ns->image2 ? "face2 " : "face1 ") |
|
|
389 | << uint16 (face_num); |
|
|
390 | |
389 | if (ns->image2) |
391 | if (ns->image2) |
390 | strcpy ((char *) sl.buf, "face2 "); |
392 | sl << uint8 (fallback); |
391 | else if (ns->sc_version >= 1026) |
393 | |
392 | strcpy ((char *) sl.buf, "face1 "); |
394 | sl << uint32 (facesets[fallback].faces[face_num].checksum) |
|
|
395 | << new_faces[face_num].name; |
|
|
396 | |
|
|
397 | Send_With_Handling (ns, &sl); |
|
|
398 | } |
393 | else |
399 | else |
394 | strcpy ((char *) sl.buf, "face "); |
400 | { |
|
|
401 | sl << (ns->image2 ? "image2 " : "image ") |
|
|
402 | << uint32 (face_num); |
395 | |
403 | |
396 | sl.len = strlen ((const char *) sl.buf); |
|
|
397 | SockList_AddShort (&sl, face_num); |
|
|
398 | if (ns->image2) |
404 | if (ns->image2) |
399 | SockList_AddChar (&sl, fallback); |
405 | sl << uint8 (fallback); |
400 | if (ns->sc_version >= 1026) |
406 | |
401 | SockList_AddInt (&sl, facesets[fallback].faces[face_num].checksum); |
407 | sl << uint32 (facesets[fallback].faces[face_num].datalen) |
402 | strcpy ((char *) sl.buf + sl.len, new_faces[face_num].name); |
408 | << data (facesets[fallback].faces[face_num].data, facesets[fallback].faces[face_num].datalen); |
403 | sl.len += strlen (new_faces[face_num].name); |
409 | |
404 | Send_With_Handling (ns, &sl); |
410 | Send_With_Handling (ns, &sl); |
405 | } |
411 | } |
406 | else |
412 | |
407 | { |
|
|
408 | if (ns->image2) |
|
|
409 | strcpy ((char *) sl.buf, "image2 "); |
|
|
410 | else |
|
|
411 | strcpy ((char *) sl.buf, "image "); |
|
|
412 | sl.len = strlen ((char *) sl.buf); |
|
|
413 | SockList_AddInt (&sl, face_num); |
|
|
414 | if (ns->image2) |
|
|
415 | SockList_AddChar (&sl, fallback); |
|
|
416 | SockList_AddInt (&sl, facesets[fallback].faces[face_num].datalen); |
|
|
417 | memcpy (sl.buf + sl.len, facesets[fallback].faces[face_num].data, facesets[fallback].faces[face_num].datalen); |
|
|
418 | sl.len += facesets[fallback].faces[face_num].datalen; |
|
|
419 | Send_With_Handling (ns, &sl); |
|
|
420 | } |
|
|
421 | ns->faces_sent[face_num] |= NS_FACESENT_FACE; |
413 | ns->faces_sent[face_num] |= NS_FACESENT_FACE; |
422 | free (sl.buf); |
414 | sl.free (); |
423 | } |
415 | } |
424 | |
416 | |
425 | /** |
417 | /** |
426 | * Sends the number of images, checksum of the face file, |
418 | * Sends the number of images, checksum of the face file, |
427 | * and the image_info file information. See the doc/Developers/protocol |
419 | * and the image_info file information. See the doc/Developers/protocol |
… | |
… | |
429 | */ |
421 | */ |
430 | |
422 | |
431 | void |
423 | void |
432 | send_image_info (NewSocket * ns, char *params) |
424 | send_image_info (NewSocket * ns, char *params) |
433 | { |
425 | { |
434 | SockList sl; |
426 | SockList sl (MAXSOCKBUF); |
435 | int i; |
|
|
436 | |
427 | |
437 | sl.buf = (unsigned char *) malloc (MAXSOCKBUF); |
|
|
438 | |
|
|
439 | sprintf ((char *) sl.buf, "replyinfo image_info\n%d\n%d\n", nrofpixmaps - 1, bmaps_checksum); |
428 | sl.printf ("replyinfo image_info\n%d\n%d\n", nrofpixmaps - 1, bmaps_checksum); |
|
|
429 | |
440 | for (i = 0; i < MAX_FACE_SETS; i++) |
430 | for (int i = 0; i < MAX_FACE_SETS; i++) |
441 | { |
|
|
442 | if (facesets[i].prefix) |
431 | if (facesets[i].prefix) |
443 | { |
432 | sl.printf ("%d:%s:%s:%d:%s:%s:%s", |
444 | sprintf ((char *) sl.buf + strlen ((const char *) sl.buf), "%d:%s:%s:%d:%s:%s:%s", |
|
|
445 | i, facesets[i].prefix, facesets[i].fullname, facesets[i].fallback, |
433 | i, facesets[i].prefix, facesets[i].fullname, facesets[i].fallback, |
446 | facesets[i].size, facesets[i].extension, facesets[i].comment); |
434 | facesets[i].size, facesets[i].extension, facesets[i].comment); |
447 | } |
435 | |
448 | } |
|
|
449 | sl.len = strlen ((const char *) sl.buf); |
|
|
450 | Send_With_Handling (ns, &sl); |
436 | Send_With_Handling (ns, &sl); |
451 | free (sl.buf); |
437 | sl.free (); |
452 | } |
438 | } |
453 | |
439 | |
454 | /** |
440 | /** |
455 | * Sends requested face information. |
441 | * Sends requested face information. |
456 | * \param ns socket to send to |
442 | * \param ns socket to send to |
… | |
… | |
462 | */ |
448 | */ |
463 | void |
449 | void |
464 | send_image_sums (NewSocket * ns, char *params) |
450 | send_image_sums (NewSocket * ns, char *params) |
465 | { |
451 | { |
466 | int start, stop; |
452 | int start, stop; |
467 | short i; |
|
|
468 | char qq; |
|
|
469 | char *cp, buf[MAX_BUF]; |
453 | char *cp, buf[MAX_BUF]; |
470 | SockList sl; |
|
|
471 | |
454 | |
472 | sl.buf = (unsigned char *) malloc (MAXSOCKBUF); |
455 | SockList sl (MAXSOCKBUF); |
473 | |
456 | |
474 | start = atoi (params); |
457 | start = atoi (params); |
475 | for (cp = params; *cp != '\0'; cp++) |
458 | for (cp = params; *cp != '\0'; cp++) |
476 | if (*cp == ' ') |
459 | if (*cp == ' ') |
477 | break; |
460 | break; |
… | |
… | |
481 | { |
464 | { |
482 | sprintf (buf, "replyinfo image_sums %d %d", start, stop); |
465 | sprintf (buf, "replyinfo image_sums %d %d", start, stop); |
483 | cs_write_string (ns, buf, strlen (buf)); |
466 | cs_write_string (ns, buf, strlen (buf)); |
484 | return; |
467 | return; |
485 | } |
468 | } |
|
|
469 | |
486 | sprintf ((char *) sl.buf, "replyinfo image_sums %d %d ", start, stop); |
470 | sl.printf ("replyinfo image_sums %d %d ", start, stop); |
487 | |
471 | |
488 | sl.len = strlen ((const char *) sl.buf); |
|
|
489 | |
|
|
490 | for (i = start; i <= stop; i++) |
472 | for (int i = start; i <= stop; i++) |
491 | { |
473 | { |
492 | SockList_AddShort (&sl, i); |
|
|
493 | ns->faces_sent[i] |= NS_FACESENT_FACE; |
474 | ns->faces_sent[i] |= NS_FACESENT_FACE; |
494 | |
475 | |
495 | qq = get_face_fallback (ns->faceset, i); |
476 | int qq = get_face_fallback (ns->faceset, i); |
|
|
477 | |
|
|
478 | sl << uint16 (i) |
496 | SockList_AddInt (&sl, facesets[qq].faces[i].checksum); |
479 | << uint32 (facesets[qq].faces[i].checksum) |
497 | SockList_AddChar (&sl, qq); |
480 | << uint8 (qq) |
498 | |
481 | << data8 (&new_faces[i].name, new_faces[i].name.length () + 1); |
499 | qq = strlen (new_faces[i].name); |
|
|
500 | SockList_AddChar (&sl, (char) (qq + 1)); |
|
|
501 | strcpy ((char *) sl.buf + sl.len, new_faces[i].name); |
|
|
502 | sl.len += qq; |
|
|
503 | SockList_AddChar (&sl, 0); |
|
|
504 | } |
482 | } |
|
|
483 | |
505 | /* It would make more sense to catch this pre-emptively in the code above. |
484 | /* It would make more sense to catch this pre-emptively in the code above. |
506 | * however, if this really happens, we probably just want to cut down the |
485 | * however, if this really happens, we probably just want to cut down the |
507 | * size to less than 1000, since that is what we claim the protocol would |
486 | * size to less than 1000, since that is what we claim the protocol would |
508 | * support. |
487 | * support. |
509 | */ |
488 | */ |
510 | if (sl.len >= MAXSOCKBUF) |
489 | if (sl.len >= MAXSOCKBUF) |
511 | { |
490 | { |
512 | LOG (llevError, "send_image_send: buffer overrun, %d > %d\n", sl.len, MAXSOCKBUF); |
491 | LOG (llevError, "send_image_send: buffer overrun, %d > %d\n", sl.len, MAXSOCKBUF); |
513 | abort (); |
492 | abort (); |
514 | } |
493 | } |
|
|
494 | |
515 | Send_With_Handling (ns, &sl); |
495 | Send_With_Handling (ns, &sl); |
516 | free (sl.buf); |
496 | sl.free (); |
517 | } |
497 | } |
|
|
498 | |