Added settings sign_channel_messages, sign_private_messages and
[silc.git] / apps / irssi / src / silc / core / client_ops.c
index 77b362f6d44a7b1c3a86a8129f5ebdb2c49b6cf7..776fe69de16fdda84651a55dd5a0193434eef058 100644 (file)
@@ -256,7 +256,7 @@ int verify_message_signature(SilcClientEntry sender,
   if (pk != NULL) {
     fingerprint = silc_hash_fingerprint(NULL, pk_data, pk_datalen);
 
-    if (sender->fingerprint) {
+    if (sender->fingerprint[0]) {
       fingerprint2 = silc_fingerprint(sender->fingerprint,
                                      sizeof(sender->fingerprint));
       if (strcmp(fingerprint, fingerprint2)) {
@@ -268,7 +268,7 @@ int verify_message_signature(SilcClientEntry sender,
       }
       silc_free(fingerprint2);
     }
-  } else if (sender->fingerprint)
+  } else if (sender->fingerprint[0])
     fingerprint = silc_fingerprint(sender->fingerprint,
                                   sizeof(sender->fingerprint));
   else
@@ -310,7 +310,7 @@ int verify_message_signature(SilcClientEntry sender,
 
   /* the public key is now in pk, our "level of trust" in ret */
   if ((pk) && silc_message_signed_verify(message, pk,
-                                        sha1hash)!= SILC_AUTH_OK)
+                                        sha1hash) != SILC_AUTH_OK)
     ret = SILC_MSG_SIGNED_FAILED;
 
   if (pk)
@@ -1151,35 +1151,34 @@ void silc_notify(SilcClient client, SilcClientConnection conn,
        * Server has quit the network.
        */
       int i;
-      SilcClientEntry *clients;
-      SilcUInt32 clients_count;
+      SilcDList clients;
 
-      SILC_LOG_DEBUG(("Notify: SIGNOFF"));
+      SILC_LOG_DEBUG(("Notify: SERVER_SIGNOFF"));
 
       (void)va_arg(va, void *);
-      clients = va_arg(va, SilcClientEntry *);
-      clients_count = va_arg(va, SilcUInt32);
+      clients = va_arg(va, SilcDList);
 
-      for (i = 0; i < clients_count; i++) {
+      silc_dlist_start(clients);
+      while ((client_entry = silc_dlist_get(clients))) {
        memset(buf, 0, sizeof(buf));
 
        /* Print only if we have the nickname.  If this client has just quit
           when we were only resolving it, it is possible we don't have the
           nickname. */
-       if (clients[i]->nickname) {
-         if (clients[i]->username)
+       if (client_entry->nickname[0]) {
+         if (client_entry->username[0])
            snprintf(buf, sizeof(buf) - 1, "%s@%s",
-                    clients[i]->username, clients[i]->hostname);
-         signal_emit("message quit", 4, server, clients[i]->nickname,
-                     clients[i]->username ? buf : "",
+                    client_entry->username, client_entry->hostname);
+         signal_emit("message quit", 4, server, client_entry->nickname,
+                     client_entry->username[0] ? buf : "",
                      "server signoff");
        }
 
 #if 0
-       silc_server_free_ftp(server, clients[i]);
+       silc_server_free_ftp(server, client_entry);
 #endif
 
-       list1 = nicklist_get_same_unique(SERVER(server), clients[i]);
+       list1 = nicklist_get_same_unique(SERVER(server), client_entry);
        for (list_tmp = list1; list_tmp != NULL; list_tmp =
               list_tmp->next->next) {
          CHANNEL_REC *channel = list_tmp->data;
@@ -1510,7 +1509,7 @@ void silc_command_reply(SilcClient client, SilcClientConnection conn,
          silc_client_unref_client(client, conn, client_entry);
        }
        break;
-      } else if (status != SILC_STATUS_OK) {
+      } else if (SILC_STATUS_IS_ERROR(status)) {
        silc_say_error("WHOIS: %s", silc_get_status_message(status));
        return;
       }
@@ -1595,7 +1594,7 @@ void silc_command_reply(SilcClient client, SilcClientConnection conn,
          silc_say_error("%s: %s", tmp,
                         silc_get_status_message(status));
        break;
-      } else if (status != SILC_STATUS_OK) {
+      } else if (SILC_STATUS_IS_ERROR(status)) {
        silc_say_error("WHOWAS: %s", silc_get_status_message(status));
        return;
       }
@@ -1616,7 +1615,7 @@ void silc_command_reply(SilcClient client, SilcClientConnection conn,
       SilcChannelEntry channel;
       SilcArgumentPayload invite_list;
 
-      if (status != SILC_STATUS_OK)
+      if (SILC_STATUS_IS_ERROR(status))
        return;
 
       channel = va_arg(vp, SilcChannelEntry);
@@ -1638,8 +1637,10 @@ void silc_command_reply(SilcClient client, SilcClientConnection conn,
       SilcClientEntry founder = NULL;
       NICK_REC *ownnick;
 
-      if (status != SILC_STATUS_OK)
+      if (SILC_STATUS_IS_ERROR(status)) {
+       silc_say_error("JOIN: %s", silc_get_status_message(status));
        return;
+      }
 
       channel = va_arg(vp, char *);
       channel_entry = va_arg(vp, SilcChannelEntry);
@@ -1691,6 +1692,8 @@ void silc_command_reply(SilcClient client, SilcClientConnection conn,
       }
 
       ownnick = NICK(silc_nicklist_find(chanrec, conn->local_entry));
+      if (!ownnick)
+       break;
       nicklist_set_own(CHANNEL(chanrec), ownnick);
       signal_emit("channel joined", 1, chanrec);
       chanrec->entry = channel_entry;
@@ -1724,8 +1727,10 @@ void silc_command_reply(SilcClient client, SilcClientConnection conn,
       SilcClientEntry client_entry = va_arg(vp, SilcClientEntry);
       GSList *nicks;
 
-      if (status != SILC_STATUS_OK)
+      if (SILC_STATUS_IS_ERROR(status)) {
+       silc_say_error("NICK: %s", silc_get_status_message(status));
        return;
+      }
 
       nicks = nicklist_get_same(SERVER(server), client_entry->nickname);
       if ((nicks != NULL) &&
@@ -1773,13 +1778,11 @@ void silc_command_reply(SilcClient client, SilcClientConnection conn,
       char users[20];
       char tmp[256], *cp, *dm = NULL;
 
-      if (status != SILC_STATUS_OK)
+      if (SILC_STATUS_IS_ERROR(status))
        return;
 
       (void)va_arg(vp, SilcChannelEntry);
       name = va_arg(vp, char *);
-      if (!name)
-       return;
       topic = va_arg(vp, char *);
       usercount = va_arg(vp, int);
 
@@ -1818,7 +1821,7 @@ void silc_command_reply(SilcClient client, SilcClientConnection conn,
       SilcUInt32 mode;
       char *reason;
 
-      if (status != SILC_STATUS_OK)
+      if (SILC_STATUS_IS_ERROR(status))
        return;
 
       mode = va_arg(vp, SilcUInt32);
@@ -1853,7 +1856,7 @@ void silc_command_reply(SilcClient client, SilcClientConnection conn,
     break;
 
   case SILC_COMMAND_OPER:
-    if (status != SILC_STATUS_OK)
+    if (SILC_STATUS_IS_ERROR(status))
       return;
 
     server->umode |= SILC_UMODE_SERVER_OPERATOR;
@@ -1864,7 +1867,7 @@ void silc_command_reply(SilcClient client, SilcClientConnection conn,
     break;
 
   case SILC_COMMAND_SILCOPER:
-    if (status != SILC_STATUS_OK)
+    if (SILC_STATUS_IS_ERROR(status))
       return;
 
     server->umode |= SILC_UMODE_ROUTER_OPERATOR;
@@ -1880,8 +1883,10 @@ void silc_command_reply(SilcClient client, SilcClientConnection conn,
       SilcChannelEntry channel;
       SilcChannelUser chu;
 
-      if (status != SILC_STATUS_OK)
+      if (SILC_STATUS_IS_ERROR(status)) {
+       silc_say_error("USERS: %s", silc_get_status_message(status));
        return;
+      }
 
       channel = va_arg(vp, SilcChannelEntry);
 
@@ -1936,7 +1941,7 @@ void silc_command_reply(SilcClient client, SilcClientConnection conn,
       SilcChannelEntry channel;
       SilcArgumentPayload invite_list;
 
-      if (status != SILC_STATUS_OK)
+      if (SILC_STATUS_IS_ERROR(status))
        return;
 
       channel = va_arg(vp, SilcChannelEntry);
@@ -1956,8 +1961,10 @@ void silc_command_reply(SilcClient client, SilcClientConnection conn,
       GetkeyContext getkey;
       char *name;
 
-      if (status != SILC_STATUS_OK)
+      if (SILC_STATUS_IS_ERROR(status)) {
+       silc_say_error("GETKEY: %s", silc_get_status_message(status));
        return;
+      }
 
       id_type = va_arg(vp, SilcUInt32);
       entry = va_arg(vp, void *);
@@ -1992,7 +1999,7 @@ void silc_command_reply(SilcClient client, SilcClientConnection conn,
       char *server_name;
       char *server_info;
 
-      if (status != SILC_STATUS_OK)
+      if (SILC_STATUS_IS_ERROR(status))
        return;
 
       server_entry = va_arg(vp, SilcServerEntry);
@@ -2013,7 +2020,7 @@ void silc_command_reply(SilcClient client, SilcClientConnection conn,
       char *topic;
       char tmp[256], *cp, *dm = NULL;
 
-      if (status != SILC_STATUS_OK)
+      if (SILC_STATUS_IS_ERROR(status))
        return;
 
       channel = va_arg(vp, SilcChannelEntry);
@@ -2057,9 +2064,7 @@ void silc_command_reply(SilcClient client, SilcClientConnection conn,
 
   case SILC_COMMAND_STATS:
     {
-      SilcUInt32 starttime, uptime, my_clients, my_channels, my_server_ops,
-                my_router_ops, cell_clients, cell_channels, cell_servers,
-                clients, channels, servers, routers, server_ops, router_ops;
+      SilcClientStats *cstats;
       SilcUInt32 buf_len;
       SilcBufferStruct buf;
       unsigned char *tmp_buf;
@@ -2067,116 +2072,94 @@ void silc_command_reply(SilcClient client, SilcClientConnection conn,
       const char *tmptime;
       int days, hours, mins, secs;
 
-      if (status != SILC_STATUS_OK)
+      if (SILC_STATUS_IS_ERROR(status))
        return;
 
-      tmp_buf = va_arg(vp, unsigned char *);
-      buf_len = va_arg(vp, SilcUInt32);
-
-      if (!tmp_buf || !buf_len) {
+      cstats = va_arg(vp, SilcClientStats *);
+      if (!cstats) {
        printtext(server, NULL, MSGLEVEL_CRAP, "No statistics available");
        return;
       }
 
-      /* Get statistics structure */
-      silc_buffer_set(&buf, tmp_buf, buf_len);
-      silc_buffer_unformat(&buf,
-                          SILC_STR_UI_INT(&starttime),
-                          SILC_STR_UI_INT(&uptime),
-                          SILC_STR_UI_INT(&my_clients),
-                          SILC_STR_UI_INT(&my_channels),
-                          SILC_STR_UI_INT(&my_server_ops),
-                          SILC_STR_UI_INT(&my_router_ops),
-                          SILC_STR_UI_INT(&cell_clients),
-                          SILC_STR_UI_INT(&cell_channels),
-                          SILC_STR_UI_INT(&cell_servers),
-                          SILC_STR_UI_INT(&clients),
-                          SILC_STR_UI_INT(&channels),
-                          SILC_STR_UI_INT(&servers),
-                          SILC_STR_UI_INT(&routers),
-                          SILC_STR_UI_INT(&server_ops),
-                          SILC_STR_UI_INT(&router_ops),
-                          SILC_STR_END);
-
-      tmptime = silc_time_string(starttime);
+      tmptime = silc_time_string(cstats->starttime);
       printformat_module("fe-common/silc", server, NULL,
                         MSGLEVEL_CRAP, SILCTXT_STATS,
                         "Local server start time", tmptime);
 
-      days = uptime / (24 * 60 * 60);
-      uptime -= days * (24 * 60 * 60);
-      hours = uptime / (60 * 60);
-      uptime -= hours * (60 * 60);
-      mins = uptime / 60;
-      uptime -= mins * 60;
-      secs = uptime;
+      days = cstats->uptime / (24 * 60 * 60);
+      cstats->uptime -= days * (24 * 60 * 60);
+      hours = cstats->uptime / (60 * 60);
+      cstats->uptime -= hours * (60 * 60);
+      mins = cstats->uptime / 60;
+      cstats->uptime -= mins * 60;
+      secs = cstats->uptime;
       snprintf(tmp, sizeof(tmp) - 1, "%d days %d hours %d mins %d secs",
               days, hours, mins, secs);
       printformat_module("fe-common/silc", server, NULL,
                         MSGLEVEL_CRAP, SILCTXT_STATS,
                         "Local server uptime", tmp);
 
-      snprintf(tmp, sizeof(tmp) - 1, "%d", (int)my_clients);
+      snprintf(tmp, sizeof(tmp) - 1, "%d", (int)cstats->my_clients);
       printformat_module("fe-common/silc", server, NULL,
                         MSGLEVEL_CRAP, SILCTXT_STATS,
                         "Local server clients", tmp);
 
-      snprintf(tmp, sizeof(tmp) - 1, "%d", (int)my_channels);
+      snprintf(tmp, sizeof(tmp) - 1, "%d", (int)cstats->my_channels);
       printformat_module("fe-common/silc", server, NULL,
                         MSGLEVEL_CRAP, SILCTXT_STATS,
                         "Local server channels", tmp);
 
-      snprintf(tmp, sizeof(tmp) - 1, "%d", (int)my_server_ops);
+      snprintf(tmp, sizeof(tmp) - 1, "%d", (int)cstats->my_server_ops);
       printformat_module("fe-common/silc", server, NULL,
                         MSGLEVEL_CRAP, SILCTXT_STATS,
                         "Local server operators", tmp);
 
-      snprintf(tmp, sizeof(tmp) - 1, "%d", (int)my_router_ops);
+      snprintf(tmp, sizeof(tmp) - 1, "%d", (int)cstats->my_router_ops);
       printformat_module("fe-common/silc", server, NULL,
                         MSGLEVEL_CRAP, SILCTXT_STATS,
                         "Local router operators", tmp);
 
-      snprintf(tmp, sizeof(tmp) - 1, "%d", (int)cell_clients);
+      snprintf(tmp, sizeof(tmp) - 1, "%d", (int)cstats->cell_clients);
       printformat_module("fe-common/silc", server, NULL,
                         MSGLEVEL_CRAP, SILCTXT_STATS,
                         "Local cell clients", tmp);
 
-      snprintf(tmp, sizeof(tmp) - 1, "%d", (int)cell_channels);
+      snprintf(tmp, sizeof(tmp) - 1, "%d", (int)cstats->cell_channels);
       printformat_module("fe-common/silc", server, NULL,
                         MSGLEVEL_CRAP, SILCTXT_STATS,
                         "Local cell channels", tmp);
 
-      snprintf(tmp, sizeof(tmp) - 1, "%d", (int)cell_servers);
+      snprintf(tmp, sizeof(tmp) - 1, "%d", (int)cstats->cell_servers);
       printformat_module("fe-common/silc", server, NULL,
                         MSGLEVEL_CRAP, SILCTXT_STATS,
                         "Local cell servers", tmp);
 
-      snprintf(tmp, sizeof(tmp) - 1, "%d", (int)clients);
+      snprintf(tmp, sizeof(tmp) - 1, "%d", (int)cstats->clients);
       printformat_module("fe-common/silc", server, NULL,
                         MSGLEVEL_CRAP, SILCTXT_STATS,
                         "Total clients", tmp);
 
-      snprintf(tmp, sizeof(tmp) - 1, "%d", (int)channels);
+      snprintf(tmp, sizeof(tmp) - 1, "%d", (int)cstats->channels);
       printformat_module("fe-common/silc", server, NULL,
                         MSGLEVEL_CRAP, SILCTXT_STATS,
                         "Total channels", tmp);
 
-      snprintf(tmp, sizeof(tmp) - 1, "%d", (int)servers);
+      snprintf(tmp, sizeof(tmp) - 1, "%d", (int)cstats->servers);
       printformat_module("fe-common/silc", server, NULL,
                         MSGLEVEL_CRAP, SILCTXT_STATS,
                         "Total servers", tmp);
 
-      snprintf(tmp, sizeof(tmp) - 1, "%d", (int)routers);
+      snprintf(tmp, sizeof(tmp) - 1, "%d", (int)cstats->routers);
       printformat_module("fe-common/silc", server, NULL,
                         MSGLEVEL_CRAP, SILCTXT_STATS,
                         "Total routers", tmp);
 
-      snprintf(tmp, sizeof(tmp) - 1, "%d", (int)server_ops);
+      snprintf(tmp, sizeof(tmp) - 1, "%d", (int)cstats->server_ops);
       printformat_module("fe-common/silc", server, NULL,
                         MSGLEVEL_CRAP, SILCTXT_STATS,
                           "Total server operators", tmp);
 
-      snprintf(tmp, sizeof(tmp) - 1, "%d", (int)router_ops);
+      snprintf(tmp, sizeof(tmp) - 1, "%d", (int)cstats->router_ops);
       printformat_module("fe-common/silc", server, NULL,
                         MSGLEVEL_CRAP, SILCTXT_STATS,
                         "Total router operators", tmp);
@@ -2193,7 +2176,7 @@ void silc_command_reply(SilcClient client, SilcClientConnection conn,
       (void)va_arg(vp, SilcPublicKey);
       chpks = va_arg(vp, SilcDList);
 
-      if (status != SILC_STATUS_OK || !cmode_list_chpks ||
+      if (SILC_STATUS_IS_ERROR(status) || !cmode_list_chpks ||
          !channel_entry || !channel_entry->channel_name)
        return;
 
@@ -2314,7 +2297,8 @@ silc_verify_public_key_internal(SilcClient client, SilcClientConnection conn,
   memset(file, 0, sizeof(file));
 
   /* Get remote host information */
-  silc_socket_stream_get_info(conn->stream, NULL, &hostname, &ip, &port);
+  silc_socket_stream_get_info(silc_packet_stream_get_stream(conn->stream),
+                             NULL, &hostname, &ip, &port);
 
   if (conn_type == SILC_CONN_SERVER ||
       conn_type == SILC_CONN_ROUTER) {
@@ -2592,6 +2576,8 @@ void silc_get_auth_method(SilcClient client, SilcClientConnection conn,
   silc_client_request_authentication_method(client, conn,
                                            silc_get_auth_method_callback,
                                            internal);
+#else
+  completion(TRUE, SILC_AUTH_NONE, NULL, 0, context);
 #endif
 }
 
@@ -2602,20 +2588,22 @@ void silc_get_auth_method(SilcClient client, SilcClientConnection conn,
    desired (application may start it later by calling the function
    silc_client_perform_key_agreement). */
 
-bool silc_key_agreement(SilcClient client, SilcClientConnection conn,
+void silc_key_agreement(SilcClient client, SilcClientConnection conn,
                        SilcClientEntry client_entry, const char *hostname,
-                       SilcUInt16 port, SilcKeyAgreementCallback *completion,
-                       void **context)
+                       SilcUInt16 protocol, SilcUInt16 port)
 {
-  char portstr[12];
+  char portstr[12], protostr[5];
 
   SILC_LOG_DEBUG(("Start"));
 
   /* We will just display the info on the screen and return FALSE and user
      will have to start the key agreement with a command. */
 
-  if (hostname)
+  if (hostname) {
     snprintf(portstr, sizeof(portstr) - 1, "%d", port);
+    snprintf(protostr, sizeof(protostr) - 1, "%s", protocol == 1 ? "UDP" :
+            "TCP");
+  }
 
   if (!hostname)
     printformat_module("fe-common/silc", NULL, NULL, MSGLEVEL_CRAP,
@@ -2623,12 +2611,7 @@ bool silc_key_agreement(SilcClient client, SilcClientConnection conn,
   else
     printformat_module("fe-common/silc", NULL, NULL, MSGLEVEL_CRAP,
                       SILCTXT_KEY_AGREEMENT_REQUEST_HOST,
-                      client_entry->nickname, hostname, portstr);
-
-  *completion = NULL;
-  *context = NULL;
-
-  return FALSE;
+                      client_entry->nickname, hostname, portstr, protostr);
 }
 
 /* Notifies application that file transfer protocol session is being