Files
nigami/client.c
2010-01-13 08:54:37 +00:00

61 lines
1.1 KiB
C

#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "nigami.h"
#include "client.h"
ngm_client *ngm_client_new(void)
{
ngm_client *this;
this = malloc(sizeof(ngm_client));
this->parser = NULL;
this->password = NULL;
return this;
}
void ngm_client_delete(ngm_client *this)
{
if (this == NULL) {
return;
}
iks_parser_delete(this->parser); /* XXX if not NULL.. */
free(this->password);
free(this);
}
static int on_stream(void *user_data, int type, iks *node)
{
ngm_client *this = (ngm_client *)user_data;
if (node != NULL) {
printf("%s\n", iks_string(iks_stack(node), node));
}
iks_delete(node);
return IKS_OK;
}
int ngm_client_connect(ngm_client *this, const char *id, const char *password)
{
int e;
this->parser = iks_stream_new(IKS_NS_CLIENT, this, on_stream);
this->id = iks_id_new(iks_parser_stack(this->parser), id);
free(this->password);
this->password = malloc(sizeof(password) + 1);
strcpy(this->password, password);
e = iks_connect_tcp(this->parser, this->id->server, IKS_JABBER_PORT);
if (e == IKS_OK) {
return 0;
} else {
return -1;
}
}