db_sockets.c 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. /* Copyright (C) 2014 Stony Brook University
  2. This file is part of Graphene Library OS.
  3. Graphene Library OS is free software: you can redistribute it and/or
  4. modify it under the terms of the GNU Lesser General Public License
  5. as published by the Free Software Foundation, either version 3 of the
  6. License, or (at your option) any later version.
  7. Graphene Library OS is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU Lesser General Public License for more details.
  11. You should have received a copy of the GNU Lesser General Public License
  12. along with this program. If not, see <http://www.gnu.org/licenses/>. */
  13. /*
  14. * db_socket.c
  15. *
  16. * This file contains operands for streams with URIs that start with "tcp:", "tcp.srv:", "udp:",
  17. * "udp.srv:".
  18. */
  19. #include "api.h"
  20. #include "pal.h"
  21. #include "pal_debug.h"
  22. #include "pal_defs.h"
  23. #include "pal_error.h"
  24. #include "pal_internal.h"
  25. /* 96 bytes is the minimal size of buffer to store a IPv4/IPv6 address */
  26. #define PAL_SOCKADDR_SIZE 96
  27. /* listen on a tcp socket */
  28. static int tcp_listen(PAL_HANDLE* handle, char* uri, int create) {
  29. return -PAL_ERROR_NOTIMPLEMENTED;
  30. }
  31. /* accept a tcp connection */
  32. static int tcp_accept(PAL_HANDLE handle, PAL_HANDLE* client) {
  33. return -PAL_ERROR_NOTIMPLEMENTED;
  34. }
  35. /* connect on a tcp socket */
  36. static int tcp_connect(PAL_HANDLE* handle, char* uri, int create) {
  37. return -PAL_ERROR_NOTIMPLEMENTED;
  38. }
  39. /* 'open' operation of tcp stream */
  40. static int tcp_open(PAL_HANDLE* handle, const char* type, const char* uri, int access, int share,
  41. int create, int options) {
  42. size_t uri_len = strlen(uri) + 1;
  43. if (uri_len > PAL_SOCKADDR_SIZE)
  44. return -PAL_ERROR_TOOLONG;
  45. char uri_buf[PAL_SOCKADDR_SIZE];
  46. memcpy(uri_buf, uri, uri_len);
  47. if (!strcmp_static(type, URI_TYPE_TCP_SRV))
  48. return tcp_listen(handle, uri_buf, create);
  49. if (!strcmp_static(type, URI_TYPE_TCP))
  50. return tcp_connect(handle, uri_buf, create);
  51. return -PAL_ERROR_NOTSUPPORT;
  52. }
  53. /* 'read' operation of tcp stream */
  54. static int64_t tcp_read(PAL_HANDLE handle, uint64_t offset, size_t len, void* buf) {
  55. return -PAL_ERROR_NOTIMPLEMENTED;
  56. }
  57. /* write' operation of tcp stream */
  58. static int64_t tcp_write(PAL_HANDLE handle, uint64_t offset, size_t len, const void* buf) {
  59. return -PAL_ERROR_NOTIMPLEMENTED;
  60. }
  61. /* used by 'open' operation of tcp stream for bound socket */
  62. static int udp_bind(PAL_HANDLE* handle, char* uri, int create) {
  63. return -PAL_ERROR_NOTIMPLEMENTED;
  64. }
  65. /* used by 'open' operation of tcp stream for connected socket */
  66. static int udp_connect(PAL_HANDLE* handle, char* uri) {
  67. return -PAL_ERROR_NOTIMPLEMENTED;
  68. }
  69. static int udp_open(PAL_HANDLE* hdl, const char* type, const char* uri, int access, int share,
  70. int create, int options) {
  71. char buf[PAL_SOCKADDR_SIZE];
  72. size_t len = strlen(uri);
  73. if (len >= PAL_SOCKADDR_SIZE)
  74. return -PAL_ERROR_TOOLONG;
  75. memcpy(buf, uri, len + 1);
  76. if (!strcmp_static(type, URI_TYPE_UDP_SRV))
  77. return udp_bind(hdl, buf, create);
  78. if (!strcmp_static(type, URI_TYPE_UDP))
  79. return udp_connect(hdl, buf);
  80. return -PAL_ERROR_NOTSUPPORT;
  81. }
  82. static int64_t udp_receive(PAL_HANDLE handle, uint64_t offset, size_t len, void* buf) {
  83. return -PAL_ERROR_NOTIMPLEMENTED;
  84. }
  85. static int64_t udp_receivebyaddr(PAL_HANDLE handle, uint64_t offset, size_t len, void* buf,
  86. char* addr, size_t addrlen) {
  87. return -PAL_ERROR_NOTIMPLEMENTED;
  88. }
  89. static int64_t udp_send(PAL_HANDLE handle, uint64_t offset, size_t len, const void* buf) {
  90. return -PAL_ERROR_NOTIMPLEMENTED;
  91. }
  92. static int64_t udp_sendbyaddr(PAL_HANDLE handle, uint64_t offset, size_t len, const void* buf,
  93. const char* addr, size_t addrlen) {
  94. return -PAL_ERROR_NOTIMPLEMENTED;
  95. }
  96. static int socket_delete(PAL_HANDLE handle, int access) {
  97. return -PAL_ERROR_NOTIMPLEMENTED;
  98. }
  99. static int socket_close(PAL_HANDLE handle) {
  100. return -PAL_ERROR_NOTIMPLEMENTED;
  101. }
  102. static int socket_attrquerybyhdl(PAL_HANDLE handle, PAL_STREAM_ATTR* attr) {
  103. return -PAL_ERROR_NOTIMPLEMENTED;
  104. }
  105. static int socket_getname(PAL_HANDLE handle, char* buffer, size_t count) {
  106. return -PAL_ERROR_NOTIMPLEMENTED;
  107. }
  108. struct handle_ops tcp_ops = {
  109. .getname = &socket_getname,
  110. .open = &tcp_open,
  111. .waitforclient = &tcp_accept,
  112. .read = &tcp_read,
  113. .write = &tcp_write,
  114. .delete = &socket_delete,
  115. .close = &socket_close,
  116. .attrquerybyhdl = &socket_attrquerybyhdl,
  117. };
  118. struct handle_ops udp_ops = {
  119. .getname = &socket_getname,
  120. .open = &udp_open,
  121. .read = &udp_receive,
  122. .write = &udp_send,
  123. .delete = &socket_delete,
  124. .close = &socket_close,
  125. .attrquerybyhdl = &socket_attrquerybyhdl,
  126. };
  127. struct handle_ops udpsrv_ops = {
  128. .getname = &socket_getname,
  129. .open = &udp_open,
  130. .readbyaddr = &udp_receivebyaddr,
  131. .writebyaddr = &udp_sendbyaddr,
  132. .delete = &socket_delete,
  133. .close = &socket_close,
  134. .attrquerybyhdl = &socket_attrquerybyhdl,
  135. };
  136. PAL_HANDLE _DkBroadcastStreamOpen(void) {
  137. return NULL;
  138. }
  139. static int64_t mcast_send(PAL_HANDLE handle, uint64_t offset, uint64_t size, const void* buf) {
  140. return -PAL_ERROR_NOTIMPLEMENTED;
  141. }
  142. static int64_t mcast_receive(PAL_HANDLE handle, uint64_t offset, uint64_t size, void* buf) {
  143. return -PAL_ERROR_NOTIMPLEMENTED;
  144. }
  145. static int mcast_close(PAL_HANDLE handle) {
  146. return -PAL_ERROR_NOTIMPLEMENTED;
  147. }
  148. struct handle_ops mcast_ops = {
  149. .write = &mcast_send,
  150. .read = &mcast_receive,
  151. .close = &mcast_close,
  152. };