1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
|
/*
* Ostatnia aktualizacja:
*
* - $Id: groupchat.c,v 1.7 2003/04/04 19:14:20 mati Exp $
*
*/
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <time.h>
#include "libtlen.h"
/*
* tlen_groupchat_create()
*
* Tworzy konferencj
*
* - sesja - nasza sesja
*
*/
int tlen_groupchat_create(struct tlen_session *sesja)
{
char *query;
char *malloc_sample = "<presence to=\"@conf\"/><iq to=\"@conf\" type=\"set\" id=\"groupchatregister\"><query xmlns=\"jabber:iq:conference\"><nick></nick><secret></secret></query></iq>";
int second = tlen_get_second();
if (!(query = (char *) malloc (strlen(malloc_sample) + strlen(sesja->username) + 10 /*sek1*/ + strlen(sesja->username) + 10 /*sek2*/ + strlen(sesja->username) + 10 /*secret*/)))
{
perror("malloc");
sesja->error = TLEN_ERROR_MALLOC;
}
sprintf (query, "<presence to='%s%d@conf'/><iq to='%s%d@conf' type='set' id='groupchatregister'><query xmlns='jabber:iq:conference'><nick>%s</nick><secret>%d</secret></query></iq>", sesja->username, second, sesja->username, second, sesja->username, second /*I mean - secret, but it can be second too :>*/);
tlen_debug("Create conference query sent\n");
tlen_socket_write_string (sesja, query);
free(query);
return 1;
}
/*
* tlen_get_second()
*
* Zwraca sekund danego dnia
*
* - brak parametrw
*
* Potrzebna przy zapytaniach konferencyjnych
*
*/
int tlen_get_second()
{
int sec;
time_t t;
struct tm *tm;
t = time(NULL);
tm = localtime(&t);
sec = tm->tm_sec + (tm->tm_min*60) + ((tm->tm_hour*60)*60);
return sec;
}
|