gnunet_chat_service.h 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  1. /*
  2. This file is part of GNUnet.
  3. (C) 2009, 2011 Christian Grothoff (and other contributing authors)
  4. GNUnet is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published
  6. by the Free Software Foundation; either version 3, or (at your
  7. option) any later version.
  8. GNUnet is distributed in the hope that it will be useful, but
  9. WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with GNUnet; see the file COPYING. If not, write to the
  14. Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  15. Boston, MA 02111-1307, USA.
  16. */
  17. /**
  18. * @file include/gnunet_chat_service.h
  19. * @brief API for chatting via GNUnet
  20. * @author Christian Grothoff
  21. * @author Nathan Evans
  22. * @author Vitaly Minko
  23. */
  24. #ifndef GNUNET_CHAT_SERVICE_H
  25. #define GNUNET_CHAT_SERVICE_H
  26. #include "gnunet_util_lib.h"
  27. #ifdef __cplusplus
  28. extern "C"
  29. {
  30. #if 0 /* keep Emacsens' auto-indent happy */
  31. }
  32. #endif
  33. #endif
  34. #define GNUNET_CHAT_VERSION 0x00000003
  35. #define MAX_MESSAGE_LENGTH (32 * 1024)
  36. /**
  37. * Options for messaging. Compatible options can be OR'ed together.
  38. */
  39. enum GNUNET_CHAT_MsgOptions
  40. {
  41. /**
  42. * No special options.
  43. */
  44. GNUNET_CHAT_MSG_OPTION_NONE = 0,
  45. /**
  46. * Encrypt the message so that only the receiver can decrypt it.
  47. */
  48. GNUNET_CHAT_MSG_PRIVATE = 1,
  49. /**
  50. * Hide the identity of the sender.
  51. */
  52. GNUNET_CHAT_MSG_ANONYMOUS = 2,
  53. /**
  54. * Sign the content, authenticating the sender (using the provided private
  55. * key, which may represent a pseudonym).
  56. */
  57. GNUNET_CHAT_MSG_AUTHENTICATED = 4,
  58. /**
  59. * Require signed acknowledgment before completing delivery (and of course,
  60. * only acknowledge if delivery is guaranteed).
  61. */
  62. GNUNET_CHAT_MSG_ACKNOWLEDGED = 8,
  63. /**
  64. * Authenticate for the receiver, but ensure that receiver cannot prove
  65. * authenticity to third parties later. (not yet implemented)
  66. */
  67. GNUNET_CHAT_MSG_OFF_THE_RECORD = 16,
  68. };
  69. /**
  70. * Handle for a (joined) chat room.
  71. */
  72. struct GNUNET_CHAT_Room;
  73. /**
  74. * Callback used for notification that we have joined the room.
  75. *
  76. * @param cls closure
  77. * @return GNUNET_OK
  78. */
  79. typedef int (*GNUNET_CHAT_JoinCallback) (void *cls);
  80. /**
  81. * Callback used for notification about incoming messages.
  82. *
  83. * @param cls closure
  84. * @param room in which room was the message received?
  85. * @param sender what is the ID of the sender? (maybe NULL)
  86. * @param member_info information about the joining member
  87. * @param message the message text
  88. * @param timestamp when was the message sent?
  89. * @param options options for the message
  90. * @return GNUNET_OK to accept the message now, GNUNET_NO to
  91. * accept (but user is away), GNUNET_SYSERR to signal denied delivery
  92. */
  93. typedef int (*GNUNET_CHAT_MessageCallback) (void *cls,
  94. struct GNUNET_CHAT_Room * room,
  95. const GNUNET_HashCode * sender,
  96. const struct
  97. GNUNET_CONTAINER_MetaData *
  98. member_info, const char *message,
  99. struct GNUNET_TIME_Absolute
  100. timestamp,
  101. enum GNUNET_CHAT_MsgOptions
  102. options);
  103. /**
  104. * Callback used for notification that another room member has joined or left.
  105. *
  106. * @param cls closure
  107. * @param member_info will be non-null if the member is joining, NULL if he is
  108. * leaving
  109. * @param member_id hash of public key of the user (for unique identification)
  110. * @param options what types of messages is this member willing to receive?
  111. * @return GNUNET_OK
  112. */
  113. typedef int (*GNUNET_CHAT_MemberListCallback) (void *cls,
  114. const struct
  115. GNUNET_CONTAINER_MetaData *
  116. member_info,
  117. const struct
  118. GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded
  119. * member_id,
  120. enum GNUNET_CHAT_MsgOptions
  121. options);
  122. /**
  123. * Callback used for message delivery confirmations.
  124. *
  125. * @param cls closure
  126. * @param room in which room was the message received?
  127. * @param orig_seq_number sequence number of the original message
  128. * @param timestamp when was the message received?
  129. * @param receiver who is confirming the receipt?
  130. * @return GNUNET_OK to continue, GNUNET_SYSERR to refuse processing further
  131. * confirmations from anyone for this message
  132. */
  133. typedef int (*GNUNET_CHAT_MessageConfirmation) (void *cls,
  134. struct GNUNET_CHAT_Room * room,
  135. uint32_t orig_seq_number,
  136. struct GNUNET_TIME_Absolute
  137. timestamp,
  138. const GNUNET_HashCode *
  139. receiver);
  140. /**
  141. * Join a chat room.
  142. *
  143. * @param cfg configuration
  144. * @param nick_name nickname of the user joining (used to
  145. * determine which public key to use);
  146. * the nickname should probably also
  147. * be used in the member_info (as "EXTRACTOR_TITLE")
  148. * @param member_info information about the joining member
  149. * @param room_name name of the room
  150. * @param msg_options message options of the joining user
  151. * @param joinCallback which function to call when we've joined the room
  152. * @param join_cls argument to callback
  153. * @param messageCallback which function to call if a message has
  154. * been received?
  155. * @param message_cls argument to callback
  156. * @param memberCallback which function to call for join/leave notifications
  157. * @param member_cls argument to callback
  158. * @param confirmationCallback which function to call for confirmations
  159. * (maybe NULL)
  160. * @param confirmation_cls argument to callback
  161. * @param me member ID (pseudonym)
  162. * @return NULL on error
  163. */
  164. struct GNUNET_CHAT_Room *
  165. GNUNET_CHAT_join_room (const struct GNUNET_CONFIGURATION_Handle *cfg,
  166. const char *nick_name,
  167. struct GNUNET_CONTAINER_MetaData *member_info,
  168. const char *room_name,
  169. enum GNUNET_CHAT_MsgOptions msg_options,
  170. GNUNET_CHAT_JoinCallback joinCallback, void *join_cls,
  171. GNUNET_CHAT_MessageCallback messageCallback,
  172. void *message_cls,
  173. GNUNET_CHAT_MemberListCallback memberCallback,
  174. void *member_cls,
  175. GNUNET_CHAT_MessageConfirmation confirmationCallback,
  176. void *confirmation_cls, GNUNET_HashCode * me);
  177. /**
  178. * Send a message.
  179. *
  180. * @param room handle for the chat room
  181. * @param message message to be sent
  182. * @param options options for the message
  183. * @param receiver use NULL to send to everyone in the room
  184. * @param sequence_number where to write the sequence id of the message
  185. */
  186. void
  187. GNUNET_CHAT_send_message (struct GNUNET_CHAT_Room *room, const char *message,
  188. enum GNUNET_CHAT_MsgOptions options,
  189. const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded
  190. *receiver, uint32_t * sequence_number);
  191. /**
  192. * Leave a chat room.
  193. */
  194. void
  195. GNUNET_CHAT_leave_room (struct GNUNET_CHAT_Room *chat_room);
  196. #if 0
  197. /* these are not yet implemented / supported */
  198. /**
  199. * Callback function to iterate over rooms.
  200. *
  201. * @return GNUNET_OK to continue, GNUNET_SYSERR to abort iteration
  202. */
  203. typedef int (*GNUNET_CHAT_RoomIterator) (const char *room, const char *topic,
  204. void *cls);
  205. /**
  206. * List all of the (publically visible) chat rooms.
  207. * @return number of rooms on success, GNUNET_SYSERR if iterator aborted
  208. */
  209. int
  210. GNUNET_CHAT_list_rooms (struct GNUNET_GE_Context *ectx,
  211. struct GNUNET_GC_Configuration *cfg,
  212. GNUNET_CHAT_RoomIterator it, void *cls);
  213. #endif
  214. #if 0 /* keep Emacsens' auto-indent happy */
  215. {
  216. #endif
  217. #ifdef __cplusplus
  218. }
  219. #endif
  220. #endif
  221. /* end of gnunet_chat_service.h */