bsdua.org

/projects/libbsdua

This library is a collection of source files, rather than complete binary library. Anyway, all files are BSD licensed, so you can use them freely in your projects. If you don't know what BSD license gives to you, just read it in wikipedia.

Consists of:

UTF-8 <-> Unicode convertion library

It's an implementation of RFC3629. It can convert UCS4 (wchar_t) strings into UTF-8 string and vice versa. I plan to add support of streaming when converting from UTF-8 and support of specifying different endians (not one that local machine has).

Files:

SASL Digest-MD5

Digestmd5 is a implementation of SASL Digest-MD5 authentication method (RC2831). This implementation lacks auth-int, auth-conf and server part but it's functional for most of clients' needs.

Files:

Example:

#include <sys/types.h>
#include <stdio.h>
#include <string.h>

#include "digest-md5.h"

void
client_auth_session(struct digestmd5_client *ctx)
{
	char *realm;
	u_int n, i;
	int error, flags;
	struct digestmd5_client_authinfo auth;
	char buf[1000];

	/*
	 * Challenge #1
	 */
	printf("Enter challenge: ");
	fflush(stdout);
	scanf("%999s", buf);

	error = digestmd5_client_challenge(ctx, buf, strlen(buf));
	if (error != DIGESTMD5_OK) {
		fprintf(stderr, "broken challenge\n");
		return;
	}

	printf("Realms:\n");
	n = digestmd5_client_num_realms(ctx);
	if (n > 0) {
		for (i = 0; i < n; i++)
			printf("\t%s\n", digestmd5_client_get_realm(ctx, i));
		realm = digestmd5_client_get_realm(ctx, 0);
	} else
		realm = "bsdua.org";

	flags = digestmd5_client_flags(ctx);
	printf("Charset: %s\n",
	    ((flags & DIGESTMD5_UTF8) != 0) ? "utf-8" : "iso8859-1");

	memset(&auth, 0, sizeof(auth));
	auth.username="your_name";
	auth.passwd="your_password";
	auth.realm = realm;
	auth.servtype="smtp";
	auth.host = "bsdua.org";

	error = digestmd5_client_set_authinfo(ctx, &auth);
	if (error != DIGESTMD5_OK) {
		fprintf(stderr, "cannot set authinfo\n");
		return;
	}

	error = digestmd5_client_response(ctx);
	if (error != DIGESTMD5_OK)
		return;

	printf("%s\n", digestmd5_client_buf(ctx, NULL));

	/*
	 * Challenge #2
	 */
	printf("Enter challenge: ");
	fflush(stdout);
	scanf("%999s", buf);

	error = digestmd5_client_challenge(ctx, buf, strlen(buf));
	if (error == DIGESTMD5_DONE) {
		printf("authentication is successful\n");

	} else if (error == DIGESTMD5_OK) {
		fprintf(stderr, "authentication is not complete\n");
		return;

	} else {
		fprintf(stderr, "error!\n");
		return;
	}
}

int
main(void)
{
	struct digestmd5_client *client;

	client = digestmd5_client_alloc();

	client_auth_session(client);

	digestmd5_client_free(client);

	return (0);
}
   

VPOOL

Vpool is an auto-resizeable buffer (dynamic array). Using it, you don't need to care about memory allocation, boundary checking, pointer manipulations and etc.

Files:

Example:

int
main(void)
{
	struct vpool vp;
	char *p;
	int error;
	size_t len;

	/*
	 * Initialize vpool object.
	 * Use 1024 bytes allocation block.
	 * `vp' buffer will have no limits (actually, SIZE_MAX).
	 */
	vpool_init(&vp, 1024, 0);

	/*
	 * Allocate 100 bytes at the end of pool.
	 */
	p = (char *) vpool_expand(&vp, VPOOL_TAIL, 100);
	if (p != NULL)
		memset(p, 'A', 100);

	/*
	 * Insert 3 bytes ("BBB") starting from position 2
	 * into the pool.
	 */
	p = vpool_insert(&vp, 2, "BBB", 3);

	/*
	 * Truncate pool. Leave 5 bytes starting from position 3.
	 */
	error = vpool_truncate(&vp, 3, 5, VPOOL_INCLUDE);

	/*
	 * Access data
	 */
	if (!vpool_is_empty(&vp)) {
		p = (char *) vpool_get_buf(&vp);
		len = vpool_get_length(&vp);

		/*
		 * XXX - do whatever you want with the buffer.
		 * But remember! The pointer is valid until
		 * you make vpool_expand(), vpool_insert(), vpool_truncate()
		 */
	}

	/*
	 * Free resources allocated by pool.
	 */
	vpool_final(&vp);

	exit(0);
}
   
Ukrainian OpenBSD User Group
Get Firefox

Copyright © 2006-2012, Alexey Vatchenko. All rights reserved.
Designed by Vladimir Mostovoy.