Set auth properties on XMPPClient
This commit is contained in:
@@ -59,7 +59,7 @@ end_element(void *data, const char *element)
|
||||
depth--;
|
||||
|
||||
if (stanza_get_child_by_ns(curr_stanza, "jabber:iq:auth")) {
|
||||
auth_cb(xmppclient);
|
||||
auth_cb(curr_stanza, xmppclient);
|
||||
}
|
||||
|
||||
if (depth > 0) {
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
#ifndef __H_PARSER
|
||||
#define __H_PARSER
|
||||
|
||||
#include "server/stanza.h"
|
||||
#include "server/xmppclient.h"
|
||||
|
||||
typedef void (*stream_start_func)(void * const userdata);
|
||||
typedef void (*auth_func)(void * const userdata);
|
||||
typedef void (*stream_start_func)(XMPPClient *client);
|
||||
typedef void (*auth_func)(XMPPStanza *stanza, XMPPClient *client);
|
||||
|
||||
void parser_init(XMPPClient *client, stream_start_func startcb, auth_func authcb);
|
||||
int parser_feed(char *chunk, int len);
|
||||
|
||||
@@ -119,10 +119,9 @@ listen_to(XMPPClient *client)
|
||||
}
|
||||
|
||||
void
|
||||
stream_start_callback(void *userdata)
|
||||
stream_start_callback(XMPPClient *client)
|
||||
{
|
||||
printf("\n--> Stream start callback fired\n");
|
||||
XMPPClient *client = (XMPPClient*)userdata;
|
||||
send_to(client, XML_START);
|
||||
send_to(client, STREAM_RESP);
|
||||
send_to(client, FEATURES);
|
||||
@@ -130,10 +129,18 @@ stream_start_callback(void *userdata)
|
||||
}
|
||||
|
||||
void
|
||||
auth_callback(void *userdata)
|
||||
auth_callback(XMPPStanza *stanza, XMPPClient *client)
|
||||
{
|
||||
printf("\n--> Auth callback fired\n");
|
||||
XMPPClient *client = (XMPPClient*)userdata;
|
||||
XMPPStanza *query = stanza_get_child_by_ns(stanza, "jabber:iq:auth");
|
||||
XMPPStanza *username = stanza_get_child_by_name(query, "username");
|
||||
XMPPStanza *password = stanza_get_child_by_name(query, "password");
|
||||
XMPPStanza *resource = stanza_get_child_by_name(query, "resource");
|
||||
|
||||
client->username = strdup(username->content->str);
|
||||
client->password = strdup(password->content->str);
|
||||
client->resource = strdup(resource->content->str);
|
||||
|
||||
send_to(client, AUTH_RESP);
|
||||
printf("RECV: ");
|
||||
}
|
||||
|
||||
@@ -91,3 +91,27 @@ stanza_get_child_by_ns(XMPPStanza *stanza, char *ns)
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
XMPPStanza*
|
||||
stanza_get_child_by_name(XMPPStanza *stanza, char *name)
|
||||
{
|
||||
if (!stanza) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (!stanza->children) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
GList *curr_child = stanza->children;
|
||||
while (curr_child) {
|
||||
XMPPStanza *child = curr_child->data;
|
||||
if (g_strcmp0(child->name, name) == 0) {
|
||||
return child;
|
||||
}
|
||||
|
||||
curr_child = g_list_next(curr_child);
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -19,5 +19,6 @@ void stanza_show_all(void);
|
||||
void stanza_add(XMPPStanza *stanza);
|
||||
void stanza_add_child(XMPPStanza *parent, XMPPStanza *child);
|
||||
XMPPStanza* stanza_get_child_by_ns(XMPPStanza *stanza, char *ns);
|
||||
XMPPStanza* stanza_get_child_by_name(XMPPStanza *stanza, char *name);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -16,7 +16,9 @@ xmppclient_new(struct sockaddr_in client_addr, int socket)
|
||||
client->ip = strdup(inet_ntoa(client_addr.sin_addr));
|
||||
client->port = ntohs(client_addr.sin_port);
|
||||
client->sock = socket;
|
||||
client->nickname = NULL;
|
||||
client->username = NULL;
|
||||
client->password = NULL;
|
||||
client->resource = NULL;
|
||||
|
||||
return client;
|
||||
}
|
||||
@@ -29,6 +31,8 @@ xmppclient_end_session(XMPPClient *client)
|
||||
close(client->sock);
|
||||
|
||||
free(client->ip);
|
||||
free(client->nickname);
|
||||
free(client->username);
|
||||
free(client->password);
|
||||
free(client->resource);
|
||||
free(client);
|
||||
}
|
||||
|
||||
@@ -7,7 +7,9 @@ typedef struct xmpp_client_t {
|
||||
char *ip;
|
||||
int port;
|
||||
int sock;
|
||||
char *nickname;
|
||||
char *username;
|
||||
char *password;
|
||||
char *resource;
|
||||
} XMPPClient;
|
||||
|
||||
XMPPClient* xmppclient_new(struct sockaddr_in client_addr, int socket);
|
||||
|
||||
Reference in New Issue
Block a user