DummyPRFileDesc.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. /**
  2. * @file DummyPRFileDesc.c
  3. * @author Ambroz Bizjak <ambrop7@gmail.com>
  4. *
  5. * @section LICENSE
  6. *
  7. * This file is part of BadVPN.
  8. *
  9. * BadVPN is free software: you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License version 2
  11. * as published by the Free Software Foundation.
  12. *
  13. * BadVPN is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License along
  19. * with this program; if not, write to the Free Software Foundation, Inc.,
  20. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  21. */
  22. #include <stdlib.h>
  23. #include <string.h>
  24. #include <limits.h>
  25. #include <prerror.h>
  26. #include <prmem.h>
  27. #include <misc/debug.h>
  28. #include <misc/offset.h>
  29. #include <nspr_support/DummyPRFileDesc.h>
  30. #ifndef NDEBUG
  31. int dummyprfiledesc_initialized = 0;
  32. #endif
  33. PRDescIdentity dummyprfiledesc_identity;
  34. static PRStatus method_close (PRFileDesc *fd)
  35. {
  36. return PR_SUCCESS;
  37. }
  38. static PRStatus method_getpeername (PRFileDesc *fd, PRNetAddr *addr)
  39. {
  40. PR_SetError(PR_UNKNOWN_ERROR, 0);
  41. return PR_FAILURE;
  42. }
  43. static PRIntn _PR_InvalidIntn (void)
  44. {
  45. ASSERT(0)
  46. PR_SetError(PR_INVALID_METHOD_ERROR, 0);
  47. return -1;
  48. }
  49. static PRInt16 _PR_InvalidInt16 (void)
  50. {
  51. ASSERT(0)
  52. PR_SetError(PR_INVALID_METHOD_ERROR, 0);
  53. return -1;
  54. }
  55. static PRInt32 _PR_InvalidInt32 (void)
  56. {
  57. ASSERT(0)
  58. PR_SetError(PR_INVALID_METHOD_ERROR, 0);
  59. return -1;
  60. }
  61. static PRInt64 _PR_InvalidInt64 (void)
  62. {
  63. ASSERT(0)
  64. PR_SetError(PR_INVALID_METHOD_ERROR, 0);
  65. return -1;
  66. }
  67. static PROffset32 _PR_InvalidOffset32 (void)
  68. {
  69. ASSERT(0)
  70. PR_SetError(PR_INVALID_METHOD_ERROR, 0);
  71. return -1;
  72. }
  73. static PROffset64 _PR_InvalidOffset64 (void)
  74. {
  75. ASSERT(0)
  76. PR_SetError(PR_INVALID_METHOD_ERROR, 0);
  77. return -1;
  78. }
  79. static PRStatus _PR_InvalidStatus (void)
  80. {
  81. ASSERT(0)
  82. PR_SetError(PR_INVALID_METHOD_ERROR, 0);
  83. return PR_FAILURE;
  84. }
  85. static PRFileDesc *_PR_InvalidDesc (void)
  86. {
  87. ASSERT(0)
  88. PR_SetError(PR_INVALID_METHOD_ERROR, 0);
  89. return NULL;
  90. }
  91. static PRIOMethods methods = {
  92. (PRDescType)0,
  93. method_close,
  94. (PRReadFN)_PR_InvalidInt32,
  95. (PRWriteFN)_PR_InvalidInt32,
  96. (PRAvailableFN)_PR_InvalidInt32,
  97. (PRAvailable64FN)_PR_InvalidInt64,
  98. (PRFsyncFN)_PR_InvalidStatus,
  99. (PRSeekFN)_PR_InvalidOffset32,
  100. (PRSeek64FN)_PR_InvalidOffset64,
  101. (PRFileInfoFN)_PR_InvalidStatus,
  102. (PRFileInfo64FN)_PR_InvalidStatus,
  103. (PRWritevFN)_PR_InvalidInt32,
  104. (PRConnectFN)_PR_InvalidStatus,
  105. (PRAcceptFN)_PR_InvalidDesc,
  106. (PRBindFN)_PR_InvalidStatus,
  107. (PRListenFN)_PR_InvalidStatus,
  108. (PRShutdownFN)_PR_InvalidStatus,
  109. (PRRecvFN)_PR_InvalidInt32,
  110. (PRSendFN)_PR_InvalidInt32,
  111. (PRRecvfromFN)_PR_InvalidInt32,
  112. (PRSendtoFN)_PR_InvalidInt32,
  113. (PRPollFN)_PR_InvalidInt16,
  114. (PRAcceptreadFN)_PR_InvalidInt32,
  115. (PRTransmitfileFN)_PR_InvalidInt32,
  116. (PRGetsocknameFN)_PR_InvalidStatus,
  117. method_getpeername,
  118. (PRReservedFN)_PR_InvalidIntn,
  119. (PRReservedFN)_PR_InvalidIntn,
  120. (PRGetsocketoptionFN)_PR_InvalidStatus,
  121. (PRSetsocketoptionFN)_PR_InvalidStatus,
  122. (PRSendfileFN)_PR_InvalidInt32,
  123. (PRConnectcontinueFN)_PR_InvalidStatus,
  124. (PRReservedFN)_PR_InvalidIntn,
  125. (PRReservedFN)_PR_InvalidIntn,
  126. (PRReservedFN)_PR_InvalidIntn,
  127. (PRReservedFN)_PR_InvalidIntn
  128. };
  129. int DummyPRFileDesc_GlobalInit (void)
  130. {
  131. ASSERT(!dummyprfiledesc_initialized)
  132. if ((dummyprfiledesc_identity = PR_GetUniqueIdentity("DummyPRFileDesc")) == PR_INVALID_IO_LAYER) {
  133. return 0;
  134. }
  135. #ifndef NDEBUG
  136. dummyprfiledesc_initialized = 1;
  137. #endif
  138. return 1;
  139. }
  140. void DummyPRFileDesc_Create (PRFileDesc *prfd)
  141. {
  142. ASSERT(dummyprfiledesc_initialized)
  143. memset(prfd, 0, sizeof(*prfd));
  144. prfd->methods = &methods;
  145. prfd->secret = NULL;
  146. prfd->identity = dummyprfiledesc_identity;
  147. }