common.c (b43155852682c9e38509571f4a29699cdc35c950) | common.c (38c7e4a631ce968b02e4a08944aabad9b57844e8) |
---|---|
1/*- 2 * Copyright (c) 1998 Dag-Erling Co�dan Sm�rgrav 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 46 unchanged lines hidden (view full) --- 55 { EAI_NODATA, FETCH_RESOLV, "Host not found" }, 56 { EAI_AGAIN, FETCH_TEMP, "Transient resolver failure" }, 57 { EAI_FAIL, FETCH_RESOLV, "Non-recoverable resolver failure" }, 58 { EAI_NONAME, FETCH_RESOLV, "No address record" }, 59 { -1, FETCH_UNKNOWN, "Unknown resolver error" } 60}; 61 62/* End-of-Line */ | 1/*- 2 * Copyright (c) 1998 Dag-Erling Co�dan Sm�rgrav 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 46 unchanged lines hidden (view full) --- 55 { EAI_NODATA, FETCH_RESOLV, "Host not found" }, 56 { EAI_AGAIN, FETCH_TEMP, "Transient resolver failure" }, 57 { EAI_FAIL, FETCH_RESOLV, "Non-recoverable resolver failure" }, 58 { EAI_NONAME, FETCH_RESOLV, "No address record" }, 59 { -1, FETCH_UNKNOWN, "Unknown resolver error" } 60}; 61 62/* End-of-Line */ |
63static char ENDL[2] = "\r\n"; | 63static const char ENDL[2] = "\r\n"; |
64 65 66/*** Error-reporting functions ***********************************************/ 67 68/* 69 * Map error code to string 70 */ 71static struct fetcherr * --- 77 unchanged lines hidden (view full) --- 149 snprintf(fetchLastErrString, MAXERRSTRING, "%s", strerror(e)); 150} 151 152 153/* 154 * Emit status message 155 */ 156void | 64 65 66/*** Error-reporting functions ***********************************************/ 67 68/* 69 * Map error code to string 70 */ 71static struct fetcherr * --- 77 unchanged lines hidden (view full) --- 149 snprintf(fetchLastErrString, MAXERRSTRING, "%s", strerror(e)); 150} 151 152 153/* 154 * Emit status message 155 */ 156void |
157_fetch_info(char *fmt, ...) | 157_fetch_info(const char *fmt, ...) |
158{ 159 va_list ap; 160 161 va_start(ap, fmt); 162 vfprintf(stderr, fmt, ap); 163 va_end(ap); 164 fputc('\n', stderr); 165} 166 167 168/*** Network-related utility functions ***************************************/ 169 170/* 171 * Return the default port for a scheme 172 */ 173int | 158{ 159 va_list ap; 160 161 va_start(ap, fmt); 162 vfprintf(stderr, fmt, ap); 163 va_end(ap); 164 fputc('\n', stderr); 165} 166 167 168/*** Network-related utility functions ***************************************/ 169 170/* 171 * Return the default port for a scheme 172 */ 173int |
174_fetch_default_port(char *scheme) | 174_fetch_default_port(const char *scheme) |
175{ 176 struct servent *se; 177 178 if ((se = getservbyname(scheme, "tcp")) != NULL) 179 return ntohs(se->s_port); 180 if (strcasecmp(scheme, SCHEME_FTP) == 0) 181 return FTP_DEFAULT_PORT; 182 if (strcasecmp(scheme, SCHEME_HTTP) == 0) 183 return HTTP_DEFAULT_PORT; 184 return 0; 185} 186 187/* 188 * Return the default proxy port for a scheme 189 */ 190int | 175{ 176 struct servent *se; 177 178 if ((se = getservbyname(scheme, "tcp")) != NULL) 179 return ntohs(se->s_port); 180 if (strcasecmp(scheme, SCHEME_FTP) == 0) 181 return FTP_DEFAULT_PORT; 182 if (strcasecmp(scheme, SCHEME_HTTP) == 0) 183 return HTTP_DEFAULT_PORT; 184 return 0; 185} 186 187/* 188 * Return the default proxy port for a scheme 189 */ 190int |
191_fetch_default_proxy_port(char *scheme) | 191_fetch_default_proxy_port(const char *scheme) |
192{ 193 if (strcasecmp(scheme, SCHEME_FTP) == 0) 194 return FTP_DEFAULT_PROXY_PORT; 195 if (strcasecmp(scheme, SCHEME_HTTP) == 0) 196 return HTTP_DEFAULT_PROXY_PORT; 197 return 0; 198} 199 200/* 201 * Establish a TCP connection to the specified port on the specified host. 202 */ 203int | 192{ 193 if (strcasecmp(scheme, SCHEME_FTP) == 0) 194 return FTP_DEFAULT_PROXY_PORT; 195 if (strcasecmp(scheme, SCHEME_HTTP) == 0) 196 return HTTP_DEFAULT_PROXY_PORT; 197 return 0; 198} 199 200/* 201 * Establish a TCP connection to the specified port on the specified host. 202 */ 203int |
204_fetch_connect(char *host, int port, int af, int verbose) | 204_fetch_connect(const char *host, int port, int af, int verbose) |
205{ 206 char pbuf[10]; 207 struct addrinfo hints, *res, *res0; 208 int sd, err; 209 210 DEBUG(fprintf(stderr, "\033[1m---> %s:%d\033[m\n", host, port)); 211 212 if (verbose) --- 115 unchanged lines hidden (view full) --- 328} 329 330 331/* 332 * Write a line of text to a socket w/ timeout 333 * XXX currently does not enforce timeout 334 */ 335int | 205{ 206 char pbuf[10]; 207 struct addrinfo hints, *res, *res0; 208 int sd, err; 209 210 DEBUG(fprintf(stderr, "\033[1m---> %s:%d\033[m\n", host, port)); 211 212 if (verbose) --- 115 unchanged lines hidden (view full) --- 328} 329 330 331/* 332 * Write a line of text to a socket w/ timeout 333 * XXX currently does not enforce timeout 334 */ 335int |
336_fetch_putln(int fd, char *str, size_t len) | 336_fetch_putln(int fd, const char *str, size_t len) |
337{ 338 struct iovec iov[2]; 339 ssize_t wlen; 340 341 /* XXX should enforce timeout */ | 337{ 338 struct iovec iov[2]; 339 ssize_t wlen; 340 341 /* XXX should enforce timeout */ |
342 iov[0].iov_base = str; | 342 iov[0].iov_base = (char *)str; |
343 iov[0].iov_len = len; | 343 iov[0].iov_len = len; |
344 iov[1].iov_base = ENDL; | 344 iov[1].iov_base = (char *)ENDL; |
345 iov[1].iov_len = sizeof ENDL; 346 wlen = writev(fd, iov, 2); 347 DEBUG(fprintf(stderr, "\033[1m>>> %s\n\033[m", str)); 348 return (wlen != len); 349} 350 351 352/*** Directory-related utility functions *************************************/ 353 354int 355_fetch_add_entry(struct url_ent **p, int *size, int *len, | 345 iov[1].iov_len = sizeof ENDL; 346 wlen = writev(fd, iov, 2); 347 DEBUG(fprintf(stderr, "\033[1m>>> %s\n\033[m", str)); 348 return (wlen != len); 349} 350 351 352/*** Directory-related utility functions *************************************/ 353 354int 355_fetch_add_entry(struct url_ent **p, int *size, int *len, |
356 char *name, struct url_stat *stat) | 356 const char *name, struct url_stat *stat) |
357{ 358 struct url_ent *tmp; 359 360 if (*p == NULL) { 361#define INITIAL_SIZE 8 362 if ((*p = malloc(INITIAL_SIZE * sizeof **p)) == NULL) { 363 errno = ENOMEM; 364 _fetch_syserr(); --- 27 unchanged lines hidden --- | 357{ 358 struct url_ent *tmp; 359 360 if (*p == NULL) { 361#define INITIAL_SIZE 8 362 if ((*p = malloc(INITIAL_SIZE * sizeof **p)) == NULL) { 363 errno = ENOMEM; 364 _fetch_syserr(); --- 27 unchanged lines hidden --- |