Annotation of libwww/Library/src/HTUser.c, revision 2.2

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

Webmaster