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

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.6     ! frystyk     6: **     @(#) $Id: HTUser.c,v 2.5 1999/02/22 22:10:12 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 */
2.4       frystyk    14: #include "wwwsys.h"
2.1       frystyk    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.6     ! frystyk    21: #ifdef WWW_MSWINDOWS
        !            22: #define HT_TMP_ROOT            "C:\\Temp\\"
        !            23: #else
        !            24: #define HT_TMP_ROOT            "/tmp/"
        !            25: #endif /* WWW_MSWINDOWS */
2.1       frystyk    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: */
                     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: 
2.5       frystyk    51:        HTTRACE(CORE_TRACE, "User Profile Adding `%s\'\n" _ name);
2.1       frystyk    52:        StrAllocCopy(me->user, name);
                     53: 
2.3       frystyk    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: */
                     65: PUBLIC BOOL HTUserProfile_localize (HTUserProfile * up)
                     66: {
                     67:     if (up) {
2.5       frystyk    68:        HTTRACE(CORE_TRACE, "User Profile Localizing %p\n" _ up);
2.3       frystyk    69: 
2.1       frystyk    70:        /* Find the FQDN */
2.3       frystyk    71:        up->fqdn = HTGetHostName();
2.1       frystyk    72: 
                     73:        /* Find the user email address */
2.3       frystyk    74:        up->email = HTGetMailAddress();
2.1       frystyk    75: 
                     76:        /* Find the news server */
2.3       frystyk    77:        up->news = HTGetNewsServer();
2.1       frystyk    78: 
                     79:        /* Find the timezone offset */
2.3       frystyk    80:        up->timezone = HTGetTimeZoneOffset();
2.1       frystyk    81: 
                     82:        /* Find the default location for temporary files */
2.3       frystyk    83:        StrAllocCopy(up->tmp, HT_TMP_ROOT);
2.6     ! frystyk    84:        if (*(up->tmp+strlen(up->tmp)-1) != DIR_SEPARATOR_CHAR)
        !            85:            StrAllocCat(up->tmp, DIR_SEPARATOR_STR);
2.1       frystyk    86: 
2.3       frystyk    87:        return YES;
2.1       frystyk    88:     }
2.3       frystyk    89:     return NO;
2.1       frystyk    90: }
                     91: 
                     92: /*
                     93: **     Delete a user profile
                     94: */
                     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: 
                    109: PUBLIC char * HTUserProfile_fqdn (HTUserProfile * up)
                    110: {
                    111:     return up ? up->fqdn : NULL;
                    112: }
                    113: 
                    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: 
                    123: PUBLIC char * HTUserProfile_email (HTUserProfile * up)
                    124: {
                    125:     return up ? up->email : NULL;
                    126: }
                    127: 
                    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: 
                    137: PUBLIC char * HTUserProfile_news (HTUserProfile * up)
                    138: {
                    139:     return up ? up->news : NULL;
                    140: }
                    141: 
                    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: 
                    151: PUBLIC char * HTUserProfile_tmp (HTUserProfile * up)
                    152: {
                    153:     return up ? up->tmp : NULL;
                    154: }
                    155: 
                    156: PUBLIC BOOL HTUserProfile_setTmp (HTUserProfile * up, const char * tmp)
                    157: {
                    158:     if (up && tmp) {
                    159:        StrAllocCopy(up->tmp, tmp);
2.6     ! frystyk   160:        if (*(up->tmp+strlen(up->tmp)-1) != DIR_SEPARATOR_CHAR)
        !           161:            StrAllocCat(up->tmp, DIR_SEPARATOR_STR);
2.1       frystyk   162:        return YES;
                    163:     }
                    164:     return NO;
                    165: }
                    166: 
                    167: PUBLIC time_t HTUserProfile_timezone (HTUserProfile * up)
                    168: {
                    169:     return up ? up->timezone : 0;
                    170: }
                    171: 
                    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: 
                    181: PUBLIC void * HTUserProfile_context (HTUserProfile * up)
                    182: {
                    183:     return up ? up->context : NULL;
                    184: }
                    185: 
                    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: 

Webmaster