5 Author: Pekka Riikonen <priikone@silcnet.org>
7 Copyright (C) 2001 Pekka Riikonen
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; version 2 of the License.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
20 #include "silcerapp.hh"
23 #include <sys/utsname.h>
24 #include <glade/glade.h>
25 #include <libgnome/gnome-triggers.h>
26 #include <libgnome/gnome-util.h>
27 #include <libgnomeui/gnome-window-icon.h>
28 #include <gnome--/client.h>
30 // Pointer to the application
31 SilcerApp *Silcer_App;
32 string package = "silcer";
33 string version = "1.0";
35 SilcClient silc_client;
36 SilcClientConnection silc_client_conn;
39 silc_create_key_pair(char *pkcs_name, int bits, char *path,
41 SilcPublicKey *ret_pub_key,
42 SilcPrivateKey *ret_prv_key)
45 SilcPublicKey pub_key;
46 SilcPrivateKey prv_key;
50 char pkfile[256], prvfile[256];
52 if (!pkcs_name || !path)
58 rng = silc_rng_alloc();
60 silc_rng_global_init(rng);
63 silc_pkcs_alloc((const unsigned char *)pkcs_name, &pkcs);
64 pkcs->pkcs->init(pkcs->context, bits, rng);
66 /* Save public key into file */
67 key = silc_pkcs_get_public_key(pkcs, &key_len);
68 pub_key = silc_pkcs_public_key_alloc(pkcs->pkcs->name, identifier,
70 *ret_pub_key = pub_key;
72 memset(key, 0, sizeof(key_len));
75 /* Save private key into file */
76 key = silc_pkcs_get_private_key(pkcs, &key_len);
77 prv_key = silc_pkcs_private_key_alloc(pkcs->pkcs->name, key, key_len);
78 *ret_prv_key = prv_key;
80 memset(key, 0, sizeof(key_len));
90 void silc_op_say(SilcClient client, SilcClientConnection conn,
91 SilcClientMessageType type, char *msg, ...)
97 str = g_strdup_vprintf(msg, va);
98 Silcer_App->_MainDialog->print((string)str);
104 void silc_channel_message(SilcClient client, SilcClientConnection conn,
105 SilcClientEntry sender, SilcChannelEntry channel,
106 SilcMessageFlags flags, char *msg)
108 Silcer_App->_MainDialog->print((string)msg, (string)sender->nickname);
112 void silc_private_message(SilcClient client, SilcClientConnection conn,
113 SilcClientEntry sender, SilcMessageFlags flags,
116 Silcer_App->_MainDialog->print((string)msg);
120 void silc_notify(SilcClient client, SilcClientConnection conn,
121 SilcNotifyType type, ...)
126 Silcer_App->_MainDialog->print((string)va_arg(va, char *));
131 void silc_connect(SilcClient client, SilcClientConnection conn, int success)
133 silc_client_conn = conn;
137 void silc_disconnect(SilcClient client, SilcClientConnection conn)
139 silc_client_conn = NULL;
143 void silc_auth_meth(SilcClient client,
144 SilcClientConnection conn,
145 char *hostname, uint16 port,
146 SilcGetAuthMeth completion, void *context)
148 completion(TRUE, SILC_AUTH_NONE, NULL, 0, context);
152 void silc_verify_public_key(SilcClient client, SilcClientConnection conn,
153 SilcSocketType conn_type, unsigned char *pk,
154 uint32 pk_len, SilcSKEPKType pk_type,
155 SilcVerifyPublicKey completion, void *context)
157 completion(TRUE, context);
161 void silc_command(SilcClient client, SilcClientConnection conn,
162 SilcClientCommandContext cmd_context, int success,
169 void silc_command_reply(SilcClient client, SilcClientConnection conn,
170 SilcCommandPayload cmd_payload, int success,
171 SilcCommand command, SilcCommandStatus status, ...)
176 /* SILC client operations */
177 SilcClientOperations ops = {
179 silc_channel_message,
180 silc_private_message,
187 silc_verify_public_key,
194 SILC_TASK_CALLBACK(connect_client)
196 SilcClient client = (SilcClient)context;
197 silc_client_connect_to_server(client, 706, "silc.silcnet.org", NULL);
200 SilcerApp::SilcerApp(int argc, char **argv)
201 : _GnomeApp(package, version, argc, argv),
202 _gclient(Gnome::Client::master_client())
204 // Save application pointer
207 // Initialize SILC stuff
209 silc_debug_hexdump = TRUE;
210 silc_log_set_debug_string("*client*,*net*,*ske*");
212 // Initialize SILC Client Library */
213 silc_client = silc_client_alloc(&ops, NULL, NULL, "SILC-1.0-0.6.2");
214 silc_client->realname = "pekka riikonen";
215 silc_client->username = "priikone";
216 silc_client->hostname = "mun.oma.kone";
217 silc_cipher_register_default();
218 silc_pkcs_register_default();
219 silc_hash_register_default();
220 silc_hmac_register_default();
221 silc_create_key_pair("rsa", 1024, "kk", "UN=priikone, "
222 "HN=pelle.kuo.fi.ssh.com",
223 &silc_client->public_key, &silc_client->private_key);
224 silc_client_init(silc_client);
226 // Setup SILC scheduler as timeout task
227 Gnome::Main::timeout.connect(slot(this, &SilcerApp::silc_scheduler), 50);
229 silc_schedule_task_add(silc_client->schedule, 0, connect_client,
230 silc_client, 0, 1, SILC_TASK_TIMEOUT,
231 SILC_TASK_PRI_NORMAL);
236 // Locate glade files
237 if (!g_file_exists(string(_SourceDir + "SilcerMainDlg.glade").c_str()))
239 if (!g_file_exists(string(_SourceDir + "SilcerMainDlg.glade").c_str()))
240 _SourceDir = "./ui/";
241 if (!g_file_exists(string(_SourceDir + "SilcerMainDlg.glade").c_str()))
242 _SourceDir = "./src/";
243 if (!g_file_exists(string(_SourceDir + "SilcerMainDlg.glade").c_str())) {
244 g_error("Could not find SilcerMainDlg.glade");
248 _MainDialog = new SilcerMainDlg();
251 SilcerApp::~SilcerApp()
256 void SilcerApp::run()
258 // Let the gnome app start processing messages
262 void SilcerApp::quit()
264 // Stop gtk/gnome message loop
269 GladeXML *SilcerApp::load_resource(const char *name)
271 return glade_xml_new(string(_SourceDir + name + ".glade").c_str(), name);
274 GladeXML *SilcerApp::load_resource(const char *name, const char *filename)
276 return glade_xml_new(string(_SourceDir + filename + ".glade").c_str(), name);
279 gint SilcerApp::silc_scheduler()
281 silc_client_run_one(silc_client);