update.c (925B)
1 /* update.c - fetch remote hosts file entries to update counter 2 * 3 * headers and macros */ 4 #define MAX_ENTRIES 100 5 6 #include <stdio.h> 7 #include <stdlib.h> 8 #include <string.h> 9 10 #include "get.h" 11 #include "update.h" 12 #include "hfc.h" 13 14 15 int 16 count_hosts_in_content(const char *content) 17 { 18 const char *line, *next; 19 size_t len; 20 int count = 0; 21 char buffer[512], *cr; 22 23 if (!content) 24 return 0; 25 26 line = content; 27 while (*line) { 28 next = strchr(line, '\n'); 29 len = next ? (size_t)(next - line) : strlen(line); 30 if (len >= sizeof(buffer)) 31 len = sizeof(buffer) - 1; 32 33 memcpy(buffer, line, len); 34 buffer[len] = '\0'; 35 36 cr = strchr(buffer, '\r'); 37 if (cr) 38 *cr = '\0'; 39 40 while (*buffer == ' ' || *buffer == '\t') 41 memmove(buffer, buffer + 1, strlen(buffer)); 42 43 if (strncmp(buffer, "0.0.0.0 ", 8) == 0 || strncmp(buffer, "127.0.0.1 ", 10) == 0) 44 count++; 45 46 if (!next) 47 break; 48 line = next + 1; 49 } 50 51 return count; 52 }