Integer type name change.
[silc.git] / apps / silc / silc.c
index ce9f7ee028dd58d84490abbb52132efcb99cef88..e449af1d89883c03da6294b2bcbcd146017e7f21 100644 (file)
@@ -59,6 +59,7 @@ static struct option long_opts[] =
   { "create-key-pair", 0, NULL, 'C' },
   { "pkcs", 1, NULL, 10 },
   { "bits", 1, NULL, 11 },
+  { "show-key", 1, NULL, 'S' },
 
   { NULL, 0, NULL, 0 }
 };
@@ -72,10 +73,12 @@ static char *opt_cipher = NULL;
 static char *opt_public_key = NULL;
 static char *opt_private_key = NULL;
 static char *opt_config_file = NULL;
-static int opt_no_silcrc = FALSE;
+static bool opt_no_silcrc = FALSE;
 
-static int opt_create_keypair = FALSE;
+static bool opt_create_keypair = FALSE;
+static bool opt_show_key = FALSE;
 static char *opt_pkcs = NULL;
+static char *opt_keyfile = NULL;
 static int opt_bits = 0;
 
 /* SILC Client operations */
@@ -109,6 +112,7 @@ Usage: silc [options]\n\
   -C, --create-key-pair        Create new public key pair\n\
       --pkcs=PKCS              Set the PKCS of the public key pair\n\
       --bits=VALUE             Set length of the public key pair\n\
+  -S, --show-key=FILE          Show the contents of the public key\n\
 \n");
 }
 
@@ -125,7 +129,7 @@ int main(int argc, char **argv)
     {
       while ((opt = 
              getopt_long(argc, argv,
-                         "s:p:n:c:b:k:f:qdhVC",
+                         "s:p:n:c:b:k:f:qdhVCS:",
                          long_opts, &option_index)) != EOF)
        {
          switch(opt) 
@@ -210,6 +214,11 @@ SILC Secure Internet Live Conferencing, version %s\n",
              if (optarg)
                opt_bits = atoi(optarg);
              break;
+           case 'S':
+             opt_show_key = TRUE;
+             if (optarg)
+               opt_keyfile = strdup(optarg);
+             break;
 
            default:
              exit(0);
@@ -237,8 +246,24 @@ SILC Secure Internet Live Conferencing, version %s\n",
 
   if (opt_create_keypair == TRUE) {
     /* Create new key pair and exit */
+    silc_cipher_register_default();
+    silc_pkcs_register_default();
+    silc_hash_register_default();
+    silc_hmac_register_default();
     silc_client_create_key_pair(opt_pkcs, opt_bits, 
                                NULL, NULL, NULL, NULL, NULL);
+    silc_free(opt_pkcs);
+    exit(0);
+  }
+
+  if (opt_show_key == TRUE) {
+    /* Dump the key */
+    silc_cipher_register_default();
+    silc_pkcs_register_default();
+    silc_hash_register_default();
+    silc_hmac_register_default();
+    silc_client_show_key(opt_keyfile);
+    silc_free(opt_keyfile);
     exit(0);
   }
 
@@ -250,30 +275,42 @@ SILC Secure Internet Live Conferencing, version %s\n",
   app = silc_calloc(1, sizeof(*app));
 
   /* Allocate new client */
-  app->client = silc = silc_client_alloc(&ops, app);
+  app->client = silc = silc_client_alloc(&ops, app, silc_version_string);
   if (!silc)
     goto fail;
 
   /* Read global configuration file. */
   app->config = silc_client_config_alloc(opt_config_file);
-  if (app->config == NULL)
-    goto fail;
 
   /* XXX Read local configuration file */
 
-  /* Check ~/.silc directory and public and private keys */
-  if (silc_client_check_silc_dir() == FALSE)
-    goto fail;
-
   /* Get user information */
   silc->username = silc_get_username();
+  silc->hostname = silc_net_localhost();
   silc->realname = silc_get_real_name();
 
   /* Register all configured ciphers, PKCS and hash functions. */
-  app->config->client = (void *)app;
-  silc_client_config_register_ciphers(app->config);
-  silc_client_config_register_pkcs(app->config);
-  silc_client_config_register_hashfuncs(app->config);
+  if (app->config) {
+    app->config->client = (void *)app;
+    if (!silc_client_config_register_ciphers(app->config))
+      silc_cipher_register_default();
+    if (!silc_client_config_register_pkcs(app->config))
+      silc_pkcs_register_default();
+    if (!silc_client_config_register_hashfuncs(app->config))
+      silc_hash_register_default();
+    if (!silc_client_config_register_hmacs(app->config))
+      silc_hmac_register_default();
+  } else {
+    /* Register default ciphers, pkcs, hash funtions and hmacs. */
+    silc_cipher_register_default();
+    silc_pkcs_register_default();
+    silc_hash_register_default();
+    silc_hmac_register_default();
+  }
+
+  /* Check ~/.silc directory and public and private keys */
+  if (silc_client_check_silc_dir() == FALSE)
+    goto fail;
 
   /* Load public and private key */
   if (silc_client_load_keys(silc) == FALSE)
@@ -301,7 +338,7 @@ SILC Secure Internet Live Conferencing, version %s\n",
                     SILC_TASK_TIMEOUT,
                     SILC_TASK_PRI_LOW);
 
-  if (app->config->commands) {
+  if (app->config && app->config->commands) {
     /* Run user configured commands with timeout */
     silc_task_register(silc->timeout_queue, 0,
                       silc_client_run_commands,
@@ -425,17 +462,19 @@ SILC_TASK_CALLBACK(silc_client_process_key_press)
     break;
   case CTRL('a'):
   case KEY_HOME:
+#ifdef KEY_BEG
   case KEY_BEG:
+#endif
     /* Beginning, Home */
     silc_screen_input_cursor_home(app->screen);
     break;
   case CTRL('e'):
+#ifdef KEY_END
   case KEY_END:
-    /* End */
-    silc_screen_input_cursor_end(app->screen);
-    break;
+#endif
   case KEY_LL:
     /* End */
+    silc_screen_input_cursor_end(app->screen);
     break;
   case CTRL('g'):
     /* Bell, Ctrl^g */
@@ -480,8 +519,12 @@ static int silc_client_bad_keys(unsigned char key)
   case KEY_B2:
   case KEY_C1:
   case KEY_C3:
+#ifdef KEY_UNDO
   case KEY_UNDO:
+#endif
+#ifdef KEY_EXIT
   case KEY_EXIT:
+#endif
   case '\v':           /* VT */
   case '\E':           /* we ignore ESC */
     return TRUE;
@@ -506,7 +549,7 @@ static void silc_client_clear_input(SilcClientInternal app)
 static void silc_client_process_message(SilcClientInternal app)
 {
   unsigned char *data;
-  unsigned int len;
+  SilcUInt32 len;
 
   SILC_LOG_DEBUG(("Start"));
 
@@ -515,9 +558,9 @@ static void silc_client_process_message(SilcClientInternal app)
 
   if (data[0] == '/' && data[1] != ' ') {
     /* Command */
-    unsigned int argc = 0;
+    SilcUInt32 argc = 0;
     unsigned char **argv, *tmpcmd;
-    unsigned int *argv_lens, *argv_types;
+    SilcUInt32 *argv_lens, *argv_types;
     SilcClientCommand *cmd;
     SilcClientCommandContext ctx;
 
@@ -539,7 +582,7 @@ static void silc_client_process_message(SilcClientInternal app)
 
     /* Allocate command context. This and its internals must be free'd 
        by the command routine receiving it. */
-    ctx = silc_calloc(1, sizeof(*ctx));
+    ctx = silc_client_command_alloc();
     ctx->client = app->client;
     ctx->conn = app->conn;
     ctx->command = cmd;
@@ -553,13 +596,13 @@ static void silc_client_process_message(SilcClientInternal app)
 
   } else {
     /* Normal message to a channel */
-    if (len && app->conn->current_channel &&
+    if (len && app->conn && app->conn->current_channel &&
        app->conn->current_channel->on_channel == TRUE) {
       silc_print(app->client, "> %s", data);
-      silc_client_packet_send_to_channel(app->client, 
-                                        app->conn->sock,
-                                        app->conn->current_channel,
-                                        data, strlen(data), TRUE);
+      silc_client_send_channel_message(app->client, 
+                                      app->conn,
+                                      app->conn->current_channel, NULL,
+                                      0, data, strlen(data), TRUE);
     }
   }
 
@@ -615,9 +658,9 @@ SILC_TASK_CALLBACK(silc_client_run_commands)
 
   cs = app->config->commands;
   while(cs) {
-    unsigned int argc = 0;
+    SilcUInt32 argc = 0;
     unsigned char **argv, *tmpcmd;
-    unsigned int *argv_lens, *argv_types;
+    SilcUInt32 *argv_lens, *argv_types;
     SilcClientCommand *cmd;
     SilcClientCommandContext ctx;
 
@@ -639,7 +682,7 @@ SILC_TASK_CALLBACK(silc_client_run_commands)
 
     /* Allocate command context. This and its internals must be free'd 
        by the command routine receiving it. */
-    ctx = silc_calloc(1, sizeof(*ctx));
+    ctx = silc_client_command_alloc();
     ctx->client = client;
     ctx->conn = app->conn;
     ctx->command = cmd;