You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

90 lines
2.1 KiB

7 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. /* $Id: printresponse.c,v 1.2 2016/01/19 10:24:59 nanard Exp $ */
  2. /* vim: tabstop=4 shiftwidth=4 noexpandtab
  3. * Project : miniupnp
  4. * website : http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/
  5. * Author : Thomas BERNARD
  6. * copyright (c) 2005-2016 Thomas Bernard
  7. * This software is subjet to the conditions detailed in the
  8. * provided LICENCE file. */
  9. #include <stdio.h>
  10. #include "codelength.h"
  11. #define NOTIF_NEW 1
  12. #define NOTIF_UPDATE 2
  13. #define NOTIF_REMOVE 3
  14. void printresponse(const unsigned char * resp, int n)
  15. {
  16. int i, l;
  17. int notif_type;
  18. unsigned int nresp;
  19. const unsigned char * p;
  20. if(n == 0)
  21. return;
  22. /* first, hexdump the response : */
  23. for(i = 0; i < n; i += 16) {
  24. printf("%06x | ", i);
  25. for(l = i; l < n && l < (i + 16); l++)
  26. printf("%02x ", resp[l]);
  27. while(l < (i + 16)) {
  28. printf(" ");
  29. l++;
  30. }
  31. printf("| ");
  32. for(l = i; l < n && l < (i + 16); l++)
  33. putchar((resp[l] >= ' ' && resp[l] < 128) ? resp[l] : '.');
  34. putchar('\n');
  35. }
  36. for(p = resp; p < resp + n; ) {
  37. /* now parse and display all devices of response */
  38. nresp = p[0]; /* 1st byte : number of devices in response */
  39. if(nresp == 0xff) {
  40. /* notification */
  41. notif_type = p[1];
  42. nresp = p[2];
  43. printf("Notification : ");
  44. switch(notif_type) {
  45. case NOTIF_NEW: printf("new\n"); break;
  46. case NOTIF_UPDATE: printf("update\n"); break;
  47. case NOTIF_REMOVE: printf("remove\n"); break;
  48. default: printf("**UNKNOWN**\n");
  49. }
  50. p += 3;
  51. } else {
  52. p++;
  53. }
  54. for(i = 0; i < (int)nresp; i++) {
  55. if(p >= resp + n)
  56. goto error;
  57. /*l = *(p++);*/
  58. DECODELENGTH(l, p);
  59. if(p + l > resp + n)
  60. goto error;
  61. printf("%d - %.*s\n", i, l, p); /* URL */
  62. p += l;
  63. if(p >= resp + n)
  64. goto error;
  65. /*l = *(p++);*/
  66. DECODELENGTH(l, p);
  67. if(p + l > resp + n)
  68. goto error;
  69. printf(" %.*s\n", l, p); /* ST */
  70. p += l;
  71. if(p >= resp + n)
  72. goto error;
  73. /*l = *(p++);*/
  74. DECODELENGTH(l, p);
  75. if(p + l > resp + n)
  76. goto error;
  77. printf(" %.*s\n", l, p); /* USN */
  78. p += l;
  79. }
  80. }
  81. return;
  82. error:
  83. printf("*** WARNING : TRUNCATED RESPONSE ***\n");
  84. }