Changeset 7369

Show
Ignore:
Timestamp:
02/19/07 20:39:57 (23 months ago)
Author:
BradNeuberg
Message:

Implementing C-based offline cache

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/dot/proxy/off.c

    r7368 r7369  
    6969 
    7070int addOfflineHost(char host[]){ 
    71         return 0; 
     71        struct offline_list_entry *entry_ptr; 
     72         
     73        if(isHostAvailableOffline(host) == 1){ 
     74                /* already registered to be available offline */ 
     75                return 1; /* success */ 
     76        } 
     77         
     78        /* instantiate an entry for this host */ 
     79        entry_ptr = (struct offline_list_entry *) 
     80                                        malloc(sizeof(struct offline_list_entry)); 
     81        if(entry_ptr == NULL){ 
     82                do_log(L_ERROR, "No memory"); 
     83                return 0; 
     84        } 
     85        entry_ptr->host_ptr = (char *)malloc((unsigned) (strlen(host) + 1)); 
     86        if(entry_ptr->host_ptr == NULL){ 
     87                do_log(L_ERROR, "No memory"); 
     88                return 0; 
     89        } 
     90        memcpy(entry_ptr->host_ptr, host, strlen(host) + 1); 
     91        entry_ptr->next_ptr = NULL; 
     92         
     93        /* add it in the right place */ 
     94        if(offline_list_ptr == NULL){ 
     95                offline_list_ptr = entry_ptr; 
     96        }else{ 
     97                /* shuffle along the list until we get to the end */ 
     98                entry_ptr = offline_list_ptr; 
     99                while(entry_ptr->next_ptr != NULL){ 
     100                        entry_ptr = entry_ptr->next_ptr; 
     101                } 
     102                entry_ptr->next_ptr = entry_ptr; 
     103        } 
    72104} 
    73105 
     
    77109 
    78110int isHostAvailableOffline(char host[]){ 
     111        struct offline_list_entry *entry_ptr; 
     112         
     113        if(host == NULL){ 
     114                return 0; /* not available offline */ 
     115        } 
     116         
     117        entry_ptr = offline_list_ptr; 
     118        while(entry_ptr != NULL){ 
     119                if(strcmp(entry_ptr->host_ptr, host) == 0){ 
     120                        return 1; /* the host is available offline */ 
     121                } 
     122                 
     123                entry_ptr = entry_ptr->next_ptr; 
     124        } 
     125         
     126        /* host not available offlne */ 
    79127        return 0; 
    80128} 
     
    93141                                offlineFile->string); 
    94142                do_log(L_ERROR, message); 
    95                 return 0; 
     143                return 0; /* failure */ 
    96144    } 
    97145 
     
    101149                sprintf(message, "Unable to open offline list file, errno: %d", errno); 
    102150                do_log(L_ERROR, message); 
    103                 return 0; 
     151                return 0; /* failure */ 
    104152        } 
    105153 
     
    116164        fclose(file_ptr); 
    117165         
    118         return 1; 
     166        return 1; /* success */ 
    119167} 
    120168 
     
    136184                                offlineFile->string); 
    137185                do_log(L_INFO, message); 
    138                 return 1; 
     186                return 1; /* success */ 
    139187        } 
    140188         
     
    144192                                offlineFile->string); 
    145193                do_log(L_ERROR, message); 
    146                 return 0; 
     194                return 0; /* failure */ 
    147195    } 
    148196 
     
    152200                sprintf(message, "Unable to open offline list file, errno: %d", errno); 
    153201                do_log(L_ERROR, message); 
    154                 return 0; 
     202                return 0; /* failure */ 
    155203        } 
    156204         
     
    175223                new_entry_ptr = (struct offline_list_entry *) 
    176224                                                malloc(sizeof(struct offline_list_entry)); 
     225                if(new_entry_ptr == NULL){ 
     226                        do_log(L_ERROR, "No memory"); 
     227                        return 0; /* failure */ 
     228                } 
    177229                new_entry_ptr->host_ptr = (char *)malloc((unsigned) (strlen(line) + 1)); 
     230                if(new_entry_ptr->host_ptr == NULL){ 
     231                        do_log(L_ERROR, "No memory"); 
     232                        return 0; /* failure */ 
     233                } 
    178234                memcpy(new_entry_ptr->host_ptr, line, strlen(line) + 1); 
    179235                new_entry_ptr->next_ptr = NULL; 
     
    193249        fclose(file_ptr); 
    194250         
    195         return 1; 
     251        return 1; /* success */ 
    196252} 
    197253