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

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.4     ! frystyk     6: **     @(#) $Id: HTUser.c,v 2.3 1996/07/02 22:55:16 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.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: 
2.3       frystyk    50:        /* Set the context */
                     51:        me->context = context;
                     52:     }
                     53:     return me;
                     54: }
                     55: 
                     56: /*
                     57: **     Localize a user profile by filling in all the information that we
                     58: **     can figure out automatically, for example the email address, news
                     59: **     server etc.
                     60: */
                     61: PUBLIC BOOL HTUserProfile_localize (HTUserProfile * up)
                     62: {
                     63:     if (up) {
                     64:        if (CORE_TRACE) HTTrace("User Profile Localizing %p\n", up);
                     65: 
2.1       frystyk    66:        /* Find the FQDN */
2.3       frystyk    67:        up->fqdn = HTGetHostName();
2.1       frystyk    68: 
                     69:        /* Find the user email address */
2.3       frystyk    70:        up->email = HTGetMailAddress();
2.1       frystyk    71: 
                     72:        /* Find the news server */
2.3       frystyk    73:        up->news = HTGetNewsServer();
2.1       frystyk    74: 
                     75:        /* Find the timezone offset */
2.3       frystyk    76:        up->timezone = HTGetTimeZoneOffset();
2.1       frystyk    77: 
                     78:        /* Find the default location for temporary files */
2.3       frystyk    79:        StrAllocCopy(up->tmp, HT_TMP_ROOT);
                     80:        if (*(up->tmp+strlen(up->tmp)-1) != '/')
                     81:            StrAllocCat(up->tmp, "/");
2.1       frystyk    82: 
2.3       frystyk    83:        return YES;
2.1       frystyk    84:     }
2.3       frystyk    85:     return NO;
2.1       frystyk    86: }
                     87: 
                     88: /*
                     89: **     Delete a user profile
                     90: */
                     91: PUBLIC BOOL HTUserProfile_delete (HTUserProfile * up)
                     92: {
                     93:     if (up) {
                     94:        HT_FREE(up->user);
                     95:        HT_FREE(up->fqdn);
                     96:        HT_FREE(up->email);
                     97:        HT_FREE(up->news);
                     98:        HT_FREE(up->tmp);
                     99:        HT_FREE(up);
                    100:        return YES;
                    101:     }
                    102:     return NO;
                    103: }
                    104: 
                    105: PUBLIC char * HTUserProfile_fqdn (HTUserProfile * up)
                    106: {
                    107:     return up ? up->fqdn : NULL;
                    108: }
                    109: 
                    110: PUBLIC BOOL HTUserProfile_setFqdn (HTUserProfile * up, const char * fqdn)
                    111: {
                    112:     if (up && fqdn) {
                    113:        StrAllocCopy(up->fqdn, fqdn);
                    114:        return YES;
                    115:     }
                    116:     return NO;
                    117: }
                    118: 
                    119: PUBLIC char * HTUserProfile_email (HTUserProfile * up)
                    120: {
                    121:     return up ? up->email : NULL;
                    122: }
                    123: 
                    124: PUBLIC BOOL HTUserProfile_setEmail (HTUserProfile * up, const char * email)
                    125: {
                    126:     if (up && email) {
                    127:        StrAllocCopy(up->email, email);
                    128:        return YES;
                    129:     }
                    130:     return NO;
                    131: }
                    132: 
                    133: PUBLIC char * HTUserProfile_news (HTUserProfile * up)
                    134: {
                    135:     return up ? up->news : NULL;
                    136: }
                    137: 
                    138: PUBLIC BOOL HTUserProfile_setNews (HTUserProfile * up, const char * news)
                    139: {
                    140:     if (up && news) {
                    141:        StrAllocCopy(up->news, news);
                    142:        return YES;
                    143:     }
                    144:     return NO;
                    145: }
                    146: 
                    147: PUBLIC char * HTUserProfile_tmp (HTUserProfile * up)
                    148: {
                    149:     return up ? up->tmp : NULL;
                    150: }
                    151: 
                    152: PUBLIC BOOL HTUserProfile_setTmp (HTUserProfile * up, const char * tmp)
                    153: {
                    154:     if (up && tmp) {
                    155:        StrAllocCopy(up->tmp, tmp);
2.2       frystyk   156:        if (*(up->tmp+strlen(up->tmp)-1) != '/')
                    157:            StrAllocCat(up->tmp, "/");
2.1       frystyk   158:        return YES;
                    159:     }
                    160:     return NO;
                    161: }
                    162: 
                    163: PUBLIC time_t HTUserProfile_timezone (HTUserProfile * up)
                    164: {
                    165:     return up ? up->timezone : 0;
                    166: }
                    167: 
                    168: PUBLIC BOOL HTUserProfile_setTimezone (HTUserProfile * up, time_t timezone)
                    169: {
                    170:     if (up) {
                    171:        up->timezone = timezone;
                    172:        return YES;
                    173:     }
                    174:     return NO;
                    175: }
                    176: 
                    177: PUBLIC void * HTUserProfile_context (HTUserProfile * up)
                    178: {
                    179:     return up ? up->context : NULL;
                    180: }
                    181: 
                    182: PUBLIC BOOL HTUserProfile_setContext (HTUserProfile * up, void * context)
                    183: {
                    184:     if (up) {
                    185:        up->context = context;
                    186:        return YES;
                    187:     }
                    188:     return NO;
                    189: }
                    190: 

Webmaster