upnp.c 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. /*
  2. * Copyright (C) 2012-2013 by egnite GmbH
  3. *
  4. * All rights reserved.
  5. *
  6. * Redistribution and use in source and binary forms, with or without
  7. * modification, are permitted provided that the following conditions
  8. * are met:
  9. *
  10. * 1. Redistributions of source code must retain the above copyright
  11. * notice, this list of conditions and the following disclaimer.
  12. * 2. Redistributions in binary form must reproduce the above copyright
  13. * notice, this list of conditions and the following disclaimer in the
  14. * documentation and/or other materials provided with the distribution.
  15. * 3. Neither the name of the copyright holders nor the names of
  16. * contributors may be used to endorse or promote products derived
  17. * from this software without specific prior written permission.
  18. *
  19. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  20. * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  21. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  22. * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  23. * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  24. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  25. * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
  26. * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
  27. * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  28. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
  29. * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  30. * SUCH DAMAGE.
  31. *
  32. * For additional information see http://www.ethernut.de/
  33. */
  34. #include <pro/upnp.h>
  35. #include <string.h>
  36. /* Use for local debugging only. Do NOT include into NUTDEBUG.
  37. #define DEBUG_UPNP
  38. */
  39. #if defined(DEBUG_UPNP)
  40. #include <stdio.h>
  41. #endif
  42. static const char *stype_names[] = {
  43. "?", "ui1", "ui2", "ui4", "i1", "i2", "i4", "int", "r4", "r8",
  44. "number", "fixed.14.4", "float", "char", "string", "date",
  45. "dateTime", "dateTime.tz", "boolean", "bin.base64", "bin.hex",
  46. "uri", "uuid"
  47. };
  48. void UpnpDumpDevice(const SSDP_DEVICE *sdev)
  49. {
  50. #if defined(DEBUG_UPNP)
  51. UPNP_DEVICE_INFO *udev = sdev->sdev_info;
  52. SSDP_SERVICE *ssvc;
  53. printf("Device ");
  54. if (udev) {
  55. puts(udev->udev_name);
  56. } else {
  57. puts("NoName");
  58. }
  59. printf(" UUID %s\n", sdev->sdev_uuid);
  60. printf(" %s:device:%s\n", sdev->sdev_domain, sdev->sdev_type);
  61. printf(" Description %s\n", sdev->sdev_url_desc);
  62. printf(" Cache %d\n", sdev->sdev_cache);
  63. for (ssvc = sdev->sdev_svc; ssvc; ssvc = ssvc->ssvc_next) {
  64. UPNP_SERVICE_INFO *usvc = ssvc->ssvc_info;
  65. printf(" Service %s:%s\n", ssvc->ssvc_domain, ssvc->ssvc_type);
  66. if (usvc) {
  67. SOAP_PROCEDURE *proc;
  68. SOAP_ARG *arg;
  69. printf(" Description %s\n", usvc->usvc_url_scpd);
  70. printf(" Control %s\n", usvc->usvc_url_ctrl);
  71. printf(" Event %s\n", usvc->usvc_url_event);
  72. for (proc = usvc->usvc_proc; proc; proc = proc->proc_next) {
  73. printf(" Procedure %s\n", proc->proc_name);
  74. for (arg = proc->proc_argi; arg; arg = arg->arg_next) {
  75. UPNP_VARIABLE *uvar = arg->arg_info;
  76. printf(" in:%s", arg->arg_name);
  77. if (uvar) {
  78. printf(" %s:%s=%s\n", UpnpVarTypeString(uvar->ustv_type), uvar->ustv_name, uvar->ustv_default);
  79. } else {
  80. puts(" unrelated");
  81. }
  82. }
  83. for (arg = proc->proc_argo; arg; arg = arg->arg_next) {
  84. UPNP_VARIABLE *uvar = arg->arg_info;
  85. printf(" out:%s", arg->arg_name);
  86. if (uvar) {
  87. printf(" %s:%s=%s\n", UpnpVarTypeString(uvar->ustv_type), uvar->ustv_name, uvar->ustv_default);
  88. } else {
  89. puts(" unrelated");
  90. }
  91. }
  92. }
  93. }
  94. }
  95. #endif
  96. }
  97. int UpnpVarTypeIndex(const char *string)
  98. {
  99. int idx;
  100. for (idx = 0; idx < sizeof(stype_names) / sizeof(stype_names[0]); idx++) {
  101. if (strcasecmp(stype_names[idx], string) == 0) {
  102. return idx;
  103. }
  104. }
  105. return 0;
  106. }
  107. const char *UpnpVarTypeString(int type)
  108. {
  109. if (type < sizeof(stype_names) / sizeof(stype_names[0])) {
  110. return stype_names[type];
  111. }
  112. return stype_names[0];
  113. }