condvar ->cond
authorPekka Riikonen <priikone@silcnet.org>
Thu, 29 Jun 2006 21:04:33 +0000 (21:04 +0000)
committerPekka Riikonen <priikone@silcnet.org>
Thu, 29 Jun 2006 21:04:33 +0000 (21:04 +0000)
Added silc_mime_steal_data.

lib/silcutil/DIRECTORY
lib/silcutil/silccond.h [moved from lib/silcutil/silccondvar.h with 65% similarity]
lib/silcutil/silcmime.c
lib/silcutil/silcmime.h
lib/silcutil/silcsocketstream.h
lib/silcutil/unix/silcunixthread.c
lib/silcutil/win32/silcwin32thread.c

index d72eb1aac2f63a76fdf99e5fda37b3800ec9c323..6aa43e1aee78f8bf0cdfe7c48382fac6fcf9cf5a 100644 (file)
@@ -9,7 +9,7 @@
 @LINK=silcmemory.html:SILC Memory Interface
 @LINK=silcthread.html:SILC Thread Interface
 @LINK=silcmutex.html:SILC Mutex Interface
-@LINK=silccondvar.html:SILC Conditional Variable Interface
+@LINK=silccond.html:SILC Conditional Variable Interface
 @LINK=silcnet.html:SILC Network Interface
 @LINK=silcschedule.html:SILC Schedule Interface
 @LINK=silcsockconn.html:SILC Socket Interface
similarity index 65%
rename from lib/silcutil/silccondvar.h
rename to lib/silcutil/silccond.h
index ada9007ef2c15d6bdb120c9f434d38cf0da314f6..25f7c92cb676570f63f84dcfdfe79e377880fbdd 100644 (file)
@@ -1,6 +1,6 @@
 /*
 
-  silccondvar.h
+  silccond.h
 
   Author: Pekka Riikonen <priikone@silcnet.org>
 
  *
  ***/
 
-#ifndef SILCCONDVAR_H
-#define SILCCONDVAR_H
+#ifndef SILCCOND_H
+#define SILCCOND_H
 
-/****s* silcutil/SilcCondVarAPI/SilcCondVar
+/****s* silcutil/SilcCondAPI/SilcCond
  *
  * NAME
  *
- *    typedef struct SilcCondVarStruct *SilcCondVar;
+ *    typedef struct SilcCondStruct *SilcCond;
  *
  * DESCRIPTION
  *
  *    This context is the actual conditional variable and is allocated
- *    by silc_condvar_alloc and given as argument to all silc_condvar_*
- *    functions.  It is freed by the silc_condvar_free function.
+ *    by silc_cond_alloc and given as argument to all silc_cond_*
+ *    functions.  It is freed by the silc_cond_free function.
  *
  ***/
-typedef struct SilcCondVarStruct *SilcCondVar;
+typedef struct SilcCondStruct *SilcCond;
 
-/****s* silcutil/SilcCondVarAPI/silc_condvar_alloc
+/****s* silcutil/SilcCondAPI/silc_cond_alloc
  *
  * SYNOPSIS
  *
- *    SilcBool silc_condvar_alloc(SilcCondVar *cond);
+ *    SilcBool silc_cond_alloc(SilcCond *cond);
  *
  * DESCRIPTION
  *
  *    Allocates SILC Conditional variable context.  The conditional must
  *    be allocated before it can be used.  It is freed by the
- *    silc_condvar_free function.  This returns TRUE and allocated
+ *    silc_cond_free function.  This returns TRUE and allocated
  *    conditional in to the `cond' pointer and FALSE on error.
  *
  ***/
-SilcBool silc_condvar_alloc(SilcCondVar *cond);
+SilcBool silc_cond_alloc(SilcCond *cond);
 
-/****s* silcutil/SilcCondVarAPI/silc_condvar_free
+/****s* silcutil/SilcCondAPI/silc_cond_free
  *
  * SYNOPSIS
  *
- *    void silc_condvar_free(SilcCondVar cond);
+ *    void silc_cond_free(SilcCond cond);
  *
  * DESCRIPTION
  *
@@ -73,13 +73,13 @@ SilcBool silc_condvar_alloc(SilcCondVar *cond);
  *    has no effect.
  *
  ***/
-void silc_condvar_free(SilcCondVar cond);
+void silc_cond_free(SilcCond cond);
 
-/****s* silcutil/SilcCondVarAPI/silc_condvar_wait
+/****s* silcutil/SilcCondAPI/silc_cond_wait
  *
  * SYNOPSIS
  *
- *    void silc_condvar_wait(SilcCondVar cond, SilcMutex mutex);
+ *    void silc_cond_wait(SilcCond cond, SilcMutex mutex);
  *
  * DESCRIPTION
  *
@@ -93,19 +93,18 @@ void silc_condvar_free(SilcCondVar cond);
  *
  *    silc_mutex_lock(lock);
  *    while (c->a == NULL)
- *      silc_condvar_wait(cond, lock);
+ *      silc_cond_wait(cond, lock);
  *    ...
  *    silc_mutex_unlock(lock);
  *
  ***/
-void silc_condvar_wait(SilcCondVar cond, SilcMutex mutex);
+void silc_cond_wait(SilcCond cond, SilcMutex mutex);
 
-/****s* silcutil/SilcCondVarAPI/silc_condvar_timedwait
+/****s* silcutil/SilcCondAPI/silc_cond_timedwait
  *
  * SYNOPSIS
  *
- *    void silc_condvar_timedwait(SilcCondVar cond, SilcMutex mutex,
- *                                struct timespec *timeout);
+ *    void silc_cond_timedwait(SilcCond cond, SilcMutex mutex, int timeout);
  *
  * DESCRIPTION
  *
@@ -119,41 +118,40 @@ void silc_condvar_wait(SilcCondVar cond, SilcMutex mutex);
  *    state again.
  *
  ***/
-SilcBool silc_condvar_timedwait(SilcCondVar cond, SilcMutex mutex,
-                               int timeout);
+SilcBool silc_cond_timedwait(SilcCond cond, SilcMutex mutex, int timeout);
 
-/****s* silcutil/SilcCondVarAPI/silc_condvar_signal
+/****s* silcutil/SilcCondAPI/silc_cond_signal
  *
  * SYNOPSIS
  *
- *    void silc_condvar_signal(SilcCondVar cond);
+ *    void silc_cond_signal(SilcCond cond);
  *
  * DESCRIPTION
  *
  *    Signals a waiting thread and wakes it up.  If there are no waiters
  *    this function has no effect.  In case of multiple waiters only one
- *    is signalled.  To signal all of them use silc_condvar_broadcast.
+ *    is signalled.  To signal all of them use silc_cond_broadcast.
  *
  * NOTES
  *
- *    Before calling this function the mutex used with the silc_condvar_wait
+ *    Before calling this function the mutex used with the silc_cond_wait
  *    must be acquired.
  *
  * EXAMPLE
  *
  *    silc_mutex_lock(lock);
  *    c->a = context;
- *    silc_condvar_signal(cond);
+ *    silc_cond_signal(cond);
  *    silc_mutex_unlock(lock);
  *
  ***/
-void silc_condvar_signal(SilcCondVar cond);
+void silc_cond_signal(SilcCond cond);
 
-/****s* silcutil/SilcCondVarAPI/silc_condvar_broadcast
+/****s* silcutil/SilcCondAPI/silc_cond_broadcast
  *
  * SYNOPSIS
  *
- *    void silc_condvar_broadcast(SilcCondVar cond);
+ *    void silc_cond_broadcast(SilcCond cond);
  *
  * DESCRIPTION
  *
@@ -162,10 +160,10 @@ void silc_condvar_signal(SilcCondVar cond);
  *
  * NOTES
  *
- *    Before calling this function the mutex used with the silc_condvar_wait
+ *    Before calling this function the mutex used with the silc_cond_wait
  *    must be acquired.
  *
  ***/
-void silc_condvar_broadcast(SilcCondVar cond);
+void silc_cond_broadcast(SilcCond cond);
 
-#endif /* SILCCONDVAR_H */
+#endif /* SILCCOND_H */
index 5aa66c17362d001a6241eaecb173c53d983dec66..211b36c3b8dfecb858f85805c225fcfcffd2480b 100644 (file)
@@ -4,7 +4,7 @@
 
   Author: Pekka Riikonen <priikone@silcnet.org>
 
-  Copyright (C) 2005 Pekka Riikonen
+  Copyright (C) 2005 - 2006 Pekka Riikonen
 
   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
@@ -729,6 +729,26 @@ const unsigned char *silc_mime_get_data(SilcMime mime, SilcUInt32 *data_len)
   return mime->data;
 }
 
+/* Steal data */
+
+unsigned char *silc_mime_steal_data(SilcMime mime, SilcUInt32 *data_len)
+{
+  unsigned char *data;
+
+  if (!mime)
+    return NULL;
+
+  if (data_len)
+    *data_len = mime->data_len;
+
+  data = mime->data;
+
+  mime->data = NULL;
+  mime->data_len = 0;
+
+  return data;
+}
+
 /* Returns TRUE if partial message */
 
 SilcBool silc_mime_is_partial(SilcMime mime)
index 649c3d369c3e91a450c7de8a2d7f7242b6c6ce86..653a662527441626f3a110efbd2fa663cd218279 100644 (file)
@@ -4,7 +4,7 @@
 
   Author: Pekka Riikonen <priikone@silcnet.org>
 
-  Copyright (C) 2005 Pekka Riikonen
+  Copyright (C) 2005 - 2006 Pekka Riikonen
 
   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
@@ -290,6 +290,22 @@ void silc_mime_add_data(SilcMime mime, const unsigned char *data,
  ***/
 const unsigned char *silc_mime_get_data(SilcMime mime, SilcUInt32 *data_len);
 
+/****f* silcutil/SILCMIMEAPI/silc_mime_steal_data
+ *
+ * SYNOPSIS
+ *
+ *    unsigned char *
+ *    silc_mime_steal_data(SilcMime mime, SilcUInt32 *data_len);
+ *
+ * DESCRIPTION
+ *
+ *    Returns the MIME data from the `mime' message.  The data will be
+ *    removed from the `mime' and the caller is responsible of freeing the
+ *    returned pointer.
+ *
+ ***/
+unsigned char *silc_mime_steal_data(SilcMime mime, SilcUInt32 *data_len);
+
 /****f* silcutil/SILCMIMEAPI/silc_mime_is_partial
  *
  * SYNOPSIS
index a83a44b7963ba9e80fde1978d117dbf98307c4b5..08dbbcc1ebb20b5ac69d5ee305db02c2d1a37223 100644 (file)
@@ -4,7 +4,7 @@
 
   Author: Pekka Riikonen <priikone@silcnet.org>
 
-  Copyright (C) 2005 Pekka Riikonen
+  Copyright (C) 2005 - 2006 Pekka Riikonen
 
   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
@@ -69,7 +69,7 @@ typedef enum {
  *
  *    Callback function of this type is called after the socket stream
  *    creation is completed.  If the `stream' is NULL the socket stream could
- *    not be created of the socket connection is not otherwise allowed.  The
+ *    not be created or the socket connection is not otherwise allowed.  The
  *    `status' will indicate the error status.  The `stream' is socket stream
  *    representing the socket connection and silc_socket_stream_* functions
  *    can be used to access the stream.  All other silc_stream_* functions
@@ -99,7 +99,7 @@ typedef void (*SilcSocketStreamCallback)(SilcSocketStreamStatus status,
  *    and silc_stream_read.  The creation process is asynchronous since
  *    socket connection information, such as hostname and IP address are
  *    resolved, so SilcAsyncOperation is returned which can be used to cancel
- *    the creationg process.  The `callback' will be called to return the
+ *    the creation process.  The `callback' will be called to return the
  *    created socket stream.  To destroy the stream call silc_stream_destroy.
  *
  *    If the `lookup' is TRUE then this will performed IP and hostname lookup
@@ -117,6 +117,20 @@ silc_socket_stream_create(int sock, SilcBool lookup,
                          SilcSocketStreamCallback callback,
                          void *context);
 
+SilcAsyncOperation
+silc_socket_tcp_stream_create(int sock, SilcBool lookup,
+                             SilcBool require_fqdn,
+                             SilcSchedule schedule,
+                             SilcSocketStreamCallback callback,
+                             void *context);
+
+SilcAsyncOperation
+silc_socket_udp_stream_create(int sock, SilcBool lookup,
+                             SilcBool require_fqdn,
+                             SilcSchedule schedule,
+                             SilcSocketStreamCallback callback,
+                             void *context);
+
 /****f* silcutil/SilcSocketStreamAPI/silc_socket_stream_get_info
  *
  * SYNOPSIS
index b32f61d62d6d663f4042b7d6b513ae65ea6f0dcc..3c5cb65904393e49d1e2089d47d03aa77a797060 100644 (file)
@@ -153,10 +153,10 @@ void silc_mutex_unlock(SilcMutex mutex)
 }
 
 
-/**************************** SILC CondVar API ******************************/
+/**************************** SILC Cond API ******************************/
 
 /* SILC Conditional Variable context */
-struct SilcCondVarStruct {
+struct SilcCondStruct {
 #ifdef SILC_THREADS
   pthread_cond_t cond;
 #else
@@ -164,7 +164,7 @@ struct SilcCondVarStruct {
 #endif /* SILC_THREADS*/
 };
 
-SilcBool silc_condvar_alloc(SilcCondVar *cond)
+SilcBool silc_cond_alloc(SilcCond *cond)
 {
 #ifdef SILC_THREADS
   *cond = silc_calloc(1, sizeof(**cond));
@@ -177,7 +177,7 @@ SilcBool silc_condvar_alloc(SilcCondVar *cond)
 #endif /* SILC_THREADS*/
 }
 
-void silc_condvar_free(SilcCondVar cond)
+void silc_cond_free(SilcCond cond)
 {
 #ifdef SILC_THREADS
   pthread_cond_destroy(&cond->cond);
@@ -185,29 +185,29 @@ void silc_condvar_free(SilcCondVar cond)
 #endif /* SILC_THREADS*/
 }
 
-void silc_condvar_signal(SilcCondVar cond)
+void silc_cond_signal(SilcCond cond)
 {
 #ifdef SILC_THREADS
   pthread_cond_signal(&cond->cond);
 #endif /* SILC_THREADS*/
 }
 
-void silc_condvar_broadcast(SilcCondVar cond)
+void silc_cond_broadcast(SilcCond cond)
 {
 #ifdef SILC_THREADS
   pthread_cond_broadcast(&cond->cond);
 #endif /* SILC_THREADS*/
 }
 
-void silc_condvar_wait(SilcCondVar cond, SilcMutex mutex)
+void silc_cond_wait(SilcCond cond, SilcMutex mutex)
 {
 #ifdef SILC_THREADS
   pthread_cond_wait(&cond->cond, &mutex->mutex);
 #endif /* SILC_THREADS*/
 }
 
-SilcBool silc_condvar_timedwait(SilcCondVar cond, SilcMutex mutex,
-                               int timeout)
+SilcBool silc_cond_timedwait(SilcCond cond, SilcMutex mutex,
+                            int timeout)
 {
 #ifdef SILC_THREADS
   struct timespec t;
index f55a55ac8090851af7374ebb1809d16973548bff..0d82f5598d5fd25e0c30c1562b7f4ffc835a3eae 100644 (file)
@@ -205,10 +205,10 @@ void silc_mutex_unlock(SilcMutex mutex)
 }
 
 
-/**************************** SILC CondVar API ******************************/
+/**************************** SILC Cond API ******************************/
 
 /* SILC Conditional Variable context */
-struct SilcCondVarStruct {
+struct SilcCondStruct {
 #ifdef SILC_THREADS
   HANDLE event;
 #endif /* SILC_THREADS*/
@@ -216,7 +216,7 @@ struct SilcCondVarStruct {
   unsigned int signal  : 1;
 };
 
-SilcBool silc_condvar_alloc(SilcCondVar *cond)
+SilcBool silc_cond_alloc(SilcCond *cond)
 {
 #ifdef SILC_THREADS
   *cond = silc_calloc(1, sizeof(**cond));
@@ -229,7 +229,7 @@ SilcBool silc_condvar_alloc(SilcCondVar *cond)
 #endif /* SILC_THREADS*/
 }
 
-void silc_condvar_free(SilcCondVar cond)
+void silc_cond_free(SilcCond cond)
 {
 #ifdef SILC_THREADS
   CloseHandle(cond->event);
@@ -237,7 +237,7 @@ void silc_condvar_free(SilcCondVar cond)
 #endif /* SILC_THREADS*/
 }
 
-void silc_condvar_signal(SilcCondVar cond)
+void silc_cond_signal(SilcCond cond)
 {
 #ifdef SILC_THREADS
   cond->signal = TRUE;
@@ -245,7 +245,7 @@ void silc_condvar_signal(SilcCondVar cond)
 #endif /* SILC_THREADS*/
 }
 
-void silc_condvar_broadcast(SilcCondVar cond)
+void silc_cond_broadcast(SilcCond cond)
 {
 #ifdef SILC_THREADS
   cond->signal = TRUE;
@@ -253,15 +253,15 @@ void silc_condvar_broadcast(SilcCondVar cond)
 #endif /* SILC_THREADS*/
 }
 
-void silc_condvar_wait(SilcCondVar cond, SilcMutex mutex)
+void silc_cond_wait(SilcCond cond, SilcMutex mutex)
 {
 #ifdef SILC_THREADS
-  silc_condvar_timedwait(cond, mutex, NULL);
+  silc_cond_timedwait(cond, mutex, NULL);
 #endif /* SILC_THREADS*/
 }
 
-SilcBool silc_condvar_timedwait(SilcCondVar cond, SilcMutex mutex,
-                               int timeout)
+SilcBool silc_cond_timedwait(SilcCond cond, SilcMutex mutex,
+                            int timeout)
 {
 #ifdef SILC_THREADS
   DWORD ret, t = INFINITE;