PageRenderTime 45ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/tags/release-20100424/Source_Files/Network/SSLP_API.h

#
C Header | 164 lines | 26 code | 31 blank | 107 comment | 0 complexity | b0eb73b6ff12d8c23cd119f922d92ed3 MD5 | raw file
Possible License(s): LGPL-2.0, LGPL-2.1, BSD-3-Clause, GPL-3.0, LGPL-3.0, MPL-2.0-no-copyleft-exception, Zlib, GPL-2.0
  1. /*
  2. * SSLP_API.h - applications include this to use SSLP services.
  3. *
  4. * Copyright (c) 2001 Woody Zenfell, III.
  5. * woodyzenfell@hotmail.com
  6. This library is free software; you can redistribute it and/or
  7. modify it under the terms of the GNU Library General Public
  8. License as published by the Free Software Foundation; either
  9. version 2 of the License, or (at your option) any later version.
  10. This library is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13. Library General Public License for more details.
  14. You should have received a copy of the GNU Library General Public
  15. License along with this library; if not, write to the Free
  16. Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  17. * Simple Service Location Protocol (hope that name's ok with everyone, did not research it at all)
  18. * (Near-)conflict with well-known Secure Socket Layer is unfortunate, but I doubt anyone will mistake them :) .
  19. * Someone smart has surely done this better somewhere and has probably proven various characteristics,
  20. * but I decided to hack out my own anyway. Tough.
  21. *
  22. * The current implementation (and a small amount of the interface) relies on the SDL_net cross-platform
  23. * IP networking library. The current implementation (and no part of the interface) relies on my own
  24. * "SDL_netx" UDP broadcast companion to SDL_net, as well as some other features of SDL.
  25. *
  26. * for the Aleph One project, to do NBP-ish player location on non-AppleTalk networks. The current
  27. * implementation is a (significant) simplification of what this could or perhaps ought to be, but
  28. * it's sufficient for Aleph One's needs, which is all that matters right now. Besides, like I said,
  29. * I'm sure there's something better already out there that's designed for heavyweight application.
  30. *
  31. * Created by Woody Zenfell, III on Tue Sep 11 2001.
  32. */
  33. #ifndef SSLP_API_H
  34. #define SSLP_API_H
  35. #include <SDL_net.h>
  36. // SSLP does not "guarantee" anything about its findings - it's intended merely as an aid. This means (in particular)
  37. // a host that found a service via SSLP cannot assume that the service definitely exists at the host and port provided...
  38. // but it's a probably a good place to look ;)
  39. // Note: here's one sticky part, at the moment, for the sake of laziness, I share these constants between
  40. // the ServiceInstance (part of the API) and the SSLP_Packet network data format. Really, they should be
  41. // disentangled, but then I'd have to worry about them being different. ;)
  42. #define SSLP_MAX_TYPE_LENGTH 32
  43. #define SSLP_MAX_NAME_LENGTH 32
  44. // SSLP_ServiceInstance does not get written to network or file, so struct alignment no big whoop
  45. // sslps_address must have both parts in network (big-endian) byte order, though.
  46. struct SSLP_ServiceInstance {
  47. char sslps_type[SSLP_MAX_TYPE_LENGTH];
  48. char sslps_name[SSLP_MAX_NAME_LENGTH];
  49. IPaddress sslps_address; // "host" part ignored by SSLP_*_Service_Discovery()
  50. };
  51. // N.B.!!: currently, for ease of implementation, only one service can be searched for and only one service can
  52. // be made discoverable at a time. (You may do one of each simultaneously.)
  53. // No wildcard or regex matches are supported at this time.
  54. ////// General functions //////
  55. // If using a non-threaded implementation, you will need to be sure to call this function every once in a while
  56. // to give SSLP some processing time. Once a second ought to be plenty, but more or less often should also work.
  57. // More frequent calls result in more responsive updates. Try to avoid taking more than 5 seconds between calls.
  58. // In a threaded implementation, threads will worry about themselves, and you never need to call SSLP_Pump().
  59. void
  60. SSLP_Pump();
  61. ////// Trying to locate remote services //////
  62. // SSLP_Locate_Service_Instances: Starts looking for service instances of inServiceType.
  63. // If one is found, inFoundCallback is invoked immediately (potentially in a different thread than was used to call
  64. // Locate_Service_Instances). Consider the ServiceInstance* to be valid until noted otherwise... you may store a reference
  65. // (no need to copy). You won't get another foundCallback for the same instance.
  66. // If one is lost, inLostCallback is invoked immediately (again, potentially in a different thread). You won't get
  67. // a lostCallback unless there had been a matching foundCallback (err, unless you gave NULL for foundCallback, which would
  68. // probably not be very useful).
  69. // Once inLostCallback returns, consider the ServiceInstance* invalid (i.e. hope you copied anything you needed).
  70. // If a service is found with a different name but at the same host and port as an existing one, inNameChangedCallback is invoked.
  71. // (you guessed it... from a different thread.)
  72. // Any Callback(s) may be NULL, in which case you receive no notification of the corresponding event.
  73. // The ServiceInstance pointer may be used to *identify* a service instance, while it's valid... that is,
  74. // no need to "deep compare" the whole records. In particular, inLostCallback and inNameChangedCallback will get
  75. // a pointer that was previously passed to inFoundCallback.
  76. // NB!! in the current (limited) implementation, you may only have one service-location attempt ongoing at a time.
  77. // Calling this function twice without an intervening call to Stop_Locating_Service_Instances is an ERROR, and may
  78. // result in the termination of the entire application!
  79. // One more note: in the single-threaded SSLP implementation, callbacks will occur in whatever thread calls
  80. // SSLP_Pump(), so synchronization is much less of an issue.
  81. typedef void (*SSLP_Service_Instance_Status_Changed_Callback)(const SSLP_ServiceInstance* inService);
  82. void
  83. SSLP_Locate_Service_Instances(const char* inServiceType, SSLP_Service_Instance_Status_Changed_Callback inFoundCallback,
  84. SSLP_Service_Instance_Status_Changed_Callback inLostCallback,
  85. SSLP_Service_Instance_Status_Changed_Callback inNameChangedCallback);
  86. // SSLP_Stop_Locating_Service_Instances: stop looking for a particular service type.
  87. // If NULL is passed as the argument, stop all ongoing service-location efforts.
  88. // After this call returns, the callback functions will no longer be called.
  89. // After this call returns, ALL ServiceInstances that were passed to the "found" callback are invalid.
  90. // You will not receive "lost" callbacks for them.
  91. // NB!! in the current (limited) implementation, the argument is ignored altogether. The ongoing
  92. // service-location process is stopped... if there is no process ongoing, calling this function is an
  93. // ERROR and may result in the termination of the entire application!
  94. void
  95. SSLP_Stop_Locating_Service_Instances(const char* inServiceType);
  96. ////// Allowing your services to be discovered //////
  97. // Allow_Service_Discovery: let people looking for your type of service find your service-instance.
  98. // ServiceInstance's data is copied, so you may do whatever you want with your storage.
  99. // The "host" part of the address is ignored... the "port" says which port on the local machine the service
  100. // may be contacted at.
  101. // NB!! in the current (limited) implementation, only one service instance may be available for discovery
  102. // at a time... calling this function twice without an intervening Disallow_Service_Discovery is an ERROR and
  103. // may abort the entire application!
  104. void
  105. SSLP_Allow_Service_Discovery(const SSLP_ServiceInstance* inServiceInstance);
  106. // SSLP_Hint_Service_Discovery: start periodically announcing the presence of a service-instance to a named machine and port.
  107. // (this is useful if you need a way to connect machines in different broadcast domains, which ordinarily would not see
  108. // each other by SSLP.)
  109. // If remoteHost->port is 0, the default SSLP_PORT will be used. This is almost certainly what you want.
  110. // Make sure the data in inRemoteHost are in network (big-endian) byte order!
  111. // If Allow_Service_Discovery was not already called for this service-instance, it's called by this function.
  112. // The data you provide are copied, so you may do whatever you like with your own storage afterwards.
  113. // NB!! in the current (limited) implementation, a call to this function with a service-instance that differs
  114. // from the one provided to Allow_Service_Discovery is an ERROR and may lead to odd results.
  115. // (calling this without having called Allow_Service_Discovery is ok, and makes the other call for you.)
  116. // Calling this with a different serviceInstance or remote address will change the hinting behavior to reflect
  117. // your wishes.
  118. void
  119. SSLP_Hint_Service_Discovery(const SSLP_ServiceInstance* inServiceInstance, const IPaddress* inRemoteHost);
  120. // SSLP_Disallow_Service_Discovery: stop letting other machines know that the service-instance is available.
  121. // If NULL is provided, the effect is of calling Disallow_Service_Discovery on every currently-discoverable service instance.
  122. // Also stops hinting the applicable service-instance(s), if appropriate.
  123. // NB!! in the current (limited) implementation, the argument provided is ignored altogether. Any hinting is stopped and
  124. // the service-instance currently being published is unpublished. It is an ERROR in the current implementation to call this
  125. // twice without an intervening call to Allow_Service_Discovery (possibly via Hint_Service_Discovery), and doing so may
  126. // abort the entire application!
  127. void
  128. SSLP_Disallow_Service_Discovery(const SSLP_ServiceInstance* inServiceInstance);
  129. #endif//SSLP_API_H