Пример #1
0
void silc_client_free(SilcClient client)
{
  if (client->schedule)
    silc_schedule_uninit(client->schedule);

  if (client->rng)
    silc_rng_free(client->rng);

  if (!client->internal->params->dont_register_crypto_library) {
    silc_cipher_unregister_all();
    silc_pkcs_unregister_all();
    silc_hash_unregister_all();
    silc_hmac_unregister_all();
  }

  if (client->internal->packet_engine)
    silc_packet_engine_stop(client->internal->packet_engine);
  if (client->internal->ftp_sessions)
    silc_dlist_uninit(client->internal->ftp_sessions);
  if (client->internal->lock)
    silc_mutex_free(client->internal->lock);
  silc_atomic_uninit32(&client->internal->conns);
  silc_free(client->username);
  silc_free(client->hostname);
  silc_free(client->realname);
  silc_free(client->internal->params);
  silc_free(client->internal->silc_client_version);
  silc_free(client->internal);
  silc_free(client);
}
Пример #2
0
void silc_connauth_free(SilcConnAuth connauth)
{
  if (connauth->public_keys)
    silc_dlist_uninit(connauth->public_keys);

  /* Free reference */
  silc_ske_free(connauth->ske);

  silc_free(connauth);
}
Пример #3
0
void silc_attribute_payload_list_free(SilcDList list)
{
  SilcAttributePayload entry;

  silc_dlist_start(list);
  while ((entry = silc_dlist_get(list)) != SILC_LIST_END) {
    silc_attribute_payload_free(entry);
    silc_dlist_del(list, entry);
  }

  silc_dlist_uninit(list);
}
Пример #4
0
void silc_mime_partial_free(SilcDList partials)
{
    SilcBuffer buf;

    if (!partials)
        return;

    silc_dlist_start(partials);
    while ((buf = silc_dlist_get(partials)) != SILC_LIST_END)
        silc_buffer_free(buf);
    silc_dlist_uninit(partials);
}
Пример #5
0
static void skr_found(SilcSKR skr, SilcSKRFind find, SilcSKRStatus status,
		      SilcDList results, void *context)
{
  SilcSKRKey key;

  SILC_LOG_DEBUG(("Result status %d", status));
  if (status & SILC_SKR_OK) {
    SILC_LOG_DEBUG(("Found %d keys", silc_dlist_count(results)));

    while ((key = silc_dlist_get(results)) != SILC_LIST_END)
      SILC_LOG_DEBUG(("Key: %s", ((SilcPublicKey)key->key)->identifier));

    silc_dlist_uninit(results);
    found = TRUE;
  } else
    found = FALSE;
}
Пример #6
0
void silc_mime_free(SilcMime mime)
{
    SilcMime m;

    if (mime->fields)
        silc_hash_table_free(mime->fields);

    if (mime->multiparts) {
        silc_dlist_start(mime->multiparts);
        while ((m = silc_dlist_get(mime->multiparts)) != SILC_LIST_END)
            silc_mime_free(m);
        silc_dlist_uninit(mime->multiparts);
    }
    silc_free(mime->boundary);
    silc_free(mime->multitype);
    silc_free(mime->data);
    silc_free(mime);
}
Пример #7
0
SilcBool silc_client_del_channel_private_key(SilcClient client,
					     SilcClientConnection conn,
					     SilcChannelEntry channel,
					     SilcChannelPrivateKey key)
{
  SilcChannelPrivateKey entry;

  if (!client || !conn || !channel)
    return FALSE;

  if (!channel->internal.private_keys)
    return FALSE;

  silc_dlist_start(channel->internal.private_keys);
  while ((entry = silc_dlist_get(channel->internal.private_keys))) {
    if (entry != key)
      continue;

    if (channel->internal.curr_key == entry) {
      channel->internal.curr_key = NULL;
      channel->cipher = silc_cipher_get_name(channel->internal.send_key);
      channel->hmac = silc_hmac_get_name(channel->internal.hmac);
    }

    silc_dlist_del(channel->internal.private_keys, entry);
    silc_free(entry->name);
    silc_cipher_free(entry->send_key);
    silc_cipher_free(entry->receive_key);
    silc_hmac_free(entry->hmac);
    silc_free(entry);

    if (silc_dlist_count(channel->internal.private_keys) == 0) {
      silc_dlist_uninit(channel->internal.private_keys);
      channel->internal.private_keys = NULL;
    }

    return TRUE;
  }

  return FALSE;
}
Пример #8
0
SilcDList silcpurple_image_message(const char *msg, SilcMessageFlags *mflags)
{
	SilcMime mime = NULL, p;
	SilcDList list, parts = NULL;
	const char *start, *end, *last;
	GData *attribs;
	char *type;
	gboolean images = FALSE;

	last = msg;
	while (last && *last && purple_markup_find_tag("img", last, &start,
						     &end, &attribs)) {
		PurpleStoredImage *image = NULL;
		const char *id;

		/* Check if there is text before image */
		if (start - last) {
			char *text, *tmp;
			p = silc_mime_alloc();

			/* Add content type */
			silc_mime_add_field(p, "Content-Type",
					    "text/plain; charset=utf-8");

			tmp = g_strndup(last, start - last);
			text = purple_unescape_html(tmp);
			g_free(tmp);

			/* Add text */
			silc_mime_add_data(p, (const unsigned char *)text, strlen(text));
			g_free(text);

			if (!parts)
				parts = silc_dlist_init();
			silc_dlist_add(parts, p);
		}

		id = g_datalist_get_data(&attribs, "id");
		if (id && (image = purple_imgstore_find_by_id(atoi(id)))) {
			unsigned long imglen = purple_imgstore_get_size(image);
			gconstpointer img = purple_imgstore_get_data(image);

			p = silc_mime_alloc();

			/* Add content type */
			type = silcpurple_file2mime(purple_imgstore_get_filename(image));
			if (!type) {
				g_datalist_clear(&attribs);
				last = end + 1;
				continue;
			}
			silc_mime_add_field(p, "Content-Type", type);
			g_free(type);

			/* Add content transfer encoding */
			silc_mime_add_field(p, "Content-Transfer-Encoding", "binary");

			/* Add image data */
			silc_mime_add_data(p, img, imglen);

			if (!parts)
				parts = silc_dlist_init();
			silc_dlist_add(parts, p);
			images = TRUE;
		}

		g_datalist_clear(&attribs);

		/* Continue after tag */
		last = end + 1;
	}

	/* Check for text after the image(s) */
	if (images && last && *last) {
		char *tmp = purple_unescape_html(last);
		p = silc_mime_alloc();

		/* Add content type */
		silc_mime_add_field(p, "Content-Type",
				    "text/plain; charset=utf-8");

		/* Add text */
		silc_mime_add_data(p, (const unsigned char *)tmp, strlen(tmp));
		g_free(tmp);

		if (!parts)
			parts = silc_dlist_init();
		silc_dlist_add(parts, p);
	}

	/* If there weren't any images, don't return anything. */
	if (!images) {
		if (parts)
			silc_dlist_uninit(parts);
		return NULL;
	}

	if (silc_dlist_count(parts) > 1) {
		/* Multipart MIME message */
		char b[32];
		mime = silc_mime_alloc();
		silc_mime_add_field(mime, "MIME-Version", "1.0");
		g_snprintf(b, sizeof(b), "b%4X%4X",
			   (unsigned int)time(NULL),
			   silc_dlist_count(parts));
		silc_mime_set_multipart(mime, "mixed", b);
		silc_dlist_start(parts);
		while ((p = silc_dlist_get(parts)) != SILC_LIST_END)
			silc_mime_add_multipart(mime, p);
	} else {
		/* Simple MIME message */
		silc_dlist_start(parts);
		mime = silc_dlist_get(parts);
		silc_mime_add_field(mime, "MIME-Version", "1.0");
	}

	*mflags &= ~SILC_MESSAGE_FLAG_UTF8;
	*mflags |= SILC_MESSAGE_FLAG_DATA;

	/* Encode message. Fragment if it is too large */
	list = silc_mime_encode_partial(mime, 0xfc00);

	silc_dlist_uninit(parts);

	/* Added multiparts gets freed here */
	silc_mime_free(mime);

	return list;
}
Пример #9
0
SilcBool silc_client_channel_save_public_keys(SilcChannelEntry channel,
					      unsigned char *chpk_list,
					      SilcUInt32 chpk_list_len,
					      SilcBool remove_all)
{
  SilcArgumentDecodedList a, b;
  SilcDList chpks;
  SilcBool found;

  if (remove_all) {
    /* Remove all channel public keys */
    if (!channel->channel_pubkeys)
      return FALSE;

    silc_dlist_start(channel->channel_pubkeys);
    while ((b = silc_dlist_get(channel->channel_pubkeys)))
      silc_dlist_del(channel->channel_pubkeys, b);

    silc_dlist_uninit(channel->channel_pubkeys);
    channel->channel_pubkeys = NULL;

    return TRUE;
  }

  /* Parse channel public key list and add or remove public keys */
  chpks = silc_argument_list_parse_decoded(chpk_list, chpk_list_len,
					   SILC_ARGUMENT_PUBLIC_KEY);
  if (!chpks)
    return FALSE;

  if (!channel->channel_pubkeys) {
    channel->channel_pubkeys = silc_dlist_init();
    if (!channel->channel_pubkeys) {
      silc_argument_list_free(chpks, SILC_ARGUMENT_PUBLIC_KEY);
      return FALSE;
    }
  }

  silc_dlist_start(chpks);
  while ((a = silc_dlist_get(chpks))) {
    found = FALSE;
    silc_dlist_start(channel->channel_pubkeys);
    while ((b = silc_dlist_get(channel->channel_pubkeys))) {
      if (silc_pkcs_public_key_compare(a->argument, b->argument)) {
	found = TRUE;
	break;
      }
    }

    if ((a->arg_type == 0x00 || a->arg_type == 0x03) && !found) {
      silc_dlist_add(channel->channel_pubkeys, a);
      silc_dlist_del(chpks, a);
    } else if (a->arg_type == 0x01 && found) {
      silc_dlist_del(channel->channel_pubkeys, b);
    }
  }

  silc_argument_list_free(chpks, SILC_ARGUMENT_PUBLIC_KEY);

  return TRUE;
}