… | |
… | |
229 | if (len >= MAX_FACE_SETS) |
229 | if (len >= MAX_FACE_SETS) |
230 | { |
230 | { |
231 | LOG (llevError, "To high a setnum in image_info file: %d > %d\n", len, MAX_FACE_SETS); |
231 | LOG (llevError, "To high a setnum in image_info file: %d > %d\n", len, MAX_FACE_SETS); |
232 | abort (); |
232 | abort (); |
233 | } |
233 | } |
234 | facesets[len].prefix = strdup_local (cps[1]); |
234 | facesets[len].prefix = strdup (cps[1]); |
235 | facesets[len].fullname = strdup_local (cps[2]); |
235 | facesets[len].fullname = strdup (cps[2]); |
236 | facesets[len].fallback = atoi (cps[3]); |
236 | facesets[len].fallback = atoi (cps[3]); |
237 | facesets[len].size = strdup_local (cps[4]); |
237 | facesets[len].size = strdup (cps[4]); |
238 | facesets[len].extension = strdup_local (cps[5]); |
238 | facesets[len].extension = strdup (cps[5]); |
239 | facesets[len].comment = strdup_local (cps[6]); |
239 | facesets[len].comment = strdup (cps[6]); |
240 | } |
240 | } |
241 | } |
241 | } |
242 | close_and_delete (infile, compressed); |
242 | close_and_delete (infile, compressed); |
243 | for (i = 0; i < MAX_FACE_SETS; i++) |
243 | for (i = 0; i < MAX_FACE_SETS; i++) |
244 | { |
244 | { |
… | |
… | |
283 | if (len == 0 || len > MAX_IMAGE_SIZE) |
283 | if (len == 0 || len > MAX_IMAGE_SIZE) |
284 | { |
284 | { |
285 | LOG (llevError, "read_client_images: length not valid: %d > %d \n%s", len, MAX_IMAGE_SIZE, buf); |
285 | LOG (llevError, "read_client_images: length not valid: %d > %d \n%s", len, MAX_IMAGE_SIZE, buf); |
286 | abort (); |
286 | abort (); |
287 | } |
287 | } |
288 | /* We don't actualy care about the name if the image that |
288 | /* We don't actualy care about the name of the image that |
289 | * is embedded in the image file, so just ignore it. |
289 | * is embedded in the image file, so just ignore it. |
290 | */ |
290 | */ |
291 | facesets[fileno].faces[num].datalen = len; |
291 | facesets[fileno].faces[num].datalen = len; |
292 | facesets[fileno].faces[num].data = (uint8 *) malloc (len); |
292 | facesets[fileno].faces[num].data = (uint8 *) malloc (len); |
293 | if ((i = fread (facesets[fileno].faces[num].data, len, 1, infile)) != 1) |
293 | if ((i = fread (facesets[fileno].faces[num].data, len, 1, infile)) != 1) |
… | |
… | |
312 | * the caching attribute. |
312 | * the caching attribute. |
313 | * |
313 | * |
314 | */ |
314 | */ |
315 | |
315 | |
316 | void |
316 | void |
317 | SetFaceMode (char *buf, int len, NewSocket * ns) |
317 | SetFaceMode (char *buf, int len, client_socket *ns) |
318 | { |
318 | { |
319 | char tmp[256]; |
|
|
320 | |
|
|
321 | int mask = (atoi (buf) & CF_FACE_CACHE), mode = (atoi (buf) & ~CF_FACE_CACHE); |
319 | int mask = (atoi (buf) & CF_FACE_CACHE), mode = (atoi (buf) & ~CF_FACE_CACHE); |
322 | |
320 | |
323 | if (mode == CF_FACE_NONE) |
321 | if (mode == CF_FACE_NONE) |
324 | { |
|
|
325 | ns->facecache = 1; |
322 | ns->facecache = 1; |
326 | } |
|
|
327 | else if (mode != CF_FACE_PNG) |
323 | else if (mode != CF_FACE_PNG) |
328 | { |
324 | { |
|
|
325 | packet sl; |
329 | sprintf (tmp, "drawinfo %d %s", NDI_RED, "Warning - send unsupported face mode. Will use Png"); |
326 | sl.printf ("drawinfo %d %s", NDI_RED, "Warning - send unsupported face mode. Will use Png"); |
330 | Write_String_To_Socket (ns, tmp, strlen (tmp)); |
327 | ns->send_packet (sl); |
331 | #ifdef ESRV_DEBUG |
|
|
332 | LOG (llevDebug, "SetFaceMode: Invalid mode from client: %d\n", mode); |
|
|
333 | #endif |
|
|
334 | } |
328 | } |
|
|
329 | |
335 | if (mask) |
330 | if (mask) |
336 | { |
|
|
337 | ns->facecache = 1; |
331 | ns->facecache = 1; |
338 | } |
|
|
339 | } |
332 | } |
340 | |
333 | |
341 | /** |
334 | /** |
342 | * Client has requested pixmap that it somehow missed getting. |
335 | * Client has requested pixmap that it somehow missed getting. |
343 | * This will be called often if the client is |
336 | * This will be called often if the client is |
344 | * caching images. |
337 | * caching images. |
345 | */ |
338 | */ |
346 | |
339 | |
347 | void |
340 | void |
348 | SendFaceCmd (char *buff, int len, NewSocket * ns) |
341 | SendFaceCmd (char *buff, int len, client_socket * ns) |
349 | { |
342 | { |
350 | long tmpnum = atoi (buff); |
343 | long tmpnum = atoi (buff); |
351 | short facenum = tmpnum & 0xffff; |
344 | short facenum = tmpnum & 0xffff; |
352 | |
345 | |
353 | if (facenum != 0) |
346 | if (facenum != 0) |
… | |
… | |
362 | * face (and askface is the only place that should be setting it). Otherwise, |
355 | * 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. |
356 | * we look at the facecache, and if set, send the image name. |
364 | */ |
357 | */ |
365 | |
358 | |
366 | void |
359 | void |
367 | esrv_send_face (NewSocket * ns, short face_num, int nocache) |
360 | esrv_send_face (client_socket *ns, short face_num, int nocache) |
368 | { |
361 | { |
369 | SockList sl; |
|
|
370 | char fallback; |
362 | char fallback; |
371 | |
363 | |
372 | if (face_num <= 0 || face_num >= nrofpixmaps) |
364 | if (face_num <= 0 || face_num >= nrofpixmaps) |
373 | { |
365 | { |
374 | LOG (llevError, "esrv_send_face (%d) out of bounds??\n", face_num); |
366 | LOG (llevError, "esrv_send_face (%d) out of bounds??\n", face_num); |
375 | return; |
367 | return; |
376 | } |
368 | } |
377 | |
369 | |
378 | sl.buf = (unsigned char *) malloc (MAXSOCKBUF); |
370 | packet sl; |
379 | fallback = get_face_fallback (ns->faceset, face_num); |
371 | fallback = get_face_fallback (ns->faceset, face_num); |
380 | |
372 | |
381 | if (facesets[fallback].faces[face_num].data == NULL) |
373 | if (facesets[fallback].faces[face_num].data == NULL) |
382 | { |
374 | { |
383 | LOG (llevError, "esrv_send_face: faces[%d].data == NULL\n", face_num); |
375 | LOG (llevError, "esrv_send_face: faces[%d].data == NULL\n", face_num); |
384 | return; |
376 | return; |
385 | } |
377 | } |
386 | |
378 | |
387 | if (ns->facecache && !nocache) |
379 | if (ns->facecache && !nocache) |
388 | { |
380 | { |
|
|
381 | sl << (ns->image2 ? "face2 " : "face1 ") |
|
|
382 | << uint16 (face_num); |
|
|
383 | |
389 | if (ns->image2) |
384 | if (ns->image2) |
390 | strcpy ((char *) sl.buf, "face2 "); |
385 | sl << uint8 (fallback); |
391 | else if (ns->sc_version >= 1026) |
386 | |
392 | strcpy ((char *) sl.buf, "face1 "); |
387 | sl << uint32 (facesets[fallback].faces[face_num].checksum) |
|
|
388 | << new_faces[face_num].name; |
|
|
389 | |
|
|
390 | ns->send_packet (sl); |
|
|
391 | } |
393 | else |
392 | else |
394 | strcpy ((char *) sl.buf, "face "); |
393 | { |
|
|
394 | sl << (ns->image2 ? "image2 " : "image ") |
|
|
395 | << uint32 (face_num); |
395 | |
396 | |
396 | sl.len = strlen ((const char *) sl.buf); |
|
|
397 | SockList_AddShort (&sl, face_num); |
|
|
398 | if (ns->image2) |
397 | if (ns->image2) |
399 | SockList_AddChar (&sl, fallback); |
398 | sl << uint8 (fallback); |
400 | if (ns->sc_version >= 1026) |
399 | |
401 | SockList_AddInt (&sl, facesets[fallback].faces[face_num].checksum); |
|
|
402 | strcpy ((char *) sl.buf + sl.len, new_faces[face_num].name); |
|
|
403 | sl.len += strlen (new_faces[face_num].name); |
|
|
404 | Send_With_Handling (ns, &sl); |
|
|
405 | } |
|
|
406 | else |
|
|
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); |
400 | sl << uint32 (facesets[fallback].faces[face_num].datalen) |
417 | memcpy (sl.buf + sl.len, facesets[fallback].faces[face_num].data, facesets[fallback].faces[face_num].datalen); |
401 | << data (facesets[fallback].faces[face_num].data, facesets[fallback].faces[face_num].datalen); |
418 | sl.len += facesets[fallback].faces[face_num].datalen; |
402 | |
419 | Send_With_Handling (ns, &sl); |
403 | ns->send_packet (sl); |
420 | } |
404 | } |
|
|
405 | |
421 | ns->faces_sent[face_num] |= NS_FACESENT_FACE; |
406 | ns->faces_sent[face_num] |= NS_FACESENT_FACE; |
422 | free (sl.buf); |
|
|
423 | } |
407 | } |
424 | |
408 | |
425 | /** |
409 | /** |
426 | * Sends the number of images, checksum of the face file, |
410 | * Sends the number of images, checksum of the face file, |
427 | * and the image_info file information. See the doc/Developers/protocol |
411 | * and the image_info file information. See the doc/Developers/protocol |
428 | * if you want further detail. |
412 | * if you want further detail. |
429 | */ |
413 | */ |
430 | |
414 | |
431 | void |
415 | void |
432 | send_image_info (NewSocket * ns, char *params) |
416 | send_image_info (client_socket * ns, char *params) |
433 | { |
417 | { |
434 | SockList sl; |
418 | packet sl; |
435 | int i; |
|
|
436 | |
419 | |
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); |
420 | sl.printf ("replyinfo image_info\n%d\n%d\n", nrofpixmaps - 1, bmaps_checksum); |
|
|
421 | |
440 | for (i = 0; i < MAX_FACE_SETS; i++) |
422 | for (int i = 0; i < MAX_FACE_SETS; i++) |
441 | { |
|
|
442 | if (facesets[i].prefix) |
423 | if (facesets[i].prefix) |
443 | { |
424 | 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, |
425 | i, facesets[i].prefix, facesets[i].fullname, facesets[i].fallback, |
446 | facesets[i].size, facesets[i].extension, facesets[i].comment); |
426 | facesets[i].size, facesets[i].extension, facesets[i].comment); |
447 | } |
427 | |
448 | } |
428 | ns->send_packet (sl); |
449 | sl.len = strlen ((const char *) sl.buf); |
|
|
450 | Send_With_Handling (ns, &sl); |
|
|
451 | free (sl.buf); |
|
|
452 | } |
429 | } |
453 | |
430 | |
454 | /** |
431 | /** |
455 | * Sends requested face information. |
432 | * Sends requested face information. |
456 | * \param ns socket to send to |
433 | * \param ns socket to send to |
… | |
… | |
459 | * For each image in [start..stop] sends |
436 | * For each image in [start..stop] sends |
460 | * - checksum |
437 | * - checksum |
461 | * - name |
438 | * - name |
462 | */ |
439 | */ |
463 | void |
440 | void |
464 | send_image_sums (NewSocket * ns, char *params) |
441 | send_image_sums (client_socket * ns, char *params) |
465 | { |
442 | { |
466 | int start, stop; |
443 | int start, stop; |
467 | short i; |
|
|
468 | char qq; |
|
|
469 | char *cp, buf[MAX_BUF]; |
444 | char *cp, buf[MAX_BUF]; |
470 | SockList sl; |
|
|
471 | |
445 | |
472 | sl.buf = (unsigned char *) malloc (MAXSOCKBUF); |
446 | packet sl; |
473 | |
447 | |
474 | start = atoi (params); |
448 | start = atoi (params); |
475 | for (cp = params; *cp != '\0'; cp++) |
449 | for (cp = params; *cp != '\0'; cp++) |
476 | if (*cp == ' ') |
450 | if (*cp == ' ') |
477 | break; |
451 | break; |
478 | |
452 | |
479 | stop = atoi (cp); |
453 | stop = atoi (cp); |
480 | if (stop < start || *cp == '\0' || (stop - start) > 1000 || stop >= nrofpixmaps) |
454 | if (stop < start || *cp == '\0' || (stop - start) > 1000 || stop >= nrofpixmaps) |
481 | { |
455 | { |
482 | sprintf (buf, "replyinfo image_sums %d %d", start, stop); |
456 | sl.printf ("replyinfo image_sums %d %d", start, stop); |
483 | cs_write_string (ns, buf, strlen (buf)); |
457 | ns->send_packet (sl); |
|
|
458 | sl.reset (); |
484 | return; |
459 | return; |
485 | } |
460 | } |
|
|
461 | |
486 | sprintf ((char *) sl.buf, "replyinfo image_sums %d %d ", start, stop); |
462 | sl.printf ("replyinfo image_sums %d %d ", start, stop); |
487 | |
463 | |
488 | sl.len = strlen ((const char *) sl.buf); |
|
|
489 | |
|
|
490 | for (i = start; i <= stop; i++) |
464 | for (int i = start; i <= stop; i++) |
491 | { |
465 | { |
492 | SockList_AddShort (&sl, i); |
|
|
493 | ns->faces_sent[i] |= NS_FACESENT_FACE; |
466 | ns->faces_sent[i] |= NS_FACESENT_FACE; |
494 | |
467 | |
495 | qq = get_face_fallback (ns->faceset, i); |
468 | int qq = get_face_fallback (ns->faceset, i); |
|
|
469 | |
|
|
470 | sl << uint16 (i) |
496 | SockList_AddInt (&sl, facesets[qq].faces[i].checksum); |
471 | << uint32 (facesets[qq].faces[i].checksum) |
497 | SockList_AddChar (&sl, qq); |
472 | << uint8 (qq) |
498 | |
473 | << 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 | } |
474 | } |
|
|
475 | |
505 | /* It would make more sense to catch this pre-emptively in the code above. |
476 | /* 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 |
477 | * 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 |
478 | * size to less than 1000, since that is what we claim the protocol would |
508 | * support. |
479 | * support. |
509 | */ |
480 | */ |
510 | if (sl.len >= MAXSOCKBUF) |
481 | if (sl.length () >= MAXSOCKBUF) |
511 | { |
482 | { |
512 | LOG (llevError, "send_image_send: buffer overrun, %d > %d\n", sl.len, MAXSOCKBUF); |
483 | LOG (llevError, "send_image_send: buffer overrun, %d > %d\n", sl.length (), MAXSOCKBUF); |
513 | abort (); |
484 | abort (); |
514 | } |
485 | } |
515 | Send_With_Handling (ns, &sl); |
486 | |
516 | free (sl.buf); |
487 | ns->send_packet (sl); |
517 | } |
488 | } |
|
|
489 | |