jabberd2
2.2.17
Main Page
Data Structures
Files
File List
Globals
sm
mod_iq_time.c
Go to the documentation of this file.
1
/*
2
* jabberd - Jabber Open Source Server
3
* Copyright (c) 2002 Jeremie Miller, Thomas Muldowney,
4
* Ryan Eatmon, Robert Norris
5
*
6
* This program is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation; either version 2 of the License, or
9
* (at your option) any later version.
10
*
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the
14
* GNU General Public License for more details.
15
*
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA02111-1307USA
19
*/
20
21
#include "
sm.h
"
22
30
#ifdef ENABLE_SUPERSEDED
31
static
int
ns_TIME = 0;
32
#endif
33
static
int
ns_URN_TIME
= 0;
34
35
#ifdef HAVE_TZNAME
36
extern
char
*tzname[];
37
#endif
38
39
static
mod_ret_t
_iq_time_pkt_sm
(
mod_instance_t
mi,
pkt_t
pkt)
40
{
41
time_t t;
42
struct
tm *tm;
43
char
buf[64];
44
char
*c;
45
46
/* we only want to play with iq:time gets */
47
#ifdef ENABLE_SUPERSEDED
48
if
(pkt->
type
!=
pkt_IQ
|| (pkt->
ns
!= ns_TIME && pkt->
ns
!=
ns_URN_TIME
))
49
#else
50
if
(pkt->
type
!=
pkt_IQ
|| pkt->
ns
!=
ns_URN_TIME
)
51
#endif
52
return
mod_PASS
;
53
54
t = time(NULL);
55
tm = localtime(&t);
56
#ifdef HAVE_TZSET
57
tzset();
58
#endif
59
60
#ifdef ENABLE_SUPERSEDED
61
if
(pkt->
ns
== ns_TIME) {
62
datetime_out
(t,
dt_LEGACY
, buf, 64);
63
nad_insert_elem
(pkt->
nad
, 2,
NAD_ENS
(pkt->
nad
, 1),
"utc"
, buf);
64
65
strcpy(buf, asctime(tm));
66
c = strchr(buf,
'\n'
);
67
if
(c != NULL)
68
*c =
'\0'
;
69
nad_insert_elem
(pkt->
nad
, 2,
NAD_ENS
(pkt->
nad
, 1),
"display"
, buf);
70
#if defined(HAVE_STRUCT_TM_TM_ZONE)
71
nad_insert_elem
(pkt->
nad
, 2,
NAD_ENS
(pkt->
nad
, 1),
"tz"
, (
char
*) tm->tm_zone);
72
#elif defined(HAVE_TZNAME)
73
nad_insert_elem
(pkt->
nad
, 2,
NAD_ENS
(pkt->
nad
, 1),
"tz"
, tzname[0]);
74
#endif
75
}
else
{
76
#endif
/* ENABLE_SUPERSEDED */
77
78
datetime_out
(t,
dt_DATETIME
, buf, 64);
79
nad_insert_elem
(pkt->
nad
, 2,
NAD_ENS
(pkt->
nad
, 1),
"utc"
, buf);
80
#ifdef HAVE_TZSET
81
snprintf(buf, 64,
"%+03d:%02d"
, -((
int
)timezone)/(60*60), -((
int
)timezone)%(60*60));
82
#else
83
snprintf(buf, 64,
"%+03d:%02d"
, (
int
) tm->tm_gmtoff/(60*60), (
int
) tm->tm_gmtoff%(60*60));
84
#endif
85
nad_insert_elem
(pkt->
nad
, 2,
NAD_ENS
(pkt->
nad
, 1),
"tzo"
, buf);
86
87
#ifdef ENABLE_SUPERSEDED
88
}
89
#endif
90
/* tell them */
91
nad_set_attr
(pkt->
nad
, 1, -1,
"type"
,
"result"
, 6);
92
pkt_router
(
pkt_tofrom
(pkt));
93
94
return
mod_HANDLED
;
95
}
96
97
static
void
_iq_time_free
(
module_t
mod) {
98
sm_unregister_ns
(mod->
mm
->
sm
,
uri_TIME
);
99
feature_unregister
(mod->
mm
->
sm
,
uri_TIME
);
100
}
101
102
DLLEXPORT
int
module_init
(
mod_instance_t
mi,
char
*arg) {
103
module_t
mod = mi->
mod
;
104
105
if
(mod->
init
)
return
0;
106
107
mod->
pkt_sm
=
_iq_time_pkt_sm
;
108
mod->
free
=
_iq_time_free
;
109
110
#ifdef ENABLE_SUPERSEDED
111
ns_TIME =
sm_register_ns
(mod->
mm
->
sm
,
uri_TIME
);
112
feature_register
(mod->
mm
->
sm
,
uri_TIME
);
113
#endif
114
ns_URN_TIME
=
sm_register_ns
(mod->
mm
->
sm
,
urn_TIME
);
115
feature_register
(mod->
mm
->
sm
,
urn_TIME
);
116
117
return
0;
118
}
Generated by
1.8.1.1