Exemplo n.º 1
0
/* 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));
  if (!mybot) {
    perror("Out of memory");
    return 1;
  }

  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 we initialize the 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;
  }

  if (!silc_load_key_pair("mybot.pub", "mybot.prv", "",
			  &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->public_key,
			      &mybot->private_key, FALSE)) {
      perror("Could not generated key pair");
      return 1;
    }
  }

  /* 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
     to the library by calling silc_client_run.  */
  silc_client_run(mybot->client);

  /* When we get here, we have quit the client, so clean up and exit */
  silc_client_free(mybot->client);
  silc_free(mybot);
  return 0;
}
Exemplo n.º 2
0
int weechat_plugin_init(struct t_weechat_plugin *plugin, int argc, char *argv[]) {
    weechat_plugin = plugin;
    SilcClientParams params;

    if (silc_plugin_config_init() < 0) {
        weechat_log_printf("could not initialize SILC plugin config");
        return WEECHAT_RC_ERROR;
    }

    if (silc_plugin_config_read() < 0) {
        weechat_log_printf("could not read SILC plugin config file");
        return WEECHAT_RC_ERROR;
    }

    memset(&params, 0, sizeof(params));
    params.threads = TRUE;

    silc_plugin = silc_calloc(1, sizeof(*silc_plugin));
    if (!silc_plugin) {
        weechat_log_printf("could not allocate plugin context");
        return WEECHAT_RC_ERROR;
    }
    weechat_log_printf("SILC plugin context allocated");

    silc_plugin->client = silc_client_alloc(&ops, &params, silc_plugin, NULL);
    if (!silc_plugin->client) {
        weechat_log_printf("could not allocate SILC client");
        return WEECHAT_RC_ERROR;
    }
    weechat_log_printf("SILC client allocated");

    if (!silc_client_init(silc_plugin->client, weechat_config_string(option_default_username),
                silc_net_localhost(), weechat_config_string(option_default_realname), silc_running, silc_plugin)) {
        weechat_log_printf("could not initialize SILC client");
        return WEECHAT_RC_ERROR;
    }
    // tick the client once to complete the initialization
    silc_client_run_one(silc_plugin->client);
    weechat_log_printf("SILC client initialized");

    silc_plugin_get_keypair("weechat", "", 1, &silc_plugin->public_key, &silc_plugin->private_key);

    server_list = malloc(sizeof(struct SilcPluginServer));
    memset(server_list, 0, sizeof(struct SilcPluginServer));

    weechat_hook_command("silc", "This is the SILC plugin", "", "", NULL, &command_silc, NULL);
    weechat_hook_timer(50, 0, 0, &timer_silc, NULL);

    silc_bar_init();

    return WEECHAT_RC_OK;
}
Exemplo n.º 3
0
static int PySilcClient_Init(PyObject *self, PyObject *args, PyObject *kwds)
{
    PySilcClient *pyclient = (PySilcClient *)self;

    pyclient->conncallback = _pysilc_client_connect_callback;

    pyclient->callbacks.say =               _pysilc_client_callback_say;
    pyclient->callbacks.channel_message =   _pysilc_client_callback_channel_message;
    pyclient->callbacks.private_message =   _pysilc_client_callback_private_message;
    pyclient->callbacks.notify =            _pysilc_client_callback_notify;
    pyclient->callbacks.command =           _pysilc_client_callback_command;
    pyclient->callbacks.command_reply =     _pysilc_client_callback_command_reply;
    pyclient->callbacks.get_auth_method =   _pysilc_client_callback_get_auth_method;
    pyclient->callbacks.verify_public_key = _pysilc_client_callback_verify_key;
    pyclient->callbacks.ask_passphrase =    _pysilc_client_callback_ask_passphrase;
    pyclient->callbacks.key_agreement =     _pysilc_client_callback_key_agreement;
    pyclient->callbacks.ftp =               _pysilc_client_callback_ftp;

    char *nickname = NULL, *username = NULL, *realname = NULL, *hostname = NULL;
    static char *kwlist[] = {"keys", "nickname", "username", "realname", "hostname", NULL};

    PySilcKeys *keys;
    if (!PyArg_ParseTupleAndKeywords(args, kwds, "O|ssss", kwlist,
                                     &keys, &nickname, &username, &realname,
                                     &hostname)) {
        return -1;
    }

    pyclient->silcobj = silc_client_alloc(&(pyclient->callbacks), NULL, pyclient, silc_version_string);
    if (!pyclient->silcobj) {
        PyErr_SetString(PyExc_AssertionError, "Failed to Initialise Silc Client Object");
        return -1;
    }

    if (!PyObject_TypeCheck(keys, &PySilcKeys_Type))
        return -1;

    pyclient->silcconn = NULL;

    memset(&(pyclient->params), 0, sizeof(pyclient->params));

    if (nickname)
        pyclient->params.nickname = strdup(nickname);
    if (username)
        pyclient->silcobj->username = strdup(username);
    else
        pyclient->silcobj->username = silc_get_username();
    if (realname)
        pyclient->silcobj->realname = strdup(realname);
    else
        pyclient->silcobj->realname = silc_get_real_name();
    if (hostname)
        pyclient->silcobj->hostname = strdup(hostname);
    else
        pyclient->silcobj->hostname = silc_net_localhost();

    pyclient->keys = keys;
    Py_INCREF(keys);

    silc_client_init(pyclient->silcobj, pyclient->silcobj->username,
                     pyclient->silcobj->hostname,
                     pyclient->silcobj->realname, _pysilc_client_running,
                     pyclient->silcobj);

    return 0;
}