libxdas_sessions.c
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00039 #include <xdasd.h>
00040
00041 #include "libxdas_impl.h"
00042
00043 #include <stdlib.h>
00044 #include <stdio.h>
00045 #include <time.h>
00046
00047 #ifdef _WIN32
00048 # define WIN32_LEAN_AND_MEAN
00049 # include <windows.h>
00050 #endif
00051
00065 xdas_session * xdas_validate_session(xdas_audit_ref_t das_ref)
00066 {
00067 xdas_session * xs = (xdas_session *)das_ref;
00068 return (xs && xs->signature == XDAS_SESSION_SIG)? xs: 0;
00069 }
00070
00077 void xdas_set_session_rights(xdas_session * xs)
00078 {
00079
00080 xs->security = XDAS_AUDIT_SERVICE | XDAS_AUDIT_SUBMIT
00081 | XDAS_AUDIT_IMPORT | XDAS_AUDIT_CONTROL | XDAS_AUDIT_READ;
00082
00083
00084
00085
00086
00087
00088
00089
00090 }
00091
00102 int xdas_session_has_rights(xdas_session * xs, unsigned rights)
00103 {
00104 return (xs->security & rights) == rights? 1: 0;
00105 }
00106
00107 #ifdef _WIN32
00108
00126 static const char * xdas_abbreviate_win32_tzname(const wchar_t * tzstr,
00127 char * buf, size_t bufsz)
00128 {
00129 wchar_t outbuf[32];
00130 wchar_t * p = outbuf;
00131
00132 *p++ = *tzstr++;
00133 while (*tzstr)
00134 {
00135 while (*tzstr && *tzstr != L' ')
00136 tzstr++;
00137 if (*tzstr)
00138 *p++ = *++tzstr;
00139 }
00140 *p = 0;
00141 wcstombs(buf, outbuf, bufsz);
00142 return buf;
00143 }
00144
00145 #endif
00146
00159 static void escape_str(char * dst, const char * src)
00160 {
00161 do
00162 {
00163 if (*src == ':' || *src == '%')
00164 *dst++ = '%';
00165 *dst++ = *src++;
00166 } while (*src);
00167 }
00168
00190 int xdas_set_time_info(xdas_session * xs)
00191 {
00192 char tztmp[sizeof xs->time_zone] = "";
00193
00194
00195
00196
00197
00198 #ifdef _WIN32
00199
00200 HKEY key;
00201 DWORD tzschema;
00202 TIME_ZONE_INFORMATION tzi;
00203
00204
00205 *xs->time_source = 0;
00206 if (RegOpenKeyA(HKEY_LOCAL_MACHINE,
00207 "SYSTEM\\CurrentControlSet\\Services\\w32time\\Parameters",
00208 &key) == ERROR_SUCCESS)
00209 {
00210 char * p;
00211 DWORD dwBufSz = (DWORD)sizeof(xs->time_source);
00212 RegQueryValueExA(key, "NtpServer", 0, 0, (LPBYTE)xs->time_source, &dwBufSz);
00213 RegCloseKey(key);
00214 if ((p = strchr(xs->time_source, ',')) != 0)
00215 *p = 0;
00216 }
00217
00218
00219 tzschema = GetTimeZoneInformation(&tzi);
00220 if (tzschema != TIME_ZONE_ID_INVALID)
00221 {
00222 char stz[32];
00223 LONG bias = tzi.Bias + tzi.StandardBias;
00224 int ccnt = sprintf(tztmp, "%s%ld",
00225 xdas_abbreviate_win32_tzname(tzi.StandardName, stz, sizeof(stz)),
00226 bias / 60);
00227 if (bias % 60)
00228 ccnt += sprintf(tztmp + ccnt, "%%:%ld", bias % 60);
00229
00230 if (tzschema != TIME_ZONE_ID_UNKNOWN)
00231 sprintf(tztmp + ccnt, "%s",
00232 xdas_abbreviate_win32_tzname(tzi.DaylightName, stz, sizeof(stz)));
00233 }
00234
00235 #else
00236
00239
00240 int ccnt = sprintf(tztmp, "%s%ld", tzname[0], timezone / 3600);
00241 if (timezone % 3600)
00242 ccnt += sprintf(tztmp + ccnt, "%%:%ld", timezone % 3600 / 60);
00243 if (*tzname[1])
00244 sprintf(tztmp + ccnt, "%s", tzname[1]);
00245
00246 #endif
00247
00248 escape_str(xs->time_zone, tztmp);
00249
00251 xs->time_uncert_int = 0;
00252 xs->time_uncert_ind = 0;
00253
00254 return 0;
00255 }
00256
00263 void xdas_internal_terminate_session(xdas_session * xs)
00264 {
00265 xdas_service_disconnect(xs);
00266 xdas_buffer_free(xs->req);
00267 xdas_buffer_free(xs->rsp);
00268 free(xs->org_info[0]);
00269 free(xs);
00270 }
00271