1 /*
2 **	USER PROFILE
3 **
4 **	(c) COPYRIGHT MIT 1995.
5 **	Please first read the full copyright statement in the file COPYRIGH.
6 **	@(#) $Id$
7 **
8 **	Contains information about local host, email, etc.
9 **
10 **	May 96  HFN	Written
11 */
12 
13 /* Library include files */
14 #include "wwwsys.h"
15 #include "WWWUtil.h"
16 #include "HTInet.h"
17 #include "HTUser.h"					 /* Implemented here */
18 
19 /* The default directory for "save locally" and "save and execute" files: */
20 #ifndef HT_TMP_ROOT
21 #ifdef WWW_MSWINDOWS
22 #define HT_TMP_ROOT		"C:\\Temp\\"
23 #else
24 #define HT_TMP_ROOT		"/tmp/"
25 #endif /* WWW_MSWINDOWS */
26 #endif
27 
28 struct _HTUserProfile {
29     char *	user;
30     char * 	fqdn;			      /* Fully qualified domain name */
31     char * 	email;			    /* Email address of current user */
32     char * 	news;				   /* The news server to use */
33     char *	tmp;			     /* Location for temporary files */
34     time_t	timezone;			     /* Time zone in seconds */
35     void *	context;			     /* Application specific */
36 };
37 
38 /* ------------------------------------------------------------------------- */
39 
40 /*
41 **	Create a new host profile object and initialize it with what we can
42 **	find on this host.
43 */
HTUserProfile_new(const char * name,void * context)44 PUBLIC HTUserProfile * HTUserProfile_new (const char * name, void * context)
45 {
46     HTUserProfile * me = NULL;
47     if (name) {
48 	if ((me = (HTUserProfile *) HT_CALLOC(1, sizeof(HTUserProfile)))==NULL)
49 	    HT_OUTOFMEM("HTUserProfile_new");
50 
51 	HTTRACE(CORE_TRACE, "User Profile Adding `%s\'\n" _ name);
52 	StrAllocCopy(me->user, name);
53 
54 	/* Set the context */
55 	me->context = context;
56     }
57     return me;
58 }
59 
60 /*
61 **	Localize a user profile by filling in all the information that we
62 **	can figure out automatically, for example the email address, news
63 **	server etc.
64 */
HTUserProfile_localize(HTUserProfile * up)65 PUBLIC BOOL HTUserProfile_localize (HTUserProfile * up)
66 {
67     if (up) {
68 	HTTRACE(CORE_TRACE, "User Profile Localizing %p\n" _ up);
69 
70 	/* Find the FQDN */
71 	up->fqdn = HTGetHostName();
72 
73 	/* Find the user email address */
74 	up->email = HTGetMailAddress();
75 
76 	/* Find the news server */
77 	up->news = HTGetNewsServer();
78 
79 	/* Find the timezone offset */
80 	up->timezone = HTGetTimeZoneOffset();
81 
82 	/* Find the default location for temporary files */
83 	StrAllocCopy(up->tmp, HT_TMP_ROOT);
84 	if (*(up->tmp+strlen(up->tmp)-1) != DIR_SEPARATOR_CHAR)
85 	    StrAllocCat(up->tmp, DIR_SEPARATOR_STR);
86 
87 	return YES;
88     }
89     return NO;
90 }
91 
92 /*
93 **	Delete a user profile
94 */
HTUserProfile_delete(HTUserProfile * up)95 PUBLIC BOOL HTUserProfile_delete (HTUserProfile * up)
96 {
97     if (up) {
98 	HT_FREE(up->user);
99 	HT_FREE(up->fqdn);
100 	HT_FREE(up->email);
101 	HT_FREE(up->news);
102 	HT_FREE(up->tmp);
103 	HT_FREE(up);
104 	return YES;
105     }
106     return NO;
107 }
108 
HTUserProfile_fqdn(HTUserProfile * up)109 PUBLIC char * HTUserProfile_fqdn (HTUserProfile * up)
110 {
111     return up ? up->fqdn : NULL;
112 }
113 
HTUserProfile_setFqdn(HTUserProfile * up,const char * fqdn)114 PUBLIC BOOL HTUserProfile_setFqdn (HTUserProfile * up, const char * fqdn)
115 {
116     if (up && fqdn) {
117 	StrAllocCopy(up->fqdn, fqdn);
118 	return YES;
119     }
120     return NO;
121 }
122 
HTUserProfile_email(HTUserProfile * up)123 PUBLIC char * HTUserProfile_email (HTUserProfile * up)
124 {
125     return up ? up->email : NULL;
126 }
127 
HTUserProfile_setEmail(HTUserProfile * up,const char * email)128 PUBLIC BOOL HTUserProfile_setEmail (HTUserProfile * up, const char * email)
129 {
130     if (up && email) {
131 	StrAllocCopy(up->email, email);
132 	return YES;
133     }
134     return NO;
135 }
136 
HTUserProfile_news(HTUserProfile * up)137 PUBLIC char * HTUserProfile_news (HTUserProfile * up)
138 {
139     return up ? up->news : NULL;
140 }
141 
HTUserProfile_setNews(HTUserProfile * up,const char * news)142 PUBLIC BOOL HTUserProfile_setNews (HTUserProfile * up, const char * news)
143 {
144     if (up && news) {
145 	StrAllocCopy(up->news, news);
146 	return YES;
147     }
148     return NO;
149 }
150 
HTUserProfile_tmp(HTUserProfile * up)151 PUBLIC char * HTUserProfile_tmp (HTUserProfile * up)
152 {
153     return up ? up->tmp : NULL;
154 }
155 
HTUserProfile_setTmp(HTUserProfile * up,const char * tmp)156 PUBLIC BOOL HTUserProfile_setTmp (HTUserProfile * up, const char * tmp)
157 {
158     if (up && tmp) {
159 	StrAllocCopy(up->tmp, tmp);
160 	if (*(up->tmp+strlen(up->tmp)-1) != DIR_SEPARATOR_CHAR)
161 	    StrAllocCat(up->tmp, DIR_SEPARATOR_STR);
162 	return YES;
163     }
164     return NO;
165 }
166 
HTUserProfile_timezone(HTUserProfile * up)167 PUBLIC time_t HTUserProfile_timezone (HTUserProfile * up)
168 {
169     return up ? up->timezone : 0;
170 }
171 
HTUserProfile_setTimezone(HTUserProfile * up,time_t timezone)172 PUBLIC BOOL HTUserProfile_setTimezone (HTUserProfile * up, time_t timezone)
173 {
174     if (up) {
175 	up->timezone = timezone;
176 	return YES;
177     }
178     return NO;
179 }
180 
HTUserProfile_context(HTUserProfile * up)181 PUBLIC void * HTUserProfile_context (HTUserProfile * up)
182 {
183     return up ? up->context : NULL;
184 }
185 
HTUserProfile_setContext(HTUserProfile * up,void * context)186 PUBLIC BOOL HTUserProfile_setContext (HTUserProfile * up, void * context)
187 {
188     if (up) {
189 	up->context = context;
190 	return YES;
191     }
192     return NO;
193 }
194 
195