Changeset 7369
- Timestamp:
- 02/19/07 20:39:57 (23 months ago)
- Files:
-
- 1 modified
-
trunk/dot/proxy/off.c (modified) (10 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/dot/proxy/off.c
r7368 r7369 69 69 70 70 int 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 } 72 104 } 73 105 … … 77 109 78 110 int 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 */ 79 127 return 0; 80 128 } … … 93 141 offlineFile->string); 94 142 do_log(L_ERROR, message); 95 return 0; 143 return 0; /* failure */ 96 144 } 97 145 … … 101 149 sprintf(message, "Unable to open offline list file, errno: %d", errno); 102 150 do_log(L_ERROR, message); 103 return 0; 151 return 0; /* failure */ 104 152 } 105 153 … … 116 164 fclose(file_ptr); 117 165 118 return 1; 166 return 1; /* success */ 119 167 } 120 168 … … 136 184 offlineFile->string); 137 185 do_log(L_INFO, message); 138 return 1; 186 return 1; /* success */ 139 187 } 140 188 … … 144 192 offlineFile->string); 145 193 do_log(L_ERROR, message); 146 return 0; 194 return 0; /* failure */ 147 195 } 148 196 … … 152 200 sprintf(message, "Unable to open offline list file, errno: %d", errno); 153 201 do_log(L_ERROR, message); 154 return 0; 202 return 0; /* failure */ 155 203 } 156 204 … … 175 223 new_entry_ptr = (struct offline_list_entry *) 176 224 malloc(sizeof(struct offline_list_entry)); 225 if(new_entry_ptr == NULL){ 226 do_log(L_ERROR, "No memory"); 227 return 0; /* failure */ 228 } 177 229 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 } 178 234 memcpy(new_entry_ptr->host_ptr, line, strlen(line) + 1); 179 235 new_entry_ptr->next_ptr = NULL; … … 193 249 fclose(file_ptr); 194 250 195 return 1; 251 return 1; /* success */ 196 252 } 197 253