updates.
authorPekka Riikonen <priikone@silcnet.org>
Wed, 23 May 2007 15:29:42 +0000 (15:29 +0000)
committerPekka Riikonen <priikone@silcnet.org>
Wed, 23 May 2007 15:29:42 +0000 (15:29 +0000)
lib/doc/porting.html
lib/doc/silcclient_using.html
scripts/silcdoc/gen_index.php
tutorial/mybot/Makefile
tutorial/mybot/mybot.c

index 6621298a97218b160ed42009767fab230122cc8f..8ba22464af37dcf1623a09b297513c7cdd3bea4c 100644 (file)
@@ -7,6 +7,7 @@ to the new Toolkit version.
 
 <br />&nbsp;<br />
 <li><a href="#general">General</a><br />
+<li><a href="#platform">Platform changes</a>
 <li><a href="#client">Client library</a><br />
 <li><a href="#util">Utility library</a><br />
 <li><a href="#apputil">Application utility library</a>
@@ -15,7 +16,6 @@ to the new Toolkit version.
 <li><a href="#vcard">VCard library</a>
 <li><a href="#http">HTTP library</a>
 <li><a href="#asn1">ASN.1 library</a>
-<li><a href="#other">Other libraries</a>
 
 <br />&nbsp;<br />
 <h3><a name="general"></a>General changes</h3>
@@ -25,6 +25,15 @@ to silc.h.  The first task in porting from 1.0 to 1.1 is to change these
 filenames in your source tree.
 
 
+<br />&nbsp;<br />
+<h3><a name="platform"></a>Platform changes</h3>
+
+The Windows support has been made better by improving the SILC scheduler
+and network routines.  Calling silc_net_win32_init and silc_net_win32_uninit
+is not needed anymore.  The network routines on Windows are enabled
+automatically.
+
+
 <br />&nbsp;<br />
 <h3><a name="client"></a>Client library, lib/silcclient/</h3>
 
@@ -206,8 +215,9 @@ silc_client_del_socket has been removed.  They are no longer needed.
 Just like in Toolkit 1.0 we now have SilcClientEntry to represent user,
 SilcChannelEntry to represent channel and SilcServerEntry to represent
 server.  In the past these structures and all API functions that dealt
-with them were in silcclient.h file.  They are now in silcclient_entry.h
-in Toolkit 1.1.
+with them were in <a href="silcclient.html">silcclient.h</a> file.  They
+are now in <a href="silcclient_entry.html">silcclient_entry.h</a> in
+Toolkit 1.1.
 
 <br />&nbsp;<br />
 As an general convention each of these new entries now are reference
@@ -421,25 +431,28 @@ nickname of a certain client entry.
 The Utility library (runtime library) has had several changes and has several
 new interfaces.  Some interfaces has also been removed or moved to some
 other library.  Removed interfaces rae: silcprotocol.h and silcsockconn.h.
-Moved interfaces are: silcapputil.h and silcvcard.h.
+Moved interfaces are: <a href="silcapputil.html">silcapputil.h</a> and
+<a href="silcvcard.html">silcvcard.h</a>.
 
 <h4>SILC Async Operation Interface</h4>
 
-A new asynchronous operation API (silcasync.h) has been added.  It can be
-used to control asynchronous operations, like to cancel them.  Many
-asynchronous routines in SILC Toolkit now return SilcAsyncOperation context
-so that the operation can be controlled by the caller.  It especiallly
-provides a generic way to cancel asynchronous operations which
-can be difficult.
+A new asynchronous operation API (<a href="silcasync.html">silcasync.h</a>)
+has been added.  It can be used to control asynchronous operations, like
+to cancel them.  Many asynchronous routines in SILC Toolkit now return
+SilcAsyncOperation context so that the operation can be controlled by the
+caller.  It especiallly provides a generic way to cancel asynchronous
+operations which can be difficult.
 
 <h4>SILC Atomic Operations Interface</h4>
 
-A new atomic operations API (silcatomic.h) has been added.  It provides
-routines to perform various operations on integeres and pointers atomically.
+A new atomic operations API (<a href="silcatomic.html">silcatomic.h</a>)
+has been added.  It provides routines to perform various operations on
+integeres and pointers atomically.
 
 <h4>SILC Data Stack Interface</h4>
 
-A new data stack (memory pool system) API (silcstack.h) has been added.
+A new data stack (memory pool system) API
+(<a href="silcstack.html">silcstack.h</a>) has been added.
 It provides a fast memory allocation system.  Many routines in the SILC Toolkit
 are SilcStack aware thus enabling them to use the SilcStack as their source
 for memory allocation.  All routines that are SilcStack aware automatically
@@ -449,12 +462,14 @@ by default.
 
 <h4>SILC Condition Variable Interface</h4>
 
-A new condition variable API (silccond.h) has been added.  It provides
-condition variables for multithreaded applications.
+A new condition variable API (<a href="silccond.html">silccond.h</a>)
+has been added.  It provides condition variables for multithreaded
+applications.
 
 <h4>SILC Stream Interface</h4>
 
-A new abstract stream API (silcstream.h) has been added.  The SilcStream
+A new abstract stream API (<a href="silcstream.html">silcstream.h</a>)
+has been added.  The SilcStream
 provides an abstract way of representing different kinds of streams.  The
 API provides functions that can be used to read, write, control and destroy
 streams.  The API is not used to create streams but separate interfaces
@@ -463,19 +478,22 @@ socket stream and file descriptor stream exist.
 
 <h4>SILC FD Stream Interface</h4>
 
-A new file descriptor stream API (silcfdstream.h) has been added.  It
+A new file descriptor stream API
+(<a href="silcfdstream.html">silcfdstream.h</a>) has been added.  It
 provides a blocking and non-blocking file descriptor stream through the
 SilcStream abstraction.
 
 <h4>SILC Socket Stream Interface</h4>
 
-A new socket stream API (silcsocketstream.h) has been added.  It provides
-a blocking and non-blocking socket stream through the SilcStream
+A new socket stream API
+(<a href="silcsocketstream.html">silcsocketstream.h</a>) has been added.
+It provides a blocking and non-blocking socket stream through the SilcStream
 abstraction.
 
 <h4>SILC FSM Interface</h4>
 
-A new Finite State Machine API (silcfsm.h) has been added.  It provides
+A new Finite State Machine API
+(<a href="silcfsm.html">silcfsm.h</a>) has been added.  It provides
 an FSM that can be used to implement all kinds of machines and protocols.
 The machine also supports threads, and threads that are actually executed
 in real system threads.  The SILC FSM API also supports asynchronous
@@ -483,25 +501,28 @@ events.
 
 <h4>SILC Time Interface</h4>
 
-A new SILC Time API (silctime.h) has been added.  It provides utility
+A new SILC Time API
+(<a href="silctime.html">silctime.h</a>) has been added.  It provides utility
 functions to retrieve and represent time in different ways.  It supports
 Universal and Generalized time string creation and parsing and adds a new
 SilcTime structure to represent time.
 
 <h4>SILC Snprintf Interface</h4>
 
-A new snprintf API (silcsnprintf.h) has been added.  It provides snprintf
-and other string formatting routines.
+A new snprintf API
+(<a href="silcsnprintf.html">silcsnprintf.h</a>) has been added.  It
+provides snprintf and other string formatting routines.
 
 <h4>SILC Mutex Interface changes</h4>
 
-The SILC Mutex API (silcmutex) has several changes.  A support for read/write
-locks has been added (SilcRwLock).  Also silc_mutex_assert_locked function
-is added.
+The SILC Mutex API (<a href="silcmutex.html">silcmutex.h</a>)
+has several changes.  A support for read/write locks has been added
+(SilcRwLock).  Also silc_mutex_assert_locked function is added.
 
 <h4>SILC Network Interface changes</h4>
 
-The SILC Network API (silcnet.h) has several changes.  The API is almost
+The SILC Network API
+(<a href="silcnet.html">silcnet.h</a>) has several changes.  The API is almost
 entirely rewritten and most of the old functions have been removed.  The
 API has now both TCP and UDP support, and as previously supports IPv4
 and IPv6.  New functions are silc_net_tcp_create_listener,
@@ -510,8 +531,9 @@ silc_net_udp_connect, silc_net_udp_receive, silc_net_udp_send.
 
 <h4>SILC Scheduler Interface changes</h4>
 
-The SILC Schedule API (silcschedule.h) has several changes.  The scheduler
-has been entirely rewritten but most of the API remains the same.
+The SILC Schedule API
+(<a href="silcschedule.html">silcschedule.h</a>) has several changes.  The
+scheduler has been entirely rewritten but most of the API remains the same.
 The SILC_TASK_GENERIC and SILC_TASK_CALLBACK_GLOCAL have been removed.
 The way signal are dispatched has been changed.  The SILC Schedule is now
 able to itself dispatch all signals.  New functions are
@@ -523,12 +545,14 @@ removed.
 
 <h4>SILC Types Interface changes</h4>
 
-The SILC Type API (silctypes.h) has several changes.  The bool type is
-replaced with SilcBool.  Sockets are now represented by SilcSocket.
+The SILC Type API (<a href="silctypes.html">silctypes.h</a>) has several
+changes.  The bool type is replaced with SilcBool.  Sockets are now
+represented by SilcSocket.
 
 <h4>SILC String util Interface changes</h4>
 
-The SILC string utility API (silcstrutil.h) has changes.  The PEM encoding
+The SILC string utility API
+(<a href="silcstrutil.html">silcstrutil.h</a>) has changes.  The PEM encoding
 and decoding routines has been renamed, silc_base64_encode,
 silc_base64_encode_file and silc_base64_decode.  The silc_mime_parse has
 been removed.  A new silc_string_split function has been added.
@@ -538,18 +562,19 @@ been removed.  A new silc_string_split function has been added.
 
 <h4>SILC File Util Interface changes</h4>
 
-The SILC file utility API (silcfileutil.h) has changes.  A new function
-silc_file_set_nonblock has been added.
+The SILC file utility API (<a href="silcfileutil.html">silcfileutil.h</a>)
+has changes.  A new function silc_file_set_nonblock has been added.
 
 <h4>SILC List and Dynamic List Interface changes</h4>
 
-The SILC List (silclist.h) and SILC Dynamic List (silcdlist.h) APIs have
-changes. New functions silc_list_insert and silc_dlist_insert have been
-added.
+The SILC List (<a href="silclist.html">silclist.h</a>) and SILC Dynamic List
+(silcdlist.h) APIs have changes. New functions silc_list_insert and
+silc_dlist_insert have been added.
 
 <h4>SILC Buffer Interface changes</h4>
 
-The SILC Buffer API (silcbuffer.h) has several changes.  The SilcBuffer
+The SILC Buffer API (<a href="silcbuffer.html">silcbuffer.h</a>) has several
+changes.  The SilcBuffer
 structure no longer contain the buffer length and true length fields
 but silc_buffer_len() and silc_buffr_truelen() macros are available
 instead.  Also silc_buffer_data(), silc_buffer_datalen(), silc_buffer_purge(),
@@ -558,7 +583,8 @@ silc_buffer_enlarge() has been added.  The API also supports SilcStack.
 
 <h4>SILC Buffer Formatting Interface changes</h4>
 
-The SILC Buffer Formatting API (silcbuffmt.h) has several changes.  The
+The SILC Buffer Formatting API
+(<a href="silcbuffmt.html">silcbuffmt.h</a>) has several changes.  The
 silc_buffer_format now automatically allocates memory to the destination
 buffer if it does not have space.  Also new the following new formatters
 have been added: SILC_STR_DATA (replaces SILC_STR_UI_XNSTRING),
@@ -567,10 +593,10 @@ The API also supports SilcStack.
 
 <h4>SILC Memory Interface changes</h4>
 
-The memory allocation API (silcmemory.h) has several changes.  It supports
-now SilcStack as memory source.  Also all memory allocation routines can
-now fail and return NULL as opposed to fatally failing when memory allocation
-fails.
+The memory allocation API (<a href="silcmemory.html">silcmemory.h</a>) has
+several changes.  It supports now SilcStack as memory source.  Also all
+memory allocation routines can now fail and return NULL as opposed to fatally
+failing when memory allocation fails.
 
 <br />&nbsp;<br />
 <h3><a name="apputil"></a>SILC Application Utility library, lib/silcapputil/</h3>
@@ -583,7 +609,8 @@ does not contain any entirely new interfaces.
 
 <h4>SILC Application Utility Interface</h4>
 
-The silcapputil.h contains various application utility functions.  It
+The <a href="silcapputil.html">silcapputil.h</a> contains various application
+utility functions.  It
 existed in Toolkit 1.0 but some of the APIs has been changed.  The
 silc_create_key_pair, silc_load_key_pair and silc_show_public_key APIs
 has changed.  A new silc_show_public_key_file has been added.  Functions
@@ -596,15 +623,15 @@ libraries into this interface in Toolkit 1.1.
 
 <h4>SILC ID Cache Interface</h4>
 
-The ID Cache interface (silcidcache.h) has been moved from lib/silccore
-into lib/silcapputil/.
+The ID Cache interface (<a href="silcidcache.html">silcidcache.h</a>) has
+been moved from lib/silccore into lib/silcapputil/.
 
 <br />&nbsp;<br />
 <h3><a name="skr"></a>SILC Key Repository library, lib/silcskr/</h3>
 
 A new SILC Key Repository library has been added.  The library provides
-a SILC Key Repository API (silcskr.h) which provides a repository for
-storing and retrieving public keys.
+a SILC Key Repository API (a href="silcskr.html">silcskr.h</a>) which provides
+a repository for storing and retrieving public keys.
 
 <br />&nbsp;<br />
 <h3><a name="vcard"></a>SILC VCard library, lib/silcvcard/</h3>
@@ -620,14 +647,15 @@ Server Interface and SILC HTTP PHP Translator Interface.
 
 <h4>SILC HTTP Server Interface</h4>
 
-The SILC HTTP Server API (silchttpservder.h) provides a simple HTTP
-server implementation for applications that want to integrate a small
-HTTP server.
+The SILC HTTP Server API (<a href="silchttpserver.html">silchttpservder.h</a>)
+provides a simple HTTP server implementation for applications that want to
+integrate a small HTTP server.
 
 <h4>SILC HTTP PHP Translator Interface</h4>
 
-The SILC HTTP PHP Translator API (silchttpphp.h) provides PHP translates
-PHP code into HTML.  It can be used to serve PHP pages in HTTP server.
+The SILC HTTP PHP Translator API (<a href="silchttpphp.html">silchttpphp.h</a>)
+ provides PHP translates PHP code into HTML.  It can be used to serve PHP
+pages in HTTP server.
 
 <br />&nbsp;<br />
 <h3><a name="asn1"></a>SILC ASN.1 library, lib/silcasn1/</h3>
@@ -638,12 +666,13 @@ encoder and decoder interface.
 
 <h4>SILC ASN.1 Interface</h4>
 
-The SILC ASN.1 API (silcasn1.h) provides ASN.1 encoder and decoder.  The
-interface provides efficient encoder and decoder and is support SilcStack
-as memory source.  The interface is simple and it supports almost all ASN.1
-features.
+The SILC ASN.1 API (<a href="silcasn1.html">silcasn1.h</a>) provides ASN.1
+encoder and decoder.  The interface provides efficient encoder and decoder
+and is support SilcStack as memory source.  The interface is simple and it
+supports almost all ASN.1 features.
 
 <h4>SILC BER Interface</h4>
 
-The SILC BER API (silcber.h) provides BER/DER encoder and decoder.  It is
-integral part of the ASN.1 library and the ASN.1 encoder and decoder.
+The SILC BER API (<a href="silcber.html">silcber.h</a>) provides BER/DER
+encoder and decoder.  It is integral part of the ASN.1 library and the ASN.1
+encoder and decoder.
index c703cb38e0e8d87dfe402beb208534e129f76f27..b8830e82f51975f703d426c152520f368ea4ce9a 100644 (file)
@@ -20,10 +20,10 @@ interface routines in the functions and display the data whatever way
 it wants.  The library is entirely transparent to the user interface and
 it does not include any user interface specific issues such as window
 handling or item handling on the screen etc.  These does not interest
-the library.  The `silcclient.h' also defines the client libary interface
-the application can call.  The interface includes for example functions
-for sending channel and private messages, client and channel retrieval
-and other utility functions.
+the library.  The `silcclient.h' and `silcclient_entry.h' also defines the
+client libary interface the application can call.  The interface includes
+for example functions for sending channel and private messages, client and
+channel retrieval and other utility functions.
 
 <br />&nbsp;<br />&nbsp;<br />
 <b>Including Library Headers</b>
@@ -38,28 +38,6 @@ get access all SILC Client Library routines:
 #include "silcclient.h"
 </tt>
 
-<br />&nbsp;<br />&nbsp;<br />
-<b>Network Initialization on Win32</b>
-
-<br />&nbsp;<br />
-If you are programming your SILC client application on Windows system,
-you will need to initialize the network routines in order to be able
-to use the client library.  The network initialization is done by
-calling the silc_net_win32_init at the start of your Windows application.
-Usually this is done either in main() or WinMain() function, or other
-similar place.  This function should be called before calling any other
-SILC routine.
-
-<br />&nbsp;<br />
-<tt>
-if (silc_net_win32_init() == FALSE)<br />
-&nbsp;&nbsp;exit_with_error();
-</tt>
-
-<br />&nbsp;<br />
-This function is available only on Win32 platforms, and on other platforms
-the network routines are initialized automatically by the operating system.
-
 
 <br />&nbsp;<br />&nbsp;<br />
 <b>Creating Client</b>
@@ -76,19 +54,14 @@ The client object is SilcClient which is usually allocated in following
 manner:
 
 <br />&nbsp;<br />
-<tt>&nbsp;&nbsp;SilcClient client = silc_client_alloc(&ops, params, context, silc_version_string);</tt>
+<tt>&nbsp;&nbsp;SilcClient client = silc_client_alloc(&ops, params, context, NULL);</tt>
 
 <br />&nbsp;<br />
 `ops' is the static structure of client operations that library will call.
 `context' can be some application specific context that will be saved into
 the SilcClient object.  It is up to the caller to free this context.
 SilcClient is always passed to the application thus the application
-specific context can be retrieved from the SilcClient object.  See
-`client.h' file for detailed definition of SilcClient object.
-
-<br />&nbsp;<br />
-The `silc_version_string' is the current protocol version string, and you
-can get it by including `silcversion.h' header in your source code.
+specific context can be retrieved from the SilcClient object.
 
 <br />&nbsp;<br />
 `ops' can be defined for example as follows:
@@ -102,13 +75,11 @@ SilcClientOperations ops = {<br />
 &nbsp;&nbsp;  silc_notify,<br />
 &nbsp;&nbsp;  silc_command,<br />
 &nbsp;&nbsp;  silc_command_reply,<br />
-&nbsp;&nbsp;  silc_connect,<br />
-&nbsp;&nbsp;  silc_disconnect,<br />
 &nbsp;&nbsp;  silc_get_auth_method,<br />
 &nbsp;&nbsp;  silc_verify_public_key,<br />
 &nbsp;&nbsp;  silc_ask_passphrase,<br />
-&nbsp;&nbsp;  silc_failure,<br />
 &nbsp;&nbsp;  silc_key_agreement,<br />
+&nbsp;&nbsp;  silc_file_transfer,<br />
 };<br />
 </tt>
 
@@ -123,38 +94,19 @@ it and use it directly in their application.
 <b>Initializing the Client</b>
 
 <br />&nbsp;<br />
-The client must be initialized before running.  However, there are also
-some other tasks that must be done before initializing the client.
-The following pointers must be set by the application  before calling
-the initializing function:
+The client must be initialized before running.  The client is initialized
+simply by calling silc_client_init function:
 
 <br />&nbsp;<br />
-<tt>
-&nbsp;&nbsp;client->username<br />
-&nbsp;&nbsp;client->hostname<br />
-&nbsp;&nbsp;client->realname<br />
-&nbsp;&nbsp;client->pkcs<br />
-&nbsp;&nbsp;client->public_key<br />
-&nbsp;&nbsp;client->private_key
-</tt>
-
-<br />&nbsp;<br />
-You may also set client->nickname if you want.  If it is set then the
-library will change the nickname to that one after the client is connected
-to the server.  If not set, then server will initially give the nickname
-which is same as the username.
-
-<br />&nbsp;<br />
-After setting the pointers one must call:
+<tt>&nbsp;&nbsp;silc_client_init(client, username, hostname, realname,
+                                 foo_client_running, foo_ctx);</tt>
 
 <br />&nbsp;<br />
-<tt>&nbsp;&nbsp;silc_client_init(client);</tt>
-
-<br />&nbsp;<br />
-which then initializes the client library for the `client'.  If the
-pointers mentioned above are not initialized the silc_client_init will
-fail.  The application should check the return value of the silc_client_init
-function.
+which then initializes the client library for the `client'.  The `username'
+and `hostname' pointers are required.  The `foo_client_running' with
+`foo_ctx' in this example will be called by the client library after the
+client is up and running.  After you receive this callback you may start
+using other API functions, such as creating connection to remote server.
 
 
 <br />&nbsp;<br />&nbsp;<br />
@@ -195,15 +147,12 @@ second as possible to provide smooth action for the client library.  You
 can use an timeout task, or an idle task provided by your GUI library to
 accomplish this.  After you have initialized the client library with
 silc_client_init, you should register the timeout task or idle task that
-will call the silc_client_run_one periodically.  In the Toolkit package
-there is GTK-- GUI example in silcer/ directory.  That example calls the
-silc_client_run_one every 50 milliseconds, and it should be sufficient for
-smooth working.
+will call the silc_client_run_one periodically.
 
 <br />&nbsp;<br />
 For Win32 the silc_client_run can be used instead of using the Windows's
 own event loop.  However, if you would like to use the silc_client_run_one
-also on Win32 systems it is possible.
+also on Win32 system it is possible.
 
 
 <br />&nbsp;<br />&nbsp;<br />
@@ -247,60 +196,22 @@ Client library work on the background of the GUI application.
 <b>Creating Connection to Server</b>
 
 <br />&nbsp;<br />
-Connection to remote SILC server is done by calling:
+After your client is up and running you may create connection to remote
+SILC server.  It is done simply by calling:
 
 <br />&nbsp;<br />
-<tt>&nbsp;&nbsp;silc_client_connect_to_server(client, port, hostname, context);</tt>
+<tt>&nbsp;&nbsp;silc_client_connect_to_server(client, &params,
+                                              public_key, private_key,
+                                             remote_host, remote_port,
+                                             foo_connected_cb, foo_ctx);</tt>
 
 <br />&nbsp;<br />
 The function will create the connection asynchronously to the server, ie.
-the function will return before the actual connection is created.  After
-the connection is created the client->ops->connect operation is called.
-
-<br />&nbsp;<br />
-Generally speaking the connections are associated with windows' on the
-screen.  IRC is usually implemented this way, however it is not the
-necessary way to associate the client's connections.  SilcClientConnection
-object is provided by the library (and is always passed to the application)
-that can be used in the application to associate the connection from the
-library.  Application specific context can be saved to the
-SilcClientConnection object which then can be retrieved in the application,
-thus perhaps associate the connection with what ever object in
-application (window or something else).
-
-
-<br />&nbsp;<br />&nbsp;<br />
-<b>Using Own Connecting</b>
-
-<br />&nbsp;<br />
-Application might not want to use silc_client_connect_to_server function
-if it wants to perform its own connecting for some reason.  In this case
-application must call function silc_client_start_key_exchange after it
-has created the connection by itself.  This function starts the key
-exhange protocol between the client and server and the library takes care
-of everything after that.
-
-<br />&nbsp;<br />
-After connection has been created application must call:
-
-<br />&nbsp;<br />
-<tt>
-&nbsp;&nbsp;SilcClientConnection conn;
-
-<br />&nbsp;<br />
-&nbsp;&nbsp;/* Add new connection to client */<br />
-&nbsp;&nbsp;conn = silc_client_add_connection(client, hostname, port, context);
-
-<br />&nbsp;<br />
-&nbsp;&nbsp;/* Start key exchange and let the library handle everything<br />
-&nbsp;&nbsp;   after this point on. */<br />
-&nbsp;&nbsp;silc_client_start_key_exchange(client, conn, sock);
-</tt>
-
-<br />&nbsp;<br />
-NOTE: These calls are performed only and only if application did not call
-silc_client_connect_to_server function, but performed the connecting
-process manually.
+the function will return before the actual connection is created.  The
+`foo_connected_cb' will be called once the connection has been established.
+The `params' may be NULL but it may be used to provide additional parameters
+to the connecting.  For example it is possible to set the initial nickname
+you would like to use into the `params'.
 
 
 <br />&nbsp;<br />&nbsp;<br />
@@ -315,7 +226,7 @@ debugging is enabled.
 
 <br />&nbsp;<br />
 Then, to say in your application you would like to use the debugging use
-the SILC_ENABLE_DEBUG macro.  Put this macro to your main header file, or
+the SILC_DEBUG macro.  Put this macro to your main header file, or
 some other file that needs the debugging enabled.  After using this macro
 you are able to use the debugging routines provided by the SILC Toolkit.
 Note that, the Toolkit library must be compiled with --enable-debug for
@@ -345,7 +256,7 @@ examples could be:
 
 <br />&nbsp;<br />
 <tt>
-&nbsp;&nbsp;silc_log_set_debug_string("silc_client*,*socket*,*ske*");<br />
+&nbsp;&nbsp;silc_log_set_debug_string("silc_client*,*sock*,*ske*");<br />
 </tt>
 
 <br />&nbsp;<br />
@@ -389,79 +300,3 @@ out otherwise, for example binary data.
 Note that the variable arguments in SILC_LOG_HEXDUMP are before the second
 last parenthesis, and the last two arguments are the data, and its length that
 are hexdumped.
-
-
-<br />&nbsp;<br />&nbsp;<br />
-<b>Example Client</b>
-
-<br />&nbsp;<br />
-This section includes an example SILC client implementation in pseudo-like
-C code.  It creates and initializes the client and sets up an imaginary
-user interface.  The user will use the user interface then to create
-the connections.  The SilcClientOperations are expected to be implemented.
-
-<br />&nbsp;<br />
-<pre>
-#include "silc.h"
-#include "silcclient.h"
-
-int main()
-{
-       SilcClientOperations ops = {
-         silc_say,
-         silc_channel_message,
-         silc_private_message,
-         silc_notify,
-         silc_command,
-         silc_command_reply,
-         silc_connect,
-         silc_disconnect,
-         silc_get_auth_method,
-         silc_verify_public_key,
-         silc_ask_passphrase,
-         silc_failure,
-         silc_key_agreement,
-         silc_ftp,
-         silc_detach
-       };
-
-       SilcClient client;
-
-       /* Allocate SILC client. The `silc_version_string' is defined
-          in includes/version.h file. */
-       client = silc_client_alloc(&ops, NULL, NULL, silc_version_string);
-
-       /* Set the mandatory pointers, read public and private key from
-          files (or somewhere) and return pointers and PKCS context. */
-       client->username = silc_get_username();
-       client->hostname = silc_net_localhost();
-       client->realname = silc_get_real_name();
-       client->pkcs = get_public_and_private_key(&client->public_key,
-                                                 &client->private_key);
-
-       /* If the keys does not exist, create a key pair since we must
-          provide key pair to the library. */
-       if (!client->pkcs)
-         generate_key_new_key_pair(client);
-
-       /* Iinitialize client */
-       if (!silc_client_init(client))
-         fatal_error("Could not initialize client");
-
-       /* Initialize user interface. The user interface can be generally
-          initialized at any phase, including before actually allocating
-          and initializing the client, if wished. */
-       InitUserInterface();
-       DoCoolThings();
-
-       /* Start the client. This will start the scheduler. At this phase
-          the user might have the user interface in front of him already.
-          He will use the user interface to create the connection to the
-          server for example. When this function returns the program is
-         ended. */
-       silc_client_run(client);
-
-       /* Client is ended */
-       return 0;
-}
-</pre>
index b425a7916a7b5f7bf4d0e130ee61e0e914a8f71c..f7c8535802ddddc913c5e64d2466cf95ea619094 100644 (file)
@@ -43,7 +43,7 @@
 
 <table border="0" cellspacing="0" cellpadding="6" width="100%">
  <tr valign="top" bgcolor="#dddddd">
-  <td><small>Copyright &copy; 2001 - 2005 SILC Project<br />
+  <td><small>Copyright &copy; 2001 - 2007 SILC Project<br />
     <a href="http://silcnet.org">SILC Project Website</a></small></td>
   <td align="right"><small>
    <a href="index.html">SILC Toolkit Reference Manual</a><br />
@@ -121,7 +121,7 @@ if ($type == 0) {
 </table>
 <table border="0" cellspacing="0" cellpadding="6" width="100%">
  <tr valign="top" bgcolor="#dddddd">
-  <td><small>Copyright &copy; 2001 - 2005 SILC Project<br />
+  <td><small>Copyright &copy; 2001 - 2007 SILC Project<br />
     <a href="http://silcnet.org">SILC Project Website</a></small></td>
   <td align="right"><small>
    <a href="index.html">SILC Toolkit Reference Manual</a><br />
index 4cda00a69c9527323cf161d6d7ac573942bfd3a6..445e1af794c8da0ff6cf3b4a8499d9d4a598384f 100644 (file)
@@ -17,7 +17,7 @@
 
 AUTOMAKE_OPTIONS = 1.0 no-dependencies foreign
 
-CFLAGS = $(INCLUDES) $(SILC_COMMON_LIBS) $(LDFLAGS)
+CFLAGS = $(INCLUDES) $(SILC_COMMON_LDFLAGS) $(SILC_COMMON_LIBS) $(LDFLAGS)
 SOURCES = mybot.c
 
 all: mybot
index 6e689d061cb106239301ed1a5f60d76a15abfcef..02b52a2ae9dcb37c348a809a64966d4ffddaf9a2 100644 (file)
@@ -1,8 +1,8 @@
 /*
 
-  mybot.c 
+  mybot.c
 
-  Author: Pekka Riikonen <priikone@silcnet.org>, November 2002
+  Author: Pekka Riikonen <priikone@silcnet.org>, November 2002, 2007
   This code is Public Domain.
 
   MyBot
   gcc -o mybot mybot.c -I/usr/local/silc/include -L/usr/local/silc/lib \
       -lsilc -lsilcclient -lpthread -ldl
 
-  The MyBot works as follows (logicly):
-
-  main -> mybot_start -> silc_client_connect_to_server
-                v
-          silc_client_run (message loop...)
-                v
-          silc_verify_public_key
-                v
-          silc_get_auth_method
-                v
-          silc_connected -> silc_client_command_call (JOIN)
-                v
-          silc_command_reply -> silc_send_channel_message ("hello")
-                v
-          message loop...
-                v
-  main <- mybot_start
-
 */
 
 #include "silc.h"              /* Mandatory include for SILC applications */
 
 SilcClientOperations ops;
 
+static void silc_running(SilcClient client, void *application);
+static void silc_stopped(SilcClient client, void *context);
+
 /******* MyBot code **********************************************************/
 
 /* This is context for our MyBot client */
 typedef struct {
   SilcClient client;           /* The actual SILC Client */
   SilcClientConnection conn;   /* Connection to the server */
+  SilcPublicKey public_key;     /* My public key */
+  SilcPrivateKey private_key;   /* My private key */
 } *MyBot;
 
+/* Connect callback called after connected to remote server. */
+
+static void
+silc_connected(SilcClient client, SilcClientConnection conn,
+              SilcClientConnectionStatus status,
+              SilcStatus error, const char *message,
+              void *context)
+{
+  MyBot mybot = client->application;
+
+  if (status == SILC_CLIENT_CONN_DISCONNECTED) {
+    SILC_LOG_DEBUG(("Disconnected %s", message ? message : ""));
+    silc_client_stop(client, silc_stopped, mybot);
+    return;
+  }
+
+  if (status != SILC_CLIENT_CONN_SUCCESS &&
+      status != SILC_CLIENT_CONN_SUCCESS_RESUME) {
+    SILC_LOG_DEBUG(("Error connecting to server %d", status));
+    silc_client_stop(client, silc_stopped, mybot);
+    return;
+  }
+
+  fprintf(stdout, "\nMyBot: Connected to server\n\n");
+
+  /* Now that we have connected to server, let's join a channel named
+     "mybot". */
+  silc_client_command_call(client, conn, "JOIN mybot");
+
+  /* Save the connection context */
+  mybot->conn = conn;
+}
+
+/* Running callback given to silc_client_init called to indicate that the
+   Client Library is running.  After this Client API functions can be
+   called. */
+
+static void silc_running(SilcClient client, void *application)
+{
+  MyBot mybot = application;
+
+  SILC_LOG_DEBUG(("Client is running"));
+
+  /* Connect to server.  The silc_connected callback will be called after
+     the connection is established or if an error occurs during connecting. */
+  silc_client_connect_to_server(mybot->client, NULL,
+                               mybot->public_key, mybot->private_key,
+                               "silc.silcnet.org", 706,
+                               silc_connected, mybot);
+}
+
+/* Client stopped callback given to silc_client_stop.  Called to indicate
+   that Client Library is stopped. */
+
+static void silc_stopped(SilcClient client, void *context)
+{
+  SILC_LOG_DEBUG(("Client stopped"));
+}
+
 /* Start the MyBot, by creating the SILC Client entity by using the
    SILC Client Library API. */
 int mybot_start(void)
 {
   MyBot mybot;
+  SilcClientParams params;
 
   /* Allocate the MyBot structure */
   mybot = silc_calloc(1, sizeof(*mybot));
@@ -65,60 +112,36 @@ int mybot_start(void)
     return 1;
   }
 
-  /* Allocate our SILC Client which is the MyBot.  The arguments to the
-     function are:
-
-     ops           - our client operations that the library requires
-     param         - parameters, but we don't have any so we pass NULL,
-     application   - our application, ie. the MyBot of course!
-     version       - silc version, provided by the library if we put NULL
-  */
-  mybot->client = silc_client_alloc(&ops, NULL, mybot, NULL);
+  memset(&params, 0, sizeof(params));
+  params.threads = TRUE;
+  mybot->client = silc_client_alloc(&ops, &params, mybot, NULL);
   if (!mybot->client) {
     perror("Could not allocate SILC Client");
     return 1;
   }
 
-  /* Now fill the allocated client with mandatory parameters the library
-     requires: username, hostname and "real name". */
-  mybot->client->username = silc_get_username();
-  mybot->client->hostname = silc_net_localhost();
-  mybot->client->realname = strdup("I am the MyBot");
-
   /* Now we initialize the client. */
-  if (!silc_client_init(mybot->client)) {
+  if (!silc_client_init(mybot->client, silc_get_username(),
+                       silc_net_localhost(), "I am the MyBot",
+                       silc_running, mybot)) {
     perror("Could not init client");
     return 1;
   }
 
-  /* Then we load our public key from the file.  The library requires
-     the key pair loaded before the client is started.  The SILC Toolkit
-     provides nice routines to do just that so we don't have to worry
-     about much.
-
-     Oh, and if the key pair doesn't exist, we create one here
-     automatically, and save them to files for future. */
   if (!silc_load_key_pair("mybot.pub", "mybot.prv", "",
-                         &mybot->client->pkcs,
-                         &mybot->client->public_key,
-                         &mybot->client->private_key)) {
+                         &mybot->public_key,
+                         &mybot->private_key)) {
     /* The keys don't exist.  Let's generate us a key pair then!  There's
        nice ready routine for that too.  Let's do 2048 bit RSA key pair. */
     fprintf(stdout, "MyBot: Key pair does not exist, generating it.\n");
     if (!silc_create_key_pair("rsa", 2048, "mybot.pub", "mybot.prv", NULL, "",
-                             &mybot->client->pkcs,
-                             &mybot->client->public_key,
-                             &mybot->client->private_key, FALSE)) {
+                             &mybot->public_key,
+                             &mybot->private_key, FALSE)) {
       perror("Could not generated key pair");
       return 1;
     }
   }
 
-  /* Start connecting to server.  This is asynchronous connecting so the
-     connection is actually created later after we run the client. */
-  silc_client_connect_to_server(mybot->client, NULL, 706,
-                               "silc.silcnet.org", mybot);
-
   /* And, then we are ready to go.  Since we are really simple client we
      don't have user interface and we don't have to deal with message loops
      or interactivity.  That's why we can just hand over the execution
@@ -181,7 +204,7 @@ silc_channel_message(SilcClient client, SilcClientConnection conn,
 
 
 /* Private message to the client. The `sender' is the sender of the
-   message. The message is `message'and maybe NULL.  The `flags'  
+   message. The message is `message'and maybe NULL.  The `flags'
    indicates message flags  and it is used to determine how the message
    can be interpreted (like it may tell the message is multimedia
    message). */
@@ -252,8 +275,8 @@ silc_notify(SilcClient client, SilcClientConnection conn,
 
 static void
 silc_command(SilcClient client, SilcClientConnection conn,
-            SilcClientCommandContext cmd_context, bool success,
-            SilcCommand command, SilcStatus status)
+            SilcBool success, SilcCommand command, SilcStatus status,
+            SilcUInt32 argc, unsigned char **argv)
 {
   /* If error occurred in client library with our command, print the error */
   if (status != SILC_STATUS_OK)
@@ -282,92 +305,44 @@ silc_command(SilcClient client, SilcClientConnection conn,
 
 static void
 silc_command_reply(SilcClient client, SilcClientConnection conn,
-                  SilcCommandPayload cmd_payload, bool success,
-                  SilcCommand command, SilcStatus status, ...)
+                  SilcCommand command, SilcStatus status,
+                  SilcStatus error, va_list ap)
 {
-  va_list va;
-
   /* If error occurred in client library with our command, print the error */
   if (status != SILC_STATUS_OK)
     fprintf(stderr, "MyBot: COMMAND REPLY %s: %s\n",
            silc_get_command_name(command),
            silc_get_status_message(status));
 
-  va_start(va, status);
-
-  /* Check for successful JOIN */
+  /* Check for successful JOIN.  See
+     http://silcnet.org/docs/toolkit/command_reply_args.html for the
+     different arguments the client library returns. */
   if (command == SILC_COMMAND_JOIN) {
     SilcChannelEntry channel;
+    SilcHash sha1hash;
 
-    (void)va_arg(va, SilcClientEntry);
-    channel = va_arg(va, SilcChannelEntry);
+    (void)va_arg(ap, SilcClientEntry);
+    channel = va_arg(ap, SilcChannelEntry);
 
     fprintf(stdout, "MyBot: Joined '%s' channel\n", channel->channel_name);
 
     /* Now send the "hello" to the channel */
-    silc_client_send_channel_message(client, conn, channel, NULL, 0,
-                                    "hello", strlen("hello"), FALSE);
+    silc_client_send_channel_message(client, conn, channel, NULL, 0, NULL,
+                                    "hello", strlen("hello"));
     fprintf(stdout, "MyBot: Sent 'hello' to channel\n");
 
-    /* Now send digitally signed "hello" to the channel */
+    /* Now send digitally signed "hello" to the channel.  We have to allocate
+       hash function for the signature process. */
+    silc_hash_alloc("sha1", &sha1hash);
     silc_client_send_channel_message(client, conn, channel, NULL,
-                                    SILC_MESSAGE_FLAG_SIGNED,
-                                    "hello, with signature", 
-                                    strlen("hello, with signature"), FALSE);
+                                    SILC_MESSAGE_FLAG_SIGNED, sha1hash,
+                                    "hello, with signature",
+                                    strlen("hello, with signature"));
+    silc_hash_free(sha1hash);
     fprintf(stdout, "MyBot: Sent 'hello, with signature' to channel\n");
   }
-
-  va_end(va);
 }
 
-
-/* Called to indicate that connection was either successfully established
-   or connecting failed.  This is also the first time application receives
-   the SilcClientConnection objecet which it should save somewhere.
-   If the `success' is FALSE the application must always call the function
-   silc_client_close_connection. */
-
-static void
-silc_connected(SilcClient client, SilcClientConnection conn,
-              SilcClientConnectionStatus status)
-{
-  MyBot mybot = client->application;
-  SilcBuffer idp;
-
-  if (status == SILC_CLIENT_CONN_ERROR) {
-    fprintf(stderr, "MyBot: Could not connect to server\n");
-    silc_client_close_connection(client, conn);
-    return;
-  }
-
-  fprintf(stdout, "MyBot: Connected to server.\n");
-
-  /* Save the connection context */
-  mybot->conn = conn;
-
-  /* Now that we are connected, join to mybot channel with JOIN command. */
-  silc_client_command_call(client, conn, "JOIN mybot");
-}
-
-
-/* Called to indicate that connection was disconnected to the server.
-   The `status' may tell the reason of the disconnection, and if the
-   `message' is non-NULL it may include the disconnection message
-   received from server. */
-
-static void
-silc_disconnected(SilcClient client, SilcClientConnection conn,
-                 SilcStatus status, const char *message)
-{
-  MyBot mybot = client->application;
-
-  /* We got disconnected from server */
-  mybot->conn = NULL;
-  fprintf(stdout, "MyBot: %s:%s\n", silc_get_status_message(status),
-         message);
-}
-
-
 /* Find authentication method and authentication data by hostname and
    port. The hostname may be IP address as well. When the authentication
    method has been resolved the `completion' callback with the found
@@ -377,13 +352,14 @@ silc_disconnected(SilcClient client, SilcClientConnection conn,
 static void
 silc_get_auth_method(SilcClient client, SilcClientConnection conn,
                     char *hostname, SilcUInt16 port,
+                    SilcAuthMethod auth_method,
                     SilcGetAuthMeth completion,
                     void *context)
 {
   /* MyBot assumes that there is no authentication requirement in the
      server and sends nothing as authentication.  We just reply with
      TRUE, meaning we know what is the authentication method. :). */
-  completion(TRUE, SILC_AUTH_NONE, NULL, 0, context);
+  completion(SILC_AUTH_NONE, NULL, 0, context);
 }
 
 
@@ -395,14 +371,12 @@ silc_get_auth_method(SilcClient client, SilcClientConnection conn,
 
 static void
 silc_verify_public_key(SilcClient client, SilcClientConnection conn,
-                      SilcSocketType conn_type, unsigned char *pk,
-                      SilcUInt32 pk_len, SilcSKEPKType pk_type,
+                      SilcConnectionType conn_type,
+                      SilcPublicKey public_key,
                       SilcVerifyPublicKey completion, void *context)
 {
-  /* MyBot is also very trusting, so we just accept the public key
-     we get here.  Of course, we would have to verify the authenticity
-     of the public key but our bot is too simple for that.  We just
-     reply with TRUE, meaning "yeah, we trust it". :) */
+  fprintf(stdout, "MyBot: server's public key\n");
+  silc_show_public_key(public_key);
   completion(TRUE, context);
 }
 
@@ -422,26 +396,6 @@ silc_ask_passphrase(SilcClient client, SilcClientConnection conn,
 }
 
 
-/* Notifies application that failure packet was received.  This is called
-   if there is some protocol active in the client.  The `protocol' is the
-   protocol context.  The `failure' is opaque pointer to the failure
-   indication.  Note, that the `failure' is protocol dependant and
-   application must explicitly cast it to correct type.  Usually `failure'
-   is 32 bit failure type (see protocol specs for all protocol failure
-   types). */
-
-static void
-silc_failure(SilcClient client, SilcClientConnection conn,
-            SilcProtocol protocol, void *failure)
-{
-  /* Well, something bad must have happened during connecting to the
-     server since we got here.  Let's just print that something failed.
-     The "failure" would include more information but let's not bother
-     with that now. */
-  fprintf(stderr, "MyBot: Connecting failed (protocol failure)\n");
-}
-
-
 /* Asks whether the user would like to perform the key agreement protocol.
    This is called after we have received an key agreement packet or an
    reply to our key agreement packet. This returns TRUE if the user wants
@@ -450,15 +404,13 @@ silc_failure(SilcClient client, SilcClientConnection conn,
    silc_client_perform_key_agreement). If TRUE is returned also the
    `completion' and `context' arguments must be set by the application. */
 
-static bool
+static void
 silc_key_agreement(SilcClient client, SilcClientConnection conn,
                   SilcClientEntry client_entry, const char *hostname,
-                  SilcUInt16 port, SilcKeyAgreementCallback *completion,
-                  void **context)
+                  SilcUInt16 protocol, SilcUInt16 port)
 {
   /* MyBot does not support incoming key agreement protocols, it's too
      simple for that. */
-  return FALSE;
 }
 
 
@@ -478,30 +430,6 @@ silc_ftp(SilcClient client, SilcClientConnection conn,
 }
 
 
-/* Delivers SILC session detachment data indicated by `detach_data' to the
-   application.  If application has issued SILC_COMMAND_DETACH command
-   the client session in the SILC network is not quit.  The client remains
-   in the network but is detached.  The detachment data may be used later
-   to resume the session in the SILC Network.  The appliation is
-   responsible of saving the `detach_data', to for example in a file.
-
-   The detachment data can be given as argument to the functions
-   silc_client_connect_to_server, or silc_client_add_connection when
-   creating connection to remote server, inside SilcClientConnectionParams
-   structure.  If it is provided the client library will attempt to resume
-   the session in the network.  After the connection is created
-   successfully, the application is responsible of setting the user
-   interface for user into the same state it was before detaching (showing
-   same channels, channel modes, etc).  It can do this by fetching the
-   information (like joined channels) from the client library. */
-
-static void
-silc_detach(SilcClient client, SilcClientConnection conn,
-           const unsigned char *detach_data, SilcUInt32 detach_data_len)
-{
-  /* Oh, and MyBot does not support session detaching either. */
-}
-
 /* Our client operations for the MyBot.  This structure is filled with
    functions and given as argument to the silc_client_alloc function.
    Even though our little bot does not need all these functions we must
@@ -515,19 +443,15 @@ SilcClientOperations ops = {
   silc_notify,
   silc_command,
   silc_command_reply,
-  silc_connected,
-  silc_disconnected,
   silc_get_auth_method,
   silc_verify_public_key,
   silc_ask_passphrase,
-  silc_failure,
   silc_key_agreement,
-  silc_ftp,
-  silc_detach
+  silc_ftp
 };
 
 int main(int argc, char **argv)
 {
-  /* Start the bot */
+  /* Start mybot */
   return mybot_start();
 }