imapext-2007

view src/osdep/wce/env_wce.c @ 0:ada5e610ab86

imap-2007e
author yuuji@gentei.org
date Mon, 14 Sep 2009 15:17:45 +0900
parents
children
line source
1 /* ========================================================================
2 * Copyright 1988-2006 University of Washington
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 *
11 * ========================================================================
12 */
14 /*
15 * Program: WCE environment routines
16 *
17 * Author: Mark Crispin
18 * Networks and Distributed Computing
19 * Computing & Communications
20 * University of Washington
21 * Administration Building, AG-44
22 * Seattle, WA 98195
23 * Internet: MRC@CAC.Washington.EDU
24 *
25 * Date: 1 August 1988
26 * Last Edited: 30 August 2006
27 */
30 static char *myUserName = NIL; /* user name */
31 static char *myLocalHost = NIL; /* local host name */
32 static char *myClientHost = NIL;/* client host name */
33 static char *myServerHost = NIL;/* server host name */
34 static char *myHomeDir = NIL; /* home directory name */
35 static char *myNewsrc = NIL; /* newsrc file name */
36 static char *sysInbox = NIL; /* system inbox name */
37 static long list_max_level = 5; /* maximum level of list recursion */
38 static short no822tztext = NIL; /* disable RFC [2]822 timezone text */
39 /* home namespace */
40 static NAMESPACE nshome = {"",'\\',NIL,NIL};
41 /* namespace list */
42 static NAMESPACE *nslist[3] = {&nshome,NIL,NIL};
43 static long alarm_countdown = 0;/* alarm count down */
44 static void (*alarm_rang) (); /* alarm interrupt function */
45 static unsigned int rndm = 0; /* initial `random' number */
48 /* Dummy definitions to prevent errors */
50 #define server_login(user,pass,authuser,argc,argv) NIL
51 #define authserver_login(user,authuser,argc,argv) NIL
52 #define myusername() ""
53 #define MD5ENABLE "\\.nosuch.."
55 #include "pmatch.c" /* include wildcard pattern matcher */
57 /* Environment manipulate parameters
58 * Accepts: function code
59 * function-dependent value
60 * Returns: function-dependent return value
61 */
63 void *env_parameters (long function,void *value)
64 {
65 void *ret = NIL;
66 switch ((int) function) {
67 case GET_NAMESPACE:
68 ret = (void *) nslist;
69 break;
70 case SET_HOMEDIR:
71 myHomeDir = cpystr ((char *) value);
72 case GET_HOMEDIR:
73 ret = (void *) myHomeDir;
74 break;
75 case SET_LOCALHOST:
76 myLocalHost = cpystr ((char *) value);
77 case GET_LOCALHOST:
78 ret = (void *) myLocalHost;
79 break;
80 case SET_NEWSRC:
81 if (myNewsrc) fs_give ((void **) &myNewsrc);
82 myNewsrc = cpystr ((char *) value);
83 case GET_NEWSRC:
84 if (!myNewsrc) { /* set news file name if not defined */
85 char tmp[MAILTMPLEN];
86 sprintf (tmp,"%s\\NEWSRC",myhomedir ());
87 myNewsrc = cpystr (tmp);
88 }
89 ret = (void *) myNewsrc;
90 break;
91 case SET_SYSINBOX:
92 if (sysInbox) fs_give ((void **) &sysInbox);
93 sysInbox = cpystr ((char *) value);
94 case GET_SYSINBOX:
95 ret = (void *) sysInbox;
96 break;
97 case SET_LISTMAXLEVEL:
98 list_max_level = (long) value;
99 case GET_LISTMAXLEVEL:
100 ret = (void *) list_max_level;
101 break;
102 case SET_DISABLE822TZTEXT:
103 no822tztext = value ? T : NIL;
104 case GET_DISABLE822TZTEXT:
105 ret = (void *) (no822tztext ? VOIDT : NIL);
106 break;
107 }
108 return ret;
109 }
111 /* Write current time
112 * Accepts: destination string
113 * optional format of day-of-week prefix
114 * format of date and time
115 * flag whether to append symbolic timezone
116 */
118 static void do_date (char *date,char *prefix,char *fmt,int suffix)
119 {
120 time_t tn = time (0);
121 struct tm *t = gmtime (&tn);
122 int zone = t->tm_hour * 60 + t->tm_min;
123 int julian = t->tm_yday;
124 t = localtime (&tn); /* get local time now */
125 /* minus UTC minutes since midnight */
126 zone = t->tm_hour * 60 + t->tm_min - zone;
127 /* julian can be one of:
128 * 36x local time is December 31, UTC is January 1, offset -24 hours
129 * 1 local time is 1 day ahead of UTC, offset +24 hours
130 * 0 local time is same day as UTC, no offset
131 * -1 local time is 1 day behind UTC, offset -24 hours
132 * -36x local time is January 1, UTC is December 31, offset +24 hours
133 */
134 if (julian = t->tm_yday -julian)
135 zone += ((julian < 0) == (abs (julian) == 1)) ? -24*60 : 24*60;
136 if (prefix) { /* want day of week? */
137 sprintf (date,prefix,days[t->tm_wday]);
138 date += strlen (date); /* make next sprintf append */
139 }
140 /* output the date */
141 sprintf (date,fmt,t->tm_mday,months[t->tm_mon],t->tm_year+1900,
142 t->tm_hour,t->tm_min,t->tm_sec,zone/60,abs (zone) % 60);
143 if (suffix) { /* append timezone suffix if desired */
144 char *tz;
145 tzset (); /* get timezone from TZ environment stuff */
146 tz = tzname[daylight ? (((struct tm *) t)->tm_isdst > 0) : 0];
147 if (tz && tz[0]) sprintf (date + strlen (date)," (%s)",tz);
148 }
149 }
152 /* Write current time in RFC 822 format
153 * Accepts: destination string
154 */
156 void rfc822_date (char *date)
157 {
158 do_date (date,"%s, ","%d %s %d %02d:%02d:%02d %+03d%02d",
159 no822tztext ? NIL : T);
160 }
163 /* Write current time in internal format
164 * Accepts: destination string
165 */
167 void internal_date (char *date)
168 {
169 do_date (date,NIL,"%02d-%s-%d %02d:%02d:%02d %+03d%02d",NIL);
170 }
172 /* Return random number
173 */
175 long random ()
176 {
177 if (!rndm) srand (rndm = (unsigned) time (0L));
178 return (long) rand ();
179 }
181 /* Return default drive
182 * Returns: default drive
183 */
185 static char *defaultDrive (void)
186 {
187 char *s;
188 return ((s = getenv ("SystemDrive")) && *s) ? s : "C:";
189 }
192 /* Return home drive from environment variables
193 * Returns: home drive
194 */
196 static char *homeDrive (void)
197 {
198 char *s;
199 return ((s = getenv ("HOMEDRIVE")) && *s) ? s : defaultDrive ();
200 }
203 /* Return home path from environment variables
204 * Accepts: path to write into
205 * Returns: home path or NIL if it can't be determined
206 */
208 static char *homePath (char *path)
209 {
210 int i;
211 char *s;
212 if (!((s = getenv ("HOMEPATH")) && (i = strlen (s)))) return NIL;
213 if (((s[i-1] == '\\') || (s[i-1] == '/'))) s[i-1] = '\0';
214 sprintf (path,"%s%s",homeDrive (),s);
215 return path;
216 }
218 /* Return my home directory name
219 * Returns: my home directory name
220 */
222 char *myhomedir ()
223 {
224 char tmp[MAILTMPLEN];
225 /* initialize if first time */
226 if (!myHomeDir) myHomeDir = homePath (tmp);
227 return myHomeDir ? myHomeDir : homeDrive ();
228 }
230 /* Return system standard INBOX
231 * Accepts: buffer string
232 */
234 char *sysinbox ()
235 {
236 char tmp[MAILTMPLEN];
237 if (!sysInbox) { /* initialize if first time */
238 sprintf (tmp,"%s\\INBOX",myhomedir ());
239 sysInbox = cpystr (tmp); /* system inbox is from mail spool */
240 }
241 return sysInbox;
242 }
245 /* Return mailbox file name
246 * Accepts: destination buffer
247 * mailbox name
248 * Returns: file name
249 */
251 char *mailboxfile (char *dst,char *name)
252 {
253 char *dir = myhomedir ();
254 *dst = '\0'; /* default to empty string */
255 if (((name[0] == 'I') || (name[0] == 'i')) &&
256 ((name[1] == 'N') || (name[1] == 'n')) &&
257 ((name[2] == 'B') || (name[2] == 'b')) &&
258 ((name[3] == 'O') || (name[3] == 'o')) &&
259 ((name[4] == 'X') || (name[4] == 'x')) && !name[5]) name = NIL;
260 /* reject namespace names or names with / */
261 if (name && ((*name == '#') || strchr (name,'/'))) return NIL;
262 else if (!name) return dst; /* driver selects the INBOX name */
263 /* absolute path name? */
264 else if ((*name == '\\') || (name[1] == ':')) return strcpy (dst,name);
265 /* build resulting name */
266 sprintf (dst,"%s\\%s",dir,name);
267 return dst; /* return it */
268 }
271 /* Determine default prototype stream to user
272 * Accepts: type (NIL for create, T for append)
273 * Returns: default prototype stream
274 */
276 MAILSTREAM *default_proto (long type)
277 {
278 extern MAILSTREAM CREATEPROTO,APPENDPROTO;
279 return type ? &APPENDPROTO : &CREATEPROTO;
280 }
282 /* Emulator for BSD syslog() routine
283 * Accepts: priority
284 * message
285 * parameters
286 */
288 void syslog (int priority,const char *message,...)
289 {
290 }
293 /* Emulator for BSD openlog() routine
294 * Accepts: identity
295 * options
296 * facility
297 */
299 void openlog (const char *ident,int logopt,int facility)
300 {
301 }

UW-IMAP'd extensions by yuuji