- fixed string to address parsing
[oweals/gnunet.git] / src / include / gnunet_server_lib.h
index f03d9625d8d242aa556b8fc306c339df9e48b200..7fb8ae76ce034be6fa9a081c6f824b56d53743f3 100644 (file)
@@ -46,7 +46,7 @@ extern "C"
 #define GNUNET_SERVER_MAX_MESSAGE_SIZE 65536
 
 /**
- * Largest supported message.
+ * Smallest supported message.
  */
 #define GNUNET_SERVER_MIN_BUFFER_SIZE sizeof (struct GNUNET_MessageHeader)
 
@@ -239,6 +239,14 @@ GNUNET_SERVER_client_set_timeout (struct GNUNET_SERVER_Client *client,
                                   struct GNUNET_TIME_Relative timeout);
 
 
+/**
+ * Set if a client should finish a pending write when disconnecting.
+ */
+void
+GNUNET_SERVER_client_set_finish_pending_write (struct GNUNET_SERVER_Client *client,
+                                               int finish);
+
+
 /**
  * Disable the warning the server issues if a message is not acknowledged
  * in a timely fashion.  Use this call if a client is intentionally delayed
@@ -463,10 +471,9 @@ GNUNET_SERVER_transmit_context_append_message (struct
 
 
 /**
- * Execute a transmission context.  If there is
- * an error in the transmission, the receive_done
- * method will be called with an error code (GNUNET_SYSERR),
- * otherwise with GNUNET_OK.
+ * Execute a transmission context.  If there is an error in the
+ * transmission, the receive_done method will be called with an error
+ * code (GNUNET_SYSERR), otherwise with GNUNET_OK.
  *
  * @param tc transmission context to use
  * @param timeout when to time out and abort the transmission
@@ -476,6 +483,22 @@ GNUNET_SERVER_transmit_context_run (struct GNUNET_SERVER_TransmitContext *tc,
                                     struct GNUNET_TIME_Relative timeout);
 
 
+/**
+ * Destroy a transmission context.  This function must not be called
+ * after 'GNUNET_SERVER_transmit_context_run'.
+ *
+ * @param tc transmission context to destroy
+ * @param success code to give to 'GNUNET_SERVER_receive_done' for
+ *        the client:  GNUNET_OK to keep the connection open and
+ *                          continue to receive
+ *                GNUNET_NO to close the connection (normal behavior)
+ *                GNUNET_SYSERR to close the connection (signal
+ *                          serious error)
+ */
+void
+GNUNET_SERVER_transmit_context_destroy (struct GNUNET_SERVER_TransmitContext
+                                        *tc, int success);
+
 
 /**
  * The notification context is the key datastructure for a conveniance
@@ -621,6 +644,64 @@ void
 GNUNET_SERVER_mst_destroy (struct GNUNET_SERVER_MessageStreamTokenizer *mst);
 
 
+/**
+ * Signature of a function to create a custom tokenizer.
+ *
+ * @param cls closure from 'GNUNET_SERVER_set_callbacks'
+ * @param client handle to client the tokenzier will be used for
+ * @return handle to custom tokenizer ('mst')
+ */
+typedef void* (*GNUNET_SERVER_MstCreateCallback) (void *cls,
+                                                  struct GNUNET_SERVER_Client *client);
+
+/**
+ * Signature of a function to destroy a custom tokenizer.
+ *
+ * @param cls closure from 'GNUNET_SERVER_set_callbacks'
+ * @param mst custom tokenizer handle
+ */
+typedef void (*GNUNET_SERVER_MstDestroyCallback) (void *cls, void *mst);
+
+/**
+ * Signature of a function to destroy a custom tokenizer.
+ *
+ * @param cls closure from 'GNUNET_SERVER_set_callbacks'
+ * @param mst custom tokenizer handle
+ * @param client_identity ID of client for which this is a buffer,
+ *        can be NULL (will be passed back to 'cb')
+ * @param buf input data to add
+ * @param size number of bytes in buf
+ * @param purge should any excess bytes in the buffer be discarded
+ *       (i.e. for packet-based services like UDP)
+ * @param one_shot only call callback once, keep rest of message in buffer
+ * @return GNUNET_OK if we are done processing (need more data)
+ *         GNUNET_NO if one_shot was set and we have another message ready
+ *         GNUNET_SYSERR if the data stream is corrupt 
+ */
+typedef int (*GNUNET_SERVER_MstReceiveCallback) (void *cls, void *mst,
+                                                 struct GNUNET_SERVER_Client *client,
+                                                 const char *buf, size_t size,
+                                                 int purge, int one_shot);
+
+
+/**
+ * Change functions used by the server to tokenize the message stream.
+ * (very rarely used).
+ *
+ * @param server server to modify
+ * @param create new tokenizer initialization function
+ * @param destroy new tokenizer destruction function
+ * @param receive new tokenizer receive function
+ * @param cls closure for 'create', 'receive', 'destroy' 
+ */
+void
+GNUNET_SERVER_set_callbacks (struct GNUNET_SERVER_Handle *server,
+                             GNUNET_SERVER_MstCreateCallback create,
+                             GNUNET_SERVER_MstDestroyCallback destroy,
+                             GNUNET_SERVER_MstReceiveCallback receive,
+                             void *cls);
+
+
 #if 0                           /* keep Emacsens' auto-indent happy */
 {
 #endif