Example #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;
}
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;
}
Example #3
0
char *silc_get_real_name(void)
{
  return silc_get_username();
}