static PyObject *pysilc_client_send_channel_message(PyObject *self, PyObject *args, PyObject *kwds)
{
    PySilcChannel *channel;
    char *message = NULL;
    int length = 0;
    int result = 0;
    PyObject *private_key = NULL; // TODO: ignored at the moment
    unsigned int defaultFlags = SILC_MESSAGE_FLAG_UTF8;
    unsigned int flags = 0;
    PySilcClient *pyclient = (PySilcClient *)self;

    static char *kwlist[] = {"channel", "msg", "private_key", "flags", NULL};

    if (!PyArg_ParseTupleAndKeywords(args, kwds, "Oes#|OI", kwlist, &channel, "utf-8", &message, &length, &private_key, &flags))
        return NULL;

    if (!PyObject_IsInstance((PyObject *)channel, (PyObject *)&PySilcChannel_Type))
        return NULL;

    if (!pyclient || !pyclient->silcobj) {
        PyErr_SetString(PyExc_RuntimeError, "SILC Client Not Initialised");
        return NULL;
     }

    result = silc_client_send_channel_message(pyclient->silcobj,
                                              pyclient->silcconn,
                                              channel->silcobj,
                                              NULL,
                                              flags | defaultFlags,
                                              NULL,
                                              message, length);

    return PyInt_FromLong(result);
}
Beispiel #2
0
void silcpurple_wb_send(PurpleWhiteboard *wb, GList *draw_list)
{
	SilcPurpleWb wbs = wb->proto_data;
	SilcBuffer packet;
	GList *list;
	int len;
        PurpleConnection *gc;
        SilcPurple sg;

	g_return_if_fail(draw_list);
	gc = purple_account_get_connection(wb->account);
	g_return_if_fail(gc);
 	sg = gc->proto_data;
	g_return_if_fail(sg);

	len = SILCPURPLE_WB_HEADER;
	for (list = draw_list; list; list = list->next)
		len += 4;

	packet = silc_buffer_alloc_size(len);
	if (!packet)
		return;

	/* Assmeble packet */
	silc_buffer_format(packet,
			   SILC_STR_UI32_STRING(SILCPURPLE_WB_MIME),
			   SILC_STR_UI_CHAR(SILCPURPLE_WB_DRAW),
			   SILC_STR_UI_SHORT(wbs->width),
			   SILC_STR_UI_SHORT(wbs->height),
			   SILC_STR_UI_INT(wbs->brush_color),
			   SILC_STR_UI_SHORT(wbs->brush_size),
			   SILC_STR_END);
	silc_buffer_pull(packet, SILCPURPLE_WB_HEADER);
	for (list = draw_list; list; list = list->next) {
		silc_buffer_format(packet,
				   SILC_STR_UI_INT(GPOINTER_TO_INT(list->data)),
				   SILC_STR_END);
		silc_buffer_pull(packet, 4);
	}

	/* Send the message */
	if (wbs->type == 0) {
		/* Private message */
		silc_client_send_private_message(sg->client, sg->conn,
						 wbs->u.client,
						 SILC_MESSAGE_FLAG_DATA, NULL,
						 packet->head, len);
	} else if (wbs->type == 1) {
		/* Channel message. Channel private keys are not supported. */
		silc_client_send_channel_message(sg->client, sg->conn,
						 wbs->u.channel, NULL,
						 SILC_MESSAGE_FLAG_DATA, NULL,
						 packet->head, len);
	}

	silc_buffer_free(packet);
}
Beispiel #3
0
int silc_plugin_channel_input(void *data, struct t_gui_buffer *buffer, const char *input_data) {
    struct SilcChannelContext *chanCtx = data;

    silc_client_send_channel_message(silc_plugin->client, chanCtx->connection, chanCtx->channel_entry,
            NULL, SILC_MESSAGE_FLAG_NONE, NULL, (unsigned char *)input_data, strlen(input_data));
    weechat_printf(buffer, "%s\t%s", chanCtx->connection->local_entry->nickname, input_data);

    return WEECHAT_RC_OK;
}
Beispiel #4
0
static void
silc_command_reply(SilcClient client, SilcClientConnection conn,
		   SilcCommand command, SilcStatus status,
		   SilcStatus error, va_list ap)
{
  /* If error occurred in client library with our command, print the error */
  if (status != SILC_STATUS_OK)
    fprintf(stderr, "MyBot: COMMAND REPLY %s: %s\n",
	    silc_get_command_name(command),
	    silc_get_status_message(status));

  /* Check for successful JOIN.  See
     http://silcnet.org/docs/toolkit/command_reply_args.html for the
     different arguments the client library returns. */
  if (command == SILC_COMMAND_JOIN) {
    SilcChannelEntry channel;
    SilcHash sha1hash;

    (void)va_arg(ap, SilcClientEntry);
    channel = va_arg(ap, SilcChannelEntry);

    fprintf(stdout, "MyBot: Joined '%s' channel\n", channel->channel_name);

    /* Now send the "hello" to the channel */
    silc_client_send_channel_message(client, conn, channel, NULL, 0, NULL,
				     "hello", strlen("hello"));
    fprintf(stdout, "MyBot: Sent 'hello' to channel\n");

    /* Now send digitally signed "hello" to the channel.  We have to allocate
       hash function for the signature process. */
    silc_hash_alloc("sha1", &sha1hash);
    silc_client_send_channel_message(client, conn, channel, NULL,
				     SILC_MESSAGE_FLAG_SIGNED, sha1hash,
				     "hello, with signature",
				     strlen("hello, with signature"));
    silc_hash_free(sha1hash);
    fprintf(stdout, "MyBot: Sent 'hello, with signature' to channel\n");
  }
}
Beispiel #5
0
void silcpurple_wb_clear(PurpleWhiteboard *wb)
{
	SilcPurpleWb wbs = wb->proto_data;
	SilcBuffer packet;
	int len;
        PurpleConnection *gc;
        SilcPurple sg;

	gc = purple_account_get_connection(wb->account);
	g_return_if_fail(gc);
 	sg = gc->proto_data;
	g_return_if_fail(sg);

	len = SILCPURPLE_WB_HEADER;
	packet = silc_buffer_alloc_size(len);
	if (!packet)
		return;

	/* Assmeble packet */
	silc_buffer_format(packet,
			   SILC_STR_UI32_STRING(SILCPURPLE_WB_MIME),
			   SILC_STR_UI_CHAR(SILCPURPLE_WB_CLEAR),
			   SILC_STR_UI_SHORT(wbs->width),
			   SILC_STR_UI_SHORT(wbs->height),
			   SILC_STR_UI_INT(wbs->brush_color),
			   SILC_STR_UI_SHORT(wbs->brush_size),
			   SILC_STR_END);

	/* Send the message */
	if (wbs->type == 0) {
		/* Private message */
		silc_client_send_private_message(sg->client, sg->conn,
						 wbs->u.client,
						 SILC_MESSAGE_FLAG_DATA, NULL,
						 packet->head, len);
	} else if (wbs->type == 1) {
		/* Channel message */
		silc_client_send_channel_message(sg->client, sg->conn,
						 wbs->u.channel, NULL,
						 SILC_MESSAGE_FLAG_DATA, NULL,
						 packet->head, len);
	}

	silc_buffer_free(packet);
}