Source code of Windows XP (NT5)
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.

239 lines
6.1 KiB

  1. #include <pch.h>
  2. #pragma hdrstop
  3. #include "ssdpapi.h"
  4. #include "common.h"
  5. #include "ncdefine.h"
  6. #include "ncdebug.h"
  7. #include "ssdpparser.h"
  8. #include "ncstring.h"
  9. VOID PrintSsdpMessageList(MessageList *list)
  10. {
  11. int i;
  12. TraceTag(ttidSsdpNotify, "Printing notification list.");
  13. for (i = 0; i < list->size; i++)
  14. {
  15. PrintSsdpRequest(list->list+i);
  16. TraceTag(ttidSsdpNotify, "--------");
  17. }
  18. }
  19. VOID WINAPI FreeSsdpMessage(PSSDP_MESSAGE pSsdpMessage)
  20. {
  21. if (pSsdpMessage)
  22. {
  23. free(pSsdpMessage->szAltHeaders);
  24. free(pSsdpMessage->szContent);
  25. free(pSsdpMessage->szLocHeader);
  26. free(pSsdpMessage->szSid);
  27. free(pSsdpMessage->szType);
  28. free(pSsdpMessage->szUSN);
  29. free(pSsdpMessage);
  30. }
  31. }
  32. BOOL InitializeSsdpMessageFromRequest(PSSDP_MESSAGE pSsdpMessage, const PSSDP_REQUEST pSsdpRequest)
  33. {
  34. pSsdpMessage->guidInterface = pSsdpRequest->guidInterface;
  35. pSsdpMessage->szLocHeader = NULL;
  36. pSsdpMessage->szAltHeaders = NULL;
  37. pSsdpMessage->szType = NULL;
  38. pSsdpMessage->szUSN = NULL;
  39. pSsdpMessage->szContent = NULL;
  40. pSsdpMessage->szSid = NULL;
  41. pSsdpMessage->iLifeTime = 0;
  42. pSsdpMessage->iSeq = 0;
  43. if (pSsdpRequest->Headers[SSDP_NT] != NULL)
  44. {
  45. pSsdpMessage->szType = (char *) malloc(sizeof(char) * (strlen(pSsdpRequest->Headers[SSDP_NT]) + 1));
  46. if (pSsdpMessage->szType == NULL)
  47. {
  48. goto cleanup;
  49. }
  50. else
  51. {
  52. strcpy(pSsdpMessage->szType, pSsdpRequest->Headers[SSDP_NT]);
  53. }
  54. }
  55. else if (pSsdpRequest->Headers[SSDP_ST] != NULL)
  56. {
  57. pSsdpMessage->szType = (char *) malloc(sizeof(char) * (strlen(pSsdpRequest->Headers[SSDP_ST]) + 1));
  58. if (pSsdpMessage->szType == NULL)
  59. {
  60. goto cleanup;
  61. }
  62. else
  63. {
  64. strcpy(pSsdpMessage->szType, pSsdpRequest->Headers[SSDP_ST]);
  65. }
  66. }
  67. if (pSsdpRequest->Headers[SSDP_LOCATION] != NULL)
  68. {
  69. pSsdpMessage->szLocHeader = (char *) malloc(sizeof(char) * (strlen(pSsdpRequest->Headers[SSDP_LOCATION]) + 1));
  70. if (pSsdpMessage->szLocHeader == NULL)
  71. {
  72. goto cleanup;
  73. }
  74. else
  75. {
  76. strcpy(pSsdpMessage->szLocHeader, pSsdpRequest->Headers[SSDP_LOCATION]);
  77. }
  78. }
  79. if (pSsdpRequest->Headers[SSDP_AL] != NULL)
  80. {
  81. pSsdpMessage->szAltHeaders = (char *) malloc(sizeof(char) * (strlen(pSsdpRequest->Headers[SSDP_AL]) + 1));
  82. if (pSsdpMessage->szAltHeaders == NULL)
  83. {
  84. goto cleanup;
  85. }
  86. else
  87. {
  88. strcpy(pSsdpMessage->szAltHeaders, pSsdpRequest->Headers[SSDP_AL]);
  89. }
  90. }
  91. if (pSsdpRequest->Headers[SSDP_USN] != NULL)
  92. {
  93. pSsdpMessage->szUSN = (char *) malloc(sizeof(char) * (strlen(pSsdpRequest->Headers[SSDP_USN]) + 1));
  94. if (pSsdpMessage->szUSN == NULL)
  95. {
  96. goto cleanup;
  97. }
  98. else
  99. {
  100. strcpy(pSsdpMessage->szUSN, pSsdpRequest->Headers[SSDP_USN]);
  101. }
  102. }
  103. if (pSsdpRequest->Headers[GENA_SID] != NULL)
  104. {
  105. pSsdpMessage->szSid = (char *) malloc(sizeof(char) * (strlen(pSsdpRequest->Headers[GENA_SID]) + 1));
  106. if (pSsdpMessage->szSid == NULL)
  107. {
  108. goto cleanup;
  109. }
  110. else
  111. {
  112. strcpy(pSsdpMessage->szSid, pSsdpRequest->Headers[GENA_SID]);
  113. }
  114. }
  115. if (pSsdpRequest->Headers[GENA_SEQ] != NULL)
  116. {
  117. pSsdpMessage->iSeq = strtoul(pSsdpRequest->Headers[GENA_SEQ], NULL, 10);
  118. }
  119. if (pSsdpRequest->Content)
  120. {
  121. pSsdpMessage->szContent = SzaDupSza(pSsdpRequest->Content);
  122. if (pSsdpMessage->szContent == NULL)
  123. {
  124. goto cleanup;
  125. }
  126. }
  127. pSsdpMessage->iLifeTime = GetMaxAgeFromCacheControl(pSsdpRequest->Headers[SSDP_CACHECONTROL]);
  128. return TRUE;
  129. cleanup:
  130. FreeSsdpMessage(pSsdpMessage);
  131. return FALSE;
  132. }
  133. BOOL CopySsdpMessage(PSSDP_MESSAGE pDestination, const PSSDP_MESSAGE pSource)
  134. {
  135. pDestination->guidInterface = pSource->guidInterface;
  136. pDestination->szLocHeader = NULL;
  137. pDestination->szAltHeaders = NULL;
  138. pDestination->szType = NULL;
  139. pDestination->szUSN = NULL;
  140. pDestination->szSid = NULL;
  141. pDestination->szContent = NULL;
  142. pDestination->iLifeTime = 0;
  143. if (pSource->szType != NULL)
  144. {
  145. pDestination->szType = (char *) malloc(sizeof(char) * (strlen(pSource->szType) + 1));
  146. if (pDestination->szType == NULL)
  147. {
  148. goto cleanup;
  149. }
  150. else
  151. {
  152. strcpy(pDestination->szType, pSource->szType);
  153. }
  154. }
  155. if (pSource->szLocHeader != NULL)
  156. {
  157. pDestination->szLocHeader = (char *) malloc(sizeof(char) * (strlen(pSource->szLocHeader) + 1));
  158. if (pDestination->szLocHeader == NULL)
  159. {
  160. goto cleanup;
  161. }
  162. else
  163. {
  164. strcpy(pDestination->szLocHeader, pSource->szLocHeader);
  165. }
  166. }
  167. if (pSource->szAltHeaders != NULL)
  168. {
  169. pDestination->szAltHeaders = (char *) malloc(sizeof(char) * (strlen(pSource->szAltHeaders) + 1));
  170. if (pDestination->szAltHeaders == NULL)
  171. {
  172. goto cleanup;
  173. }
  174. else
  175. {
  176. strcpy(pDestination->szAltHeaders, pSource->szAltHeaders);
  177. }
  178. }
  179. if (pSource->szUSN != NULL)
  180. {
  181. pDestination->szUSN = (char *) malloc(sizeof(char) * (strlen(pSource->szUSN) + 1));
  182. if (pDestination->szUSN == NULL)
  183. {
  184. goto cleanup;
  185. }
  186. else
  187. {
  188. strcpy(pDestination->szUSN, pSource->szUSN);
  189. }
  190. }
  191. if (pSource->szSid != NULL)
  192. {
  193. pDestination->szSid = (char *) malloc(sizeof(char) * (strlen(pSource->szSid) + 1));
  194. if (pDestination->szSid == NULL)
  195. {
  196. goto cleanup;
  197. }
  198. else
  199. {
  200. strcpy(pDestination->szSid, pSource->szSid);
  201. }
  202. }
  203. pDestination->iLifeTime = pSource->iLifeTime;
  204. pDestination->iSeq = pSource->iSeq;
  205. return TRUE;
  206. cleanup:
  207. FreeSsdpMessage(pDestination);
  208. return FALSE;
  209. }