Merged from silc_1_0_branch.
[silc.git] / tutorial / mybot / mybot.c
index aea502c5ad51ea0e7e8f5c6ecb2c2477f9223075..10163ef81abd84d4a19da91f0f8114f8041789fe 100644 (file)
@@ -29,7 +29,7 @@
                 v
           silc_get_auth_method
                 v
-          silc_connected -> silc_client_send_command (JOIN)
+          silc_connected -> silc_client_command_call (JOIN)
                 v
           silc_command_reply -> silc_send_channel_message ("hello")
                 v
@@ -73,8 +73,7 @@ int mybot_start(void)
      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 */"SILC-1.1-0.9.4");
+  mybot->client = silc_client_alloc(&ops, NULL, mybot, NULL);
   if (!mybot->client) {
     perror("Could not allocate SILC Client");
     return 1;
@@ -99,15 +98,15 @@ int mybot_start(void)
 
      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", NULL,
+  if (!silc_load_key_pair("mybot.pub", "mybot.prv", "",
                          &mybot->client->pkcs,
                          &mybot->client->public_key,
                          &mybot->client->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,
-                             NULL, &mybot->client->pkcs,
+    if (!silc_create_key_pair("rsa", 2048, "mybot.pub", "mybot.prv", NULL, "",
+                             &mybot->client->pkcs,
                              &mybot->client->public_key,
                              &mybot->client->private_key, FALSE)) {
       perror("Could not generated key pair");
@@ -167,11 +166,16 @@ silc_say(SilcClient client, SilcClientConnection conn,
 static void
 silc_channel_message(SilcClient client, SilcClientConnection conn,
                     SilcClientEntry sender, SilcChannelEntry channel,
+                    SilcMessagePayload payload,
                     SilcMessageFlags flags, const unsigned char *message,
                     SilcUInt32 message_len)
 {
   /* Yay! We got a message from channel. */
-  fprintf(stdout, "<%s> %s\n", sender->nickname, message);
+
+  if (flags & SILC_MESSAGE_FLAG_SIGNED)
+    fprintf(stdout, "[SIGNED] <%s> %s\n", sender->nickname, message);
+  else
+    fprintf(stdout, "<%s> %s\n", sender->nickname, message);
 }
 
 
@@ -183,7 +187,8 @@ silc_channel_message(SilcClient client, SilcClientConnection conn,
 
 static void
 silc_private_message(SilcClient client, SilcClientConnection conn,
-                    SilcClientEntry sender, SilcMessageFlags flags,
+                    SilcClientEntry sender, SilcMessagePayload payload,
+                    SilcMessageFlags flags,
                     const unsigned char *message,
                     SilcUInt32 message_len)
 {
@@ -302,6 +307,13 @@ silc_command_reply(SilcClient client, SilcClientConnection conn,
     silc_client_send_channel_message(client, conn, channel, NULL, 0,
                                     "hello", strlen("hello"), FALSE);
     fprintf(stdout, "MyBot: Sent 'hello' to channel\n");
+
+    /* Now send digitally signed "hello" to the channel */
+    silc_client_send_channel_message(client, conn, channel, NULL,
+                                    SILC_MESSAGE_FLAG_SIGNED,
+                                    "hello, with signature", 
+                                    strlen("hello, with signature"), FALSE);
+    fprintf(stdout, "MyBot: Sent 'hello, with signature' to channel\n");
   }
 
   va_end(va);
@@ -332,13 +344,8 @@ silc_connected(SilcClient client, SilcClientConnection conn,
   /* Save the connection context */
   mybot->conn = conn;
 
-  /* Now that we are connected, send the JOIN command to the "mybot"
-     channel */
-  idp = silc_id_payload_encode(conn->local_id, SILC_ID_CLIENT);
-  silc_client_command_send(client, conn, SILC_COMMAND_JOIN, 0, 2,
-                          1, "mybot", strlen("mybot"),
-                          2, idp->data, idp->len);
-  silc_buffer_free(idp);
+  /* Now that we are connected, join to mybot channel with JOIN command. */
+  silc_client_command_call(client, conn, "JOIN mybot");
 }