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.

133 lines
3.4 KiB

8 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. /******************************************************************
  2. * $Id: soap-fault.c,v 1.11 2006/07/09 16:24:19 snowdrop Exp $
  3. *
  4. * CSOAP Project: A SOAP client/server library in C
  5. * Copyright (C) 2003 Ferhat Ayaz
  6. *
  7. * This library is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU Library General Public
  9. * License as published by the Free Software Foundation; either
  10. * version 2 of the License, or (at your option) any later version.
  11. *
  12. * This library is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * Library General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Library General Public
  18. * License along with this library; if not, write to the
  19. * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  20. * Boston, MA 02111-1307, USA.
  21. *
  22. * Email: ayaz@jprogrammer.net
  23. ******************************************************************/
  24. #ifdef HAVE_CONFIG_H
  25. #include <config.h>
  26. #endif
  27. #ifdef HAVE_STRING_H
  28. #include <string.h>
  29. #endif
  30. #include <nanohttp/nanohttp-logging.h>
  31. #include "soap-fault.h"
  32. #include "soap-xml.h"
  33. /*
  34. Parameters:
  35. 1- soap_env_ns
  36. 2- soap_env_enc
  37. 3- xsi_ns
  38. 4- xsd_ns
  39. 5- faultcode
  40. 6- faultstring
  41. 7- faultactor
  42. 8- detail
  43. */
  44. #define _SOAP_FAULT_TEMPLATE_ \
  45. "<SOAP-ENV:Envelope xmlns:SOAP-ENV=\"%s\" SOAP-ENV:encoding=\"%s\"" \
  46. " xmlns:xsi=\"%s\"" \
  47. " xmlns:xsd=\"%s\">" \
  48. " <SOAP-ENV:Header />" \
  49. " <SOAP-ENV:Body>" \
  50. " <SOAP-ENV:Fault>"\
  51. " <faultcode>%s</faultcode>"\
  52. " <faultstring>%s</faultstring>"\
  53. " <faultactor>%s</faultactor>"\
  54. " <detail>%s</detail>"\
  55. " </SOAP-ENV:Fault>" \
  56. " </SOAP-ENV:Body>"\
  57. "</SOAP-ENV:Envelope>"
  58. static char *fault_vm = "VersionMismatch";
  59. static char *fault_mu = "MustUnderstand";
  60. static char *fault_client = "Client";
  61. static char *fault_server = "Server";
  62. xmlDocPtr
  63. soap_fault_build(fault_code_t fcode,
  64. const char *faultstring,
  65. const char *faultactor, const char *detail)
  66. {
  67. /* variables */
  68. char *faultcode;
  69. int bufferlen = 2000;
  70. char *buffer;
  71. xmlDocPtr fault; /* result */
  72. log_verbose1("Build fault");
  73. switch (fcode)
  74. {
  75. case Fault_VersionMismatch:
  76. faultcode = fault_vm;
  77. break;
  78. case Fault_MustUnderstand:
  79. faultcode = fault_mu;
  80. break;
  81. case Fault_Client:
  82. faultcode = fault_client;
  83. break;
  84. case Fault_Server:
  85. faultcode = fault_server;
  86. break;
  87. default:
  88. faultcode = fault_client;
  89. }
  90. /* calculate buffer length */
  91. if (faultstring)
  92. bufferlen += strlen(faultstring);
  93. if (faultactor)
  94. bufferlen += strlen(faultactor);
  95. if (detail)
  96. bufferlen += strlen(detail);
  97. log_verbose2("Creating buffer with %d bytes", bufferlen);
  98. buffer = (char *) malloc(bufferlen);
  99. sprintf(buffer, _SOAP_FAULT_TEMPLATE_,
  100. soap_env_ns, soap_env_enc, soap_xsi_ns,
  101. soap_xsd_ns, faultcode,
  102. faultstring ? faultstring : "error",
  103. faultactor ? faultactor : "", detail ? detail : "");
  104. fault = xmlParseDoc(BAD_CAST buffer);
  105. free(buffer);
  106. if (fault == NULL)
  107. {
  108. log_error1("Can not create xml document!");
  109. return soap_fault_build(fcode, "Can not create fault object in xml",
  110. "soap_fault_build()", NULL);
  111. }
  112. log_verbose2("Returning fault (%p)", fault);
  113. return fault;
  114. }