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