]> granicus.if.org Git - apache/commitdiff
Remove all of the calls to functions like "ap_popenf". These functions were
authorRyan Bloom <rbb@apache.org>
Wed, 8 Sep 1999 14:15:55 +0000 (14:15 +0000)
committerRyan Bloom <rbb@apache.org>
Wed, 8 Sep 1999 14:15:55 +0000 (14:15 +0000)
moved down to APR, but they are being removed.  They are not portable, and
were only moved down for backwards compatability.  With this change, they can
be safely removed, which is the next commit on it's way.
Submitted by:  Ryan Bloom and Paul Reder

git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@83879 13f79535-47bb-0310-9956-ffa450edef68

21 files changed:
include/ap_config.h
include/ap_listen.h
include/http_log.h
include/http_protocol.h
include/httpd.h
include/util_md5.h
modules/generators/mod_asis.c
modules/generators/mod_autoindex.c
modules/http/http_core.c
modules/http/http_protocol.c
modules/loggers/mod_log_config.c
modules/mappers/mod_negotiation.c
server/config.c
server/listen.c
server/log.c
server/mpm/mpmt_pthread/mpmt_pthread.c
server/mpm/prefork/prefork.c
server/rfc1413.c
server/util.c
server/util_md5.c
server/util_script.c

index 811b7d4e78d0bdff5081ec3ef6311973eb9b8fb9..20bd133ca7e57a3385becac4231101c97eef2d23 100644 (file)
@@ -1206,12 +1206,6 @@ int ap_select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, st
        select(_a, _b, _c, _d, _e)
 #endif
 
-#ifdef USE_TPF_ACCEPT
-#define ap_accept(_fd, _sa, _ln)       tpf_accept(_fd, _sa, _ln)
-#else
-#define ap_accept(_fd, _sa, _ln)       accept(_fd, _sa, _ln)
-#endif
-
 #ifdef NEED_SIGNAL_INTERRUPT
 #define ap_check_signals()     tpf_process_signals()
 #else
index 1d8433335fd0842cdaaeaa11a80e91338a75e014..ab3fe43700c05dd51e4e5c845a6ad638462713c4 100644 (file)
 #ifndef AP_LISTEN_H
 #define AP_LISTEN_H
 
+#include "apr_network_io.h"
+
 typedef struct ap_listen_rec ap_listen_rec;
 struct ap_listen_rec {
     ap_listen_rec *next;
-    struct sockaddr_in local_addr;     /* local IP address and port */
-/* TODO: replace the fd with APR stuff */
-    int fd;
+    ap_socket_t *sd;
 /* more stuff here, like which protocol is bound to the port */
 };
 
index 2044463efff9173f04cf11d33c4910cbca0c7bf8..61abeab01677c71b13af40c55e4c004d068835e7 100644 (file)
@@ -139,9 +139,9 @@ typedef struct piped_log {
 #ifndef NO_RELIABLE_PIPED_LOGS
     char *program;
     int pid;
-    int fds[2];
+    ap_file_t fds[2];
 #else
-    FILE *write_f;
+    ap_file_t *write_f;
 #endif
 } piped_log;
 
@@ -152,7 +152,7 @@ API_EXPORT(void) ap_close_piped_log (piped_log *);
 #define ap_piped_log_write_fd(pl)      ((pl)->fds[1])
 #else
 #define ap_piped_log_read_fd(pl)       (-1)
-#define ap_piped_log_write_fd(pl)      (fileno((pl)->write_f))
+#define ap_piped_log_write_fd(pl)      ((pl)->write_f)
 #endif
 
 #ifdef __cplusplus
index 4fefb8be7c664b88c160906086048a86ab9a635a..908326ce7b03bb60bab48bb1dd1eb9149a3f4822 100644 (file)
@@ -59,6 +59,7 @@
 #define APACHE_HTTP_PROTOCOL_H
 
 #include "ap_hooks.h"
+#include "apr_portable.h"
 
 #ifdef __cplusplus
 extern "C" {
@@ -133,8 +134,8 @@ API_EXPORT(int) ap_meets_conditions(request_rec *r);
  * (Ditto the send_header stuff).
  */
 
-API_EXPORT(long) ap_send_fd(APRFile fd, request_rec *r);
-API_EXPORT(long) ap_send_fd_length(APRFile fd, request_rec *r, long length);
+API_EXPORT(long) ap_send_fd(int fd, request_rec *r);
+API_EXPORT(long) ap_send_fd_length(int fd, request_rec *r, long length);
 
 API_EXPORT(long) ap_send_fb(BUFF *f, request_rec *r);
 API_EXPORT(long) ap_send_fb_length(BUFF *f, request_rec *r, long length);
index 2440913691dce722800a4620b0b7ef6da00ea584..6ec8b340db5e08abe4912efe9adfc9c8370289a4 100644 (file)
@@ -859,7 +859,7 @@ struct server_rec {
     /* Log files --- note that transfer log is now in the modules... */
 
     char *error_fname;
-    FILE *error_log;
+    ap_file_t *error_log;
     int loglevel;
 
     /* Module-specific configuration for server, and defaults... */
index 14e960522a5f95f8a01864598f9fe431eafef822..c5a5e654d775d1fe43469f74602fe15008143d5d 100644 (file)
@@ -68,9 +68,9 @@ API_EXPORT(char *) ap_md5(ap_context_t *a, const unsigned char *string);
 API_EXPORT(char *) ap_md5_binary(ap_context_t *a, const unsigned char *buf, int len);
 API_EXPORT(char *) ap_md5contextTo64(ap_context_t *p, AP_MD5_CTX * context);
 #ifdef CHARSET_EBCDIC
-API_EXPORT(char *) ap_md5digest(ap_context_t *p, FILE *infile, int convert);
+API_EXPORT(char *) ap_md5digest(ap_context_t *p, int infile, int convert);
 #else
-API_EXPORT(char *) ap_md5digest(ap_context_t *p, APRFile infile);
+API_EXPORT(char *) ap_md5digest(ap_context_t *p, int infile);
 #endif /* CHARSET_EBCDIC */
 
 #ifdef __cplusplus
index bd23d1720d536a2d7cceb1f9fcdd70c13347158b..a6bf897e23db1db67c051ba131c4b53bc09fd3b0 100644 (file)
 
 static int asis_handler(request_rec *r)
 {
-    FILE *f;
+    ap_file_t *f;
     const char *location;
+    FILE *thefile;         /* XXX leave these alone until we convert */
+    int thefd;             /* everything to use apr_file_t's. */ 
 
     r->allowed |= (1 << M_GET);
     if (r->method_number != M_GET)
@@ -77,21 +79,23 @@ static int asis_handler(request_rec *r)
        return NOT_FOUND;
     }
 
-    f = ap_pfopen(r->pool, r->filename, "r");
-
-    if (f == NULL) {
+    if (ap_open(r->pool, r->filename, APR_READ | APR_BUFFERED, 
+                APR_OS_DEFAULT, &f) != APR_SUCCESS) {
        ap_log_rerror(APLOG_MARK, APLOG_ERR, r,
                    "file permissions deny server access: %s", r->filename);
        return FORBIDDEN;
     }
 
-    ap_scan_script_header_err(r, f, NULL);
+    ap_get_os_file(f, &thefd); 
+    thefile = fdopen(thefd, "r");
+    
+    ap_scan_script_header_err(r, thefile, NULL);
     location = ap_table_get(r->headers_out, "Location");
 
     if (location && location[0] == '/' &&
        ((r->status == HTTP_OK) || ap_is_HTTP_REDIRECT(r->status))) {
 
-       ap_pfclose(r->pool, f);
+       ap_close(f);
 
        /* Internal redirect -- fake-up a pseudo-request */
        r->status = HTTP_OK;
@@ -108,11 +112,12 @@ static int asis_handler(request_rec *r)
 
     ap_send_http_header(r);
     if (!r->header_only) {
-       fseek(f, 0, SEEK_CUR);
-       ap_send_fd(fileno(f), r);
+        ap_off_t zero = 0;
+       ap_seek(f, APR_CUR, &zero);
+       ap_send_fd(thefd, r);
     }
 
-    ap_pfclose(r->pool, f);
+    ap_close(f);
     return OK;
 }
 
index a874079c311bd6bc844196dd9d928258f22c6bb4..cdf47e1ed11fbfb4ae1e485d67a86ad49aa332b2 100644 (file)
@@ -884,17 +884,19 @@ static int ignore_entry(autoindex_config_rec *d, char *path)
 /*
  * emit a plain text file
  */
-static void do_emit_plain(request_rec *r, FILE *f)
+static void do_emit_plain(request_rec *r, ap_file_t *f)
 {
     char buf[IOBUFSIZE + 1];
     int i, n, c, ch;
+    ap_status_t stat;
 
     ap_rputs("<PRE>\n", r);
-    while (!feof(f)) {
+    while (!ap_eof(f)) {
        do {
-           n = fread(buf, sizeof(char), IOBUFSIZE, f);
+            n = sizeof(char) * IOBUFSIZE;
+           stat = ap_read(f, buf, &n);
        }
-       while (n == -1 && ferror(f) && errno == EINTR);
+       while (stat != APR_SUCCESS && stat == EINTR);
        if (n == -1 || n == 0) {
            break;
        }
@@ -936,7 +938,7 @@ static void do_emit_plain(request_rec *r, FILE *f)
 static void emit_head(request_rec *r, char *header_fname, int suppress_amble,
                      char *title)
 {
-    FILE *f;
+    ap_file_t *f;
     request_rec *rr = NULL;
     int emit_amble = 1;
     int emit_H1 = 1;
@@ -984,11 +986,12 @@ static void emit_head(request_rec *r, char *header_fname, int suppress_amble,
                 * the file's contents, any HTML header it had won't end up
                 * where it belongs.
                 */
-               if ((f = ap_pfopen(r->pool, rr->filename, "r")) != 0) {
+               if (ap_open(r->pool, rr->filename, APR_READ | APR_BUFFERED,
+                            APR_OS_DEFAULT, &f) == APR_SUCCESS) {
                    emit_preamble(r, title);
                    emit_amble = 0;
                    do_emit_plain(r, f);
-                   ap_pfclose(r->pool, f);
+                   ap_close(f);
                    emit_H1 = 0;
                }
            }
@@ -1018,7 +1021,7 @@ static void emit_head(request_rec *r, char *header_fname, int suppress_amble,
  */
 static void emit_tail(request_rec *r, char *readme_fname, int suppress_amble)
 {
-    FILE *f;
+    ap_file_t *f;
     request_rec *rr = NULL;
     int suppress_post = 0;
     int suppress_sig = 0;
@@ -1051,9 +1054,10 @@ static void emit_tail(request_rec *r, char *readme_fname, int suppress_amble)
                /*
                 * If we can open the file, suppress the signature.
                 */
-               if ((f = ap_pfopen(r->pool, rr->filename, "r")) != 0) {
+               if (ap_open(r->pool, rr->filename, APR_READ | APR_BUFFERED,
+                            APR_OS_DEFAULT, &f) == APR_SUCCESS) {
                    do_emit_plain(r, f);
-                   ap_pfclose(r->pool, f);
+                   ap_close(f);
                    suppress_sig = 1;
                }
            }
@@ -1075,7 +1079,7 @@ static void emit_tail(request_rec *r, char *readme_fname, int suppress_amble)
 static char *find_title(request_rec *r)
 {
     char titlebuf[MAX_STRING_LEN], *find = "<TITLE>";
-    FILE *thefile = NULL;
+    ap_file_t *thefile = NULL;
     int x, y, n, p;
 
     if (r->status != HTTP_OK) {
@@ -1086,12 +1090,14 @@ static char *find_title(request_rec *r)
                        "text/html")
            || !strcmp(r->content_type, INCLUDES_MAGIC_TYPE))
        && !r->content_encoding) {
-        if (!(thefile = ap_pfopen(r->pool, r->filename, "r"))) {
+        if (ap_open(r->pool, r->filename, APR_READ | APR_BUFFERED,
+                    APR_OS_DEFAULT, &thefile) != APR_SUCCESS) {
            return NULL;
        }
-       n = fread(titlebuf, sizeof(char), MAX_STRING_LEN - 1, thefile);
+        n = sizeof(char) * (MAX_STRING_LEN - 1);
+       ap_read(thefile, titlebuf, &n);
        if (n <= 0) {
-           ap_pfclose(r->pool, thefile);
+           ap_close(thefile);
            return NULL;
        }
        titlebuf[n] = '\0';
@@ -1112,7 +1118,7 @@ static char *find_title(request_rec *r)
                            }
                        }
                    }
-                   ap_pfclose(r->pool, thefile);
+                   ap_close(thefile);
                    return ap_pstrdup(r->pool, &titlebuf[x]);
                }
            }
@@ -1120,7 +1126,7 @@ static char *find_title(request_rec *r)
                p = 0;
            }
        }
-       ap_pfclose(r->pool, thefile);
+       ap_close(thefile);
     }
     return NULL;
 }
@@ -1498,8 +1504,7 @@ static int index_directory(request_rec *r,
     char *title_endp;
     char *name = r->filename;
 
-    DIR *d;
-    struct DIR_TYPE *dstruct;
+    ap_dir_t *d;
     int num_ent = 0, x;
     struct ent *head, *p;
     struct ent **ar = NULL;
@@ -1508,7 +1513,7 @@ static int index_directory(request_rec *r,
     char keyid;
     char direction;
 
-    if (!(d = ap_popendir(r->pool, name))) {
+    if (ap_opendir(r->pool, name, &d) != APR_SUCCESS) {
        ap_log_rerror(APLOG_MARK, APLOG_ERR, r,
                    "Can't open directory for index: %s", r->filename);
        return HTTP_FORBIDDEN;
@@ -1519,7 +1524,7 @@ static int index_directory(request_rec *r,
     ap_send_http_header(r);
 
     if (r->header_only) {
-       ap_pclosedir(r->pool, d);
+       ap_closedir(d);
        return 0;
     }
 
@@ -1571,8 +1576,10 @@ static int index_directory(request_rec *r,
      * linked list and then arrayificate them so qsort can use them. 
      */
     head = NULL;
-    while ((dstruct = readdir(d))) {
-       p = make_autoindex_entry(dstruct->d_name, autoindex_opts,
+    while (ap_readdir(d)) {
+        char *d_name;
+        ap_get_dir_filename(d, &d_name);
+       p = make_autoindex_entry(d_name, autoindex_opts,
                                 autoindex_conf, r, keyid, direction);
        if (p != NULL) {
            p->next = head;
@@ -1595,7 +1602,7 @@ static int index_directory(request_rec *r,
     }
     output_directories(ar, num_ent, autoindex_conf, r, autoindex_opts, keyid,
                       direction);
-    ap_pclosedir(r->pool, d);
+    ap_closedir(d);
 
     if (autoindex_opts & FANCY_INDEXING) {
        ap_rputs("<HR>\n", r);
index 96b437e8dea2138e3415569ab95152087764e007..02debf7c32023a117312ca70acd8260741c4cf6d 100644 (file)
@@ -2472,9 +2472,10 @@ static ap_status_t mmap_cleanup(void *mmv)
 static int default_handler(request_rec *r)
 {
     core_dir_config *d =
-      (core_dir_config *)ap_get_module_config(r->per_dir_config, &core_module);
+           (core_dir_config *)ap_get_module_config(r->per_dir_config, &core_module);
     int rangestatus, errstatus;
-    APRFile fd;         /*  Abstract out File descriptors. */
+    ap_file_t *fd = NULL;
+    int fd_os;
 #ifdef USE_MMAP_FILES
     caddr_t mm;
 #endif
@@ -2514,18 +2515,13 @@ static int default_handler(request_rec *r)
         return METHOD_NOT_ALLOWED;
     }
        
-#if defined(OS2) || defined(WIN32)
-    /* Need binary mode for OS/2 */
-    fd = ap_popenf(r->pool, r->filename, O_RDONLY | O_BINARY, 0);
-#else
-    fd = ap_popenf(r->pool, r->filename, O_RDONLY, 0);
-#endif
-
-    if (fd == -1) {
+    if (ap_open (r->pool, r->filename, APR_READ | APR_BINARY, 0, &fd) != APR_SUCCESS) {
         ap_log_rerror(APLOG_MARK, APLOG_ERR, r,
                     "file permissions deny server access: %s", r->filename);
         return FORBIDDEN;
     }
+    else
+       ap_get_os_file (fd, &fd_os);
        
     ap_update_mtime(r, r->finfo.st_mtime);
     ap_set_last_modified(r);
@@ -2533,7 +2529,7 @@ static int default_handler(request_rec *r)
     ap_table_setn(r->headers_out, "Accept-Ranges", "bytes");
     if (((errstatus = ap_meets_conditions(r)) != OK)
        || (errstatus = ap_set_content_length(r, r->finfo.st_size))) {
-        ap_pclosef(r->pool, fd);
+        ap_close(fd);
         return errstatus;
     }
 
@@ -2544,7 +2540,7 @@ static int default_handler(request_rec *r)
        /* we need to protect ourselves in case we die while we've got the
         * file mmapped */
        mm = mmap(NULL, r->finfo.st_size, PROT_READ, MAP_PRIVATE,
-                 fd, 0);
+                 fd_os, 0);
        if (mm == (caddr_t)-1) {
            ap_log_rerror(APLOG_MARK, APLOG_CRIT, r,
                         "default_handler: mmap failed: %s", r->filename);
@@ -2568,12 +2564,12 @@ static int default_handler(request_rec *r)
        convert_flag = ap_checkconv(r);
        if (d->content_md5 & 1) {
            ap_table_setn(r->headers_out, "Content-MD5",
-                         ap_md5digest(r->pool, fd, convert_flag));
+                         ap_md5digest(r->pool, fd_os, convert_flag));
        }
 #else
        if (d->content_md5 & 1) {
            ap_table_setn(r->headers_out, "Content-MD5",
-                         ap_md5digest(r->pool, fd));
+                         ap_md5digest(r->pool, fd_os));
        }
 #endif /* CHARSET_EBCDIC */
 
@@ -2583,19 +2579,20 @@ static int default_handler(request_rec *r)
        
        if (!r->header_only) {
            if (!rangestatus) {
-               ap_send_fd(fd, r);
+               ap_send_fd(fd_os, r);
            }
            else {
-               long offset, length;
+               long     length;
+                ap_off_t offset;
+
                while (ap_each_byterange(r, &offset, &length)) {
-                   /* ZZZ change to AP func */
-                   if (lseek(fd, offset, SEEK_SET) == -1) {
+                    if (ap_seek(fd, APR_SET, &offset) != APR_SUCCESS) {
                        ap_log_error(APLOG_MARK, APLOG_ERR, r->server,
                                  "error byteserving file: %s", r->filename);
-                       ap_pclosef(r->pool, fd);
+                       ap_close(fd);
                        return HTTP_INTERNAL_SERVER_ERROR;
                    }
-                   ap_send_fd_length(fd, r, length);
+                   ap_send_fd_length(fd_os, r, length);
                }
            }
        }
@@ -2636,7 +2633,7 @@ static int default_handler(request_rec *r)
     }
 #endif
 
-    ap_pclosef(r->pool, fd);
+    ap_close(fd);
     return OK;
 }
 
index d2036a0c1664df4abb6b08f6607de11ae411e453..b642a96542d30adf3ba1c75e51a338829c855bb5 100644 (file)
@@ -1997,12 +1997,12 @@ API_EXPORT(int) ap_discard_request_body(request_rec *r)
 /*
  * Send the body of a response to the client.
  */
-API_EXPORT(long) ap_send_fd(APRFile fd, request_rec *r)
+API_EXPORT(long) ap_send_fd(int fd, request_rec *r)
 {
     return ap_send_fd_length(fd, r, -1);
 }
 
-API_EXPORT(long) ap_send_fd_length(APRFile fd, request_rec *r, long length)
+API_EXPORT(long) ap_send_fd_length(int fd, request_rec *r, long length)
 {
     char buf[IOBUFSIZE];
     long total_bytes_sent = 0;
index 2f1acb0a94e81fc55861aa66728d0d70047e045f..90025db60fd7d6916d4b2bfcba59b951a434b0e6 100644 (file)
 
 module MODULE_VAR_EXPORT config_log_module;
 
-static int xfer_flags = (O_WRONLY | O_APPEND | O_CREAT);
+static int xfer_flags = (APR_WRITE | APR_APPEND | APR_CREATE);
 #if defined(OS2) || defined(WIN32)
 /* OS/2 dosen't support users and groups */
 static mode_t xfer_mode = (S_IREAD | S_IWRITE);
 #else
-static mode_t xfer_mode = (S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
+static mode_t xfer_mode = (APR_UREAD | APR_UWRITE | APR_GREAD | APR_WREAD);
 #endif
 
 /* POSIX.1 defines PIPE_BUF as the maximum number of bytes that is
@@ -229,7 +229,7 @@ typedef struct {
  * be NULL, which means this module does no logging for this
  * request. format might be NULL, in which case the default_format
  * from the multi_log_state should be used, or if that is NULL as
- * well, use the CLF. log_fd is -1 before the log file is opened and
+ * well, use the CLF. log_fd is NULL before the log file is opened and
  * set to a valid fd after it is opened.
  */
 
@@ -237,7 +237,7 @@ typedef struct {
     char *fname;
     char *format_string;
     ap_array_header_t *format;
-    int log_fd;
+    ap_file_t *log_fd;
     char *condition_var;
 #ifdef BUFFERED_LOGS
     int outcnt;
@@ -723,8 +723,8 @@ static const char *process_item(request_rec *r, request_rec *orig,
 #ifdef BUFFERED_LOGS
 static void flush_log(config_log_state *cls)
 {
-    if (cls->outcnt && cls->log_fd != -1) {
-        write(cls->log_fd, cls->outbuf, cls->outcnt);
+    if (cls->outcnt && cls->log_fd != NULL) {
+        ap_write(cls->log_fd, cls->outbuf, cls->outcnt);
         cls->outcnt = 0;
     }
 }
@@ -797,7 +797,7 @@ static int config_log_transaction(request_rec *r, config_log_state *cls,
             memcpy(s, strs[i], strl[i]);
             s += strl[i];
         }
-        write(cls->log_fd, str, len);
+        ap_write(cls->log_fd, str, len);
     }
     else {
         for (i = 0, s = &cls->outbuf[cls->outcnt]; i < format->nelts; ++i) {
@@ -814,7 +814,7 @@ static int config_log_transaction(request_rec *r, config_log_state *cls,
         s += strl[i];
     }
 
-    write(cls->log_fd, str, len);
+    ap_write(cls->log_fd, str, &len);
 #endif
 
     return OK;
@@ -949,7 +949,7 @@ static const char *add_custom_log(cmd_parms *cmd, void *dummy, char *fn,
     else {
         cls->format = parse_log_string(cmd->pool, fmt, &err_string);
     }
-    cls->log_fd = -1;
+    cls->log_fd = NULL;
 
     return err_string;
 }
@@ -982,7 +982,7 @@ static config_log_state *open_config_log(server_rec *s, ap_context_t *p,
                                          config_log_state *cls,
                                          ap_array_header_t *default_format)
 {
-    if (cls->log_fd > 0) {
+    if (cls->log_fd != NULL) {
         return cls;             /* virtual config shared w/main server */
     }
 
@@ -1001,7 +1001,7 @@ static config_log_state *open_config_log(server_rec *s, ap_context_t *p,
     }
     else {
         const char *fname = ap_server_root_relative(p, cls->fname);
-        if ((cls->log_fd = ap_popenf(p, fname, xfer_flags, xfer_mode)) < 0) {
+        if (ap_open(p, fname, xfer_flags, xfer_mode, &cls->log_fd) != APR_SUCCESS) {
             ap_log_error(APLOG_MARK, APLOG_ERR, s,
                          "could not open transfer log file %s.", fname);
             exit(1);
index 71737c9b978662278d6a536b910f177842c71620..47e0319db2ee48bd2152ab4a964247ab9e22a7f4 100644 (file)
@@ -635,16 +635,16 @@ enum header_state {
     header_eof, header_seen, header_sep
 };
 
-static enum header_state get_header_line(char *buffer, int len, FILE *map)
+static enum header_state get_header_line(char *buffer, int len, ap_file_t *map)
 {
     char *buf_end = buffer + len;
     char *cp;
-    int c;
+    char c;
 
     /* Get a noncommented line */
 
     do {
-        if (fgets(buffer, MAX_STRING_LEN, map) == NULL) {
+        if (ap_gets(map, buffer, MAX_STRING_LEN) != APR_SUCCESS) {
             return header_eof;
         }
     } while (buffer[0] == '#');
@@ -665,10 +665,10 @@ static enum header_state get_header_line(char *buffer, int len, FILE *map)
 
     cp += strlen(cp);
 
-    while ((c = getc(map)) != EOF) {
+    while (ap_getc(map, &c) != APR_EOF) {
         if (c == '#') {
             /* Comment line */
-            while ((c = getc(map)) != EOF && c != '\n') {
+            while (ap_getc(map, &c) != EOF && c != '\n') {
                 continue;
             }
         }
@@ -679,10 +679,10 @@ static enum header_state get_header_line(char *buffer, int len, FILE *map)
              */
 
             while (c != EOF && c != '\n' && ap_isspace(c)) {
-                c = getc(map);
+                ap_getc(map, &c);
             }
 
-            ungetc(c, map);
+            ap_ungetc(map, c);
 
             if (c == '\n') {
                 return header_seen;     /* Blank line */
@@ -690,7 +690,7 @@ static enum header_state get_header_line(char *buffer, int len, FILE *map)
 
             /* Continuation */
 
-            while (cp < buf_end - 2 && (c = getc(map)) != EOF && c != '\n') {
+            while (cp < buf_end - 2 && (ap_getc(map, &c)) != EOF && c != '\n') {
                 *cp++ = c;
             }
 
@@ -701,7 +701,7 @@ static enum header_state get_header_line(char *buffer, int len, FILE *map)
 
             /* Line beginning with something other than whitespace */
 
-            ungetc(c, map);
+            ap_ungetc(map, c);
             return header_seen;
         }
     }
@@ -772,7 +772,7 @@ static char *lcase_header_name_return_body(char *header, request_rec *r)
 static int read_type_map(negotiation_state *neg, request_rec *rr)
 {
     request_rec *r = neg->r;
-    FILE *map;
+    ap_file_t *map;
     char buffer[MAX_STRING_LEN];
     enum header_state hstate;
     struct var_rec mime_info;
@@ -781,8 +781,8 @@ static int read_type_map(negotiation_state *neg, request_rec *rr)
     /* We are not using multiviews */
     neg->count_multiviews_variants = 0;
 
-    map = ap_pfopen(neg->pool, rr->filename, "r");
-    if (map == NULL) {
+    if (ap_open(neg->pool, rr->filename, APR_READ | APR_BUFFERED,
+                APR_OS_DEFAULT, &map) != APR_SUCCESS) {
         ap_log_rerror(APLOG_MARK, APLOG_ERR, r,
                       "cannot access type map file: %s", rr->filename);
         return HTTP_FORBIDDEN;
@@ -851,7 +851,7 @@ static int read_type_map(negotiation_state *neg, request_rec *rr)
         }
     } while (hstate != header_eof);
 
-    ap_pfclose(neg->pool, map);
+    ap_close(map);
 
     set_vlist_validator(r, rr);
 
@@ -889,8 +889,7 @@ static int read_types_multi(negotiation_state *neg)
 
     char *filp;
     int prefix_len;
-    DIR *dirp;
-    struct DIR_TYPE *dir_entry;
+    ap_dir_t *dirp;
     struct var_rec mime_info;
     struct accept_rec accept_info;
     void *new_var;
@@ -908,23 +907,23 @@ static int read_types_multi(negotiation_state *neg)
     ++filp;
     prefix_len = strlen(filp);
 
-    dirp = ap_popendir(neg->pool, neg->dir_name);
-
-    if (dirp == NULL) {
+    if (ap_opendir(neg->pool, neg->dir_name, &dirp) != APR_SUCCESS) {
         ap_log_rerror(APLOG_MARK, APLOG_ERR, r,
                     "cannot read directory for multi: %s", neg->dir_name);
         return HTTP_FORBIDDEN;
     }
 
-    while ((dir_entry = readdir(dirp))) {
+    while (ap_readdir(dirp) == APR_SUCCESS) {
         request_rec *sub_req;
+        char *d_name;
 
+        ap_get_dir_filename(dirp, &d_name);
         /* Do we have a match? */
 
-        if (strncmp(dir_entry->d_name, filp, prefix_len)) {
+        if (strncmp(d_name, filp, prefix_len)) {
             continue;
         }
-        if (dir_entry->d_name[prefix_len] != '.') {
+        if (d_name[prefix_len] != '.') {
             continue;
         }
 
@@ -933,7 +932,7 @@ static int read_types_multi(negotiation_state *neg)
          * which we'll be slapping default_type on later).
          */
 
-        sub_req = ap_sub_req_lookup_file(dir_entry->d_name, r);
+        sub_req = ap_sub_req_lookup_file(d_name, r);
 
         /* If it has a handler, we'll pretend it's a CGI script,
          * since that's a good indication of the sort of thing it
@@ -957,7 +956,7 @@ static int read_types_multi(negotiation_state *neg)
             ((sub_req->handler) &&
              !strcmp(sub_req->handler, "type-map"))) {
 
-            ap_pclosedir(neg->pool, dirp);
+            ap_closedir(dirp);
             neg->avail_vars->nelts = 0;
             if (sub_req->status != HTTP_OK) {
                 return sub_req->status;
@@ -968,7 +967,7 @@ static int read_types_multi(negotiation_state *neg)
         /* Have reasonable variant --- gather notes. */
 
         mime_info.sub_req = sub_req;
-        mime_info.file_name = ap_pstrdup(neg->pool, dir_entry->d_name);
+        mime_info.file_name = ap_pstrdup(neg->pool, d_name);
         if (sub_req->content_encoding) {
             mime_info.content_encoding = sub_req->content_encoding;
         }
@@ -987,7 +986,7 @@ static int read_types_multi(negotiation_state *neg)
         clean_var_rec(&mime_info);
     }
 
-    ap_pclosedir(neg->pool, dirp);
+    ap_closedir(dirp);
 
     set_vlist_validator(r, r);
 
index 489ae78dc3a72a9588a578e9f4f38ba608a818a9..0a4ba4f37b0e6b8060a854441ff3bcc3b2bc494f 100644 (file)
@@ -72,6 +72,7 @@
 
 #define CORE_PRIVATE
 
+#include "apr_portable.h"
 #include "httpd.h"
 #include "http_config.h"
 #include "http_core.h"
@@ -1243,13 +1244,14 @@ static void init_config_globals(ap_context_t *p)
 
 static server_rec *init_server_config(ap_context_t *p)
 {
+    int errfile = STDERR_FILENO;
     server_rec *s = (server_rec *) ap_pcalloc(p, sizeof(server_rec));
 
     s->port = 0;
     s->server_admin = DEFAULT_ADMIN;
     s->server_hostname = NULL;
     s->error_fname = DEFAULT_ERRORLOG;
-    s->error_log = stderr;
+    ap_put_os_file(p, &s->error_log, &errfile);
     s->loglevel = DEFAULT_LOGLEVEL;
     s->srm_confname = RESOURCE_CONFIG_FILE;
     s->access_confname = ACCESS_CONFIG_FILE;
index 051f708a040c8411a5b41586b432d96133ed3b6f..e151155ff30d8c845452382538ecc45b5f6e52d3 100644 (file)
@@ -55,6 +55,7 @@
  *
  */
 
+#include "apr_network_io.h"
 #include "httpd.h"
 #include "http_config.h"
 #include "ap_listen.h"
@@ -66,50 +67,28 @@ static int ap_listenbacklog;
 static int send_buffer_size;
 
 /* TODO: make_sock is just begging and screaming for APR abstraction */
-static int make_sock(const struct sockaddr_in *server)
+static ap_status_t make_sock(ap_context_t *p, ap_listen_rec *server)
 {
-    int s;
+    ap_socket_t *s = server->sd;
     int one = 1;
     char addr[512];
+    ap_status_t stat;
 
-    if (server->sin_addr.s_addr != htonl(INADDR_ANY))
-       ap_snprintf(addr, sizeof(addr), "address %s port %d",
-               inet_ntoa(server->sin_addr), ntohs(server->sin_port));
-    else
-       ap_snprintf(addr, sizeof(addr), "port %d", ntohs(server->sin_port));
-
-#ifdef WIN32
-    s = WSASocket(AF_INET, SOCK_STREAM, IPPROTO_TCP, NULL, 0, WSA_FLAG_OVERLAPPED);
-    if (s == INVALID_SOCKET) {
-       ap_log_error(APLOG_MARK, APLOG_CRIT, NULL,
-                     "make_sock: failed to get a socket for %s", addr);
-       return -1;
-    }
-#else
-    if ((s = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP)) == -1) {
-       ap_log_error(APLOG_MARK, APLOG_CRIT, NULL,
-                   "make_sock: failed to get a socket for %s", addr);
-       return -1;
-    }
-#endif
-
-#ifdef SO_REUSEADDR
-    if (setsockopt(s, SOL_SOCKET, SO_REUSEADDR, (char *) &one, sizeof(int)) < 0) {
+    stat = ap_setsocketopt(s, APR_SO_REUSEADDR, one);
+    if (stat != APR_SUCCESS && stat != APR_ENOTIMPL) {
        ap_log_error(APLOG_MARK, APLOG_CRIT, NULL,
                    "make_sock: for %s, setsockopt: (SO_REUSEADDR)", addr);
-       close(s);
-       return -1;
+       ap_close_socket(s);
+       return stat;
     }
-#endif
-    one = 1;
-#ifdef SO_KEEPALIVE
-    if (setsockopt(s, SOL_SOCKET, SO_KEEPALIVE, (char *) &one, sizeof(int)) < 0) {
+    
+    stat = ap_setsocketopt(s, APR_SO_KEEPALIVE, one);
+    if (stat != APR_SUCCESS && stat != APR_ENOTIMPL) {
        ap_log_error(APLOG_MARK, APLOG_CRIT, NULL,
                    "make_sock: for %s, setsockopt: (SO_KEEPALIVE)", addr);
-       close(s);
-       return -1;
+       ap_close_socket(s);
+       return stat;
     }
-#endif
 
     /*
      * To send data over high bandwidth-delay connections at full
@@ -130,33 +109,32 @@ static int make_sock(const struct sockaddr_in *server)
      *
      * If no size is specified, use the kernel default.
      */
-#ifdef SO_SNDBUF
     if (send_buffer_size) {
-       if (setsockopt(s, SOL_SOCKET, SO_SNDBUF,
-               (char *) &send_buffer_size, sizeof(int)) < 0) {
-           ap_log_error(APLOG_MARK, APLOG_WARNING, NULL,
+       stat = ap_setsocketopt(s, SO_SNDBUF,  send_buffer_size);
+        if (stat != APR_SUCCESS && stat != APR_ENOTIMPL) {
+            ap_log_error(APLOG_MARK, APLOG_WARNING, NULL,
                        "make_sock: failed to set SendBufferSize for %s, "
                        "using default", addr);
            /* not a fatal error */
        }
     }
-#endif
 
-    if (bind(s, (struct sockaddr *) server, sizeof(struct sockaddr_in)) == -1) {
+    if ((stat = ap_bind(s)) != APR_SUCCESS) {
        ap_log_error(APLOG_MARK, APLOG_CRIT, NULL,
            "make_sock: could not bind to %s", addr);
-       close(s);
-       return -1;
+       ap_close_socket(s);
+       return stat;
     }
 
-    if (listen(s, ap_listenbacklog) == -1) {
+    if ((stat = ap_listen(s, ap_listenbacklog)) != APR_SUCCESS) {
        ap_log_error(APLOG_MARK, APLOG_ERR, NULL,
            "make_sock: unable to listen for connections on %s", addr);
-       close(s);
-       return -1;
+       ap_close_socket(s);
+       return stat;
     }
 
-    return s;
+    server->sd = s;
+    return APR_SUCCESS;
 }
 
 
@@ -165,20 +143,24 @@ static ap_status_t close_listeners_on_exec(void *v)
     ap_listen_rec *lr;
 
     for (lr = ap_listeners; lr; lr = lr->next) {
-       close(lr->fd);
+       ap_close_socket(lr->sd);
     }
     return APR_SUCCESS;
 }
 
 
-static void alloc_listener(struct sockaddr_in *local_addr)
+static void alloc_listener(char *addr, unsigned int port)
 {
     ap_listen_rec **walk;
     ap_listen_rec *new;
+    char *oldaddr;
+    unsigned int oldport;
 
     /* see if we've got an old listener for this address:port */
     for (walk = &old_listeners; *walk; walk = &(*walk)->next) {
-       if (!memcmp(&(*walk)->local_addr, local_addr, sizeof(local_addr))) {
+        ap_getport((*walk)->sd, &oldport);
+        ap_getipaddr((*walk)->sd, &oldaddr);
+       if (!strcmp(oldaddr, addr) && port == oldport) {
            /* re-use existing record */
            new = *walk;
            *walk = new->next;
@@ -190,8 +172,13 @@ static void alloc_listener(struct sockaddr_in *local_addr)
 
     /* this has to survive restarts */
     new = malloc(sizeof(ap_listen_rec));
-    new->local_addr = *local_addr;
-    new->fd = -1;
+    if (ap_create_tcp_socket(NULL, &new->sd) != APR_SUCCESS) {
+        ap_log_error(APLOG_MARK, APLOG_CRIT, NULL,
+                 "make_sock: failed to get a socket for %s", addr);
+        return;
+    }
+    ap_setport(new->sd, port);
+    ap_setipaddr(new->sd, addr);
     new->next = ap_listeners;
     ap_listeners = new;
 }
@@ -202,31 +189,25 @@ int ap_listen_open(ap_context_t *pconf, unsigned port)
     ap_listen_rec *lr;
     ap_listen_rec *next;
     int num_open;
-    struct sockaddr_in local_addr;
-
+    ap_status_t stat;
     /* allocate a default listener if necessary */
     if (ap_listeners == NULL) {
-       local_addr.sin_family = AF_INET;
-       local_addr.sin_addr.s_addr = htonl(INADDR_ANY); /* XXX */
-       local_addr.sin_port = htons(port ? port : DEFAULT_HTTP_PORT);
-       alloc_listener(&local_addr);
+       alloc_listener(APR_ANYADDR, port ? port : DEFAULT_HTTP_PORT);
     }
 
     num_open = 0;
     for (lr = ap_listeners; lr; lr = lr->next) {
-       if (lr->fd < 0) {
-           lr->fd = make_sock(&lr->local_addr);
-       }
-       if (lr->fd >= 0) {
+       stat = make_sock(pconf, lr);
+       if (stat == APR_SUCCESS) {
            ++num_open;
        }
     }
 
     /* close the old listeners */
     for (lr = old_listeners; lr; lr = next) {
-       close(lr->fd);
+       ap_close_socket(lr->sd);
        next = lr->next;
-       free(lr);
+/*     free(lr);*/
     }
     old_listeners = NULL;
 
@@ -248,7 +229,6 @@ const char *ap_set_listener(cmd_parms *cmd, void *dummy, char *ips)
 {
     char *ports;
     unsigned short port;
-    struct sockaddr_in local_addr;
 
     const char *err = ap_check_cmd_context(cmd, GLOBAL_ONLY);
     if (err != NULL) {
@@ -269,20 +249,18 @@ const char *ap_set_listener(cmd_parms *cmd, void *dummy, char *ips)
        ports = ips;
     }
 
-    local_addr.sin_family = AF_INET;
-    if (ports == ips) { /* no address */
-       local_addr.sin_addr.s_addr = htonl(INADDR_ANY);
-    }
-    else {
-       local_addr.sin_addr.s_addr = ap_get_virthost_addr(ips, NULL);
-    }
     port = atoi(ports);
     if (!port) {
        return "Port must be numeric";
     }
-    local_addr.sin_port = htons(port);
 
-    alloc_listener(&local_addr);
+    if (ports == ips) { /* no address */
+        alloc_listener(APR_ANYADDR, port);
+    }
+    else {
+        ips[(ports - ips) - 1] = '\0';
+       alloc_listener(ips, port);
+    }
 
     return NULL;
 }
index 369d8b1b77bad454394c20e721474483c3c77a14..a2c67c0e49fa6d3632c648778a5e2f12e0b5515b 100644 (file)
@@ -65,6 +65,7 @@
 
 #define CORE_PRIVATE
 #include "apr_lib.h"
+#include "apr_portable.h"
 #include "httpd.h"
 #include "http_config.h"
 #include "http_core.h"
@@ -190,6 +191,7 @@ static void open_error_log(server_rec *s, ap_context_t *p)
 
     if (*s->error_fname == '|') {
        FILE *dummy;
+        int dummyno;
 #ifdef TPF
         TPF_FORK_CHILD cld;
         cld.filename = s->error_fname+1;
@@ -206,7 +208,8 @@ static void open_error_log(server_rec *s, ap_context_t *p)
            exit(1);
        }
 
-       s->error_log = dummy;
+        dummyno = fileno(dummy);
+       ap_put_os_file(p, &s->error_log, &dummyno);
     }
 
 #ifdef HAVE_SYSLOG
@@ -233,7 +236,8 @@ static void open_error_log(server_rec *s, ap_context_t *p)
     else {
        fname = ap_server_root_relative(p, s->error_fname);
        /*  Change to AP funcs. */
-        if (!(s->error_log = ap_pfopen(p, fname, "a"))) {
+        if (ap_open(p, fname, APR_BUFFERED | APR_APPEND | APR_READ | APR_WRITE, 
+                      APR_OS_DEFAULT, &s->error_log) != APR_SUCCESS) {
             perror("fopen");
             fprintf(stderr, "%s: could not open error log file %s.\n",
                    ap_server_argv0, fname);
@@ -246,6 +250,7 @@ void ap_open_logs(server_rec *s_main, ap_context_t *p)
 {
     server_rec *virt, *q;
     int replace_stderr;
+    int errfile;
 
     open_error_log(s_main, p);
 
@@ -253,7 +258,8 @@ void ap_open_logs(server_rec *s_main, ap_context_t *p)
     if (s_main->error_log) {
        /* replace stderr with this new log */
        fflush(stderr);
-       if (dup2(fileno(s_main->error_log), STDERR_FILENO) == -1) {
+        ap_get_os_file(s_main->error_log, &errfile);
+       if (dup2(errfile, STDERR_FILENO) == -1) {
            ap_log_error(APLOG_MARK, APLOG_CRIT, s_main,
                "unable to replace stderr with error_log");
        } else {
@@ -287,9 +293,12 @@ void ap_open_logs(server_rec *s_main, ap_context_t *p)
 }
 
 API_EXPORT(void) ap_error_log2stderr(server_rec *s) {
+    int errfile;
+
+    ap_get_os_file(s->error_log, &errfile);
     if (   s->error_log != NULL
-        && fileno(s->error_log) != STDERR_FILENO)
-        dup2(fileno(s->error_log), STDERR_FILENO);
+        && errfile != STDERR_FILENO)
+        dup2(errfile, STDERR_FILENO);
 }
 
 static void log_error_core(const char *file, int line, int level,
@@ -300,7 +309,8 @@ static void log_error_core(const char *file, int line, int level,
     size_t len;
     /* change to AP errno funcs. */
     int save_errno = errno;
-    FILE *logf;
+    ap_file_t *logf = NULL;
+    int errfileno = STDERR_FILENO;
 
     if (s == NULL) {
        /*
@@ -311,7 +321,7 @@ static void log_error_core(const char *file, int line, int level,
        if (((level & APLOG_LEVELMASK) != APLOG_NOTICE) &&
            ((level & APLOG_LEVELMASK) > DEFAULT_LOGLEVEL))
            return;
-       logf = stderr;
+       ap_put_os_file(NULL, &logf, &errfileno);
     }
     else if (s->error_log) {
        /*
@@ -448,9 +458,9 @@ static void log_error_core(const char *file, int line, int level,
     if (logf) {
       /* ZZZ let's just use AP funcs to Write to the error log.  If failure,
         can we output a message to the console??? */
-       fputs(errstr, logf);
-       fputc('\n', logf);
-       fflush(logf);
+       ap_puts(logf, errstr);
+       ap_putc(logf, '\n');
+       ap_flush(logf);
     }
 #ifdef HAVE_SYSLOG
     else {
@@ -514,11 +524,11 @@ void ap_log_pid(ap_context_t *p, const char *fname)
        *      that may screw up scripts written to do something
        *      based on the last modification time of the pid file.
        */
-      ap_log_error(APLOG_MARK, APLOG_NOERRNO|APLOG_WARNING, NULL,
-                  ap_psprintf(p,
-                              "pid file %s overwritten -- Unclean shutdown of previous Apache run?",
-                              fname)
-                  );
+        ap_log_error(APLOG_MARK, APLOG_NOERRNO|APLOG_WARNING, NULL,
+                    ap_psprintf(p,
+                                 "pid file %s overwritten -- Unclean shutdown of previous Apache run?",
+                     fname)
+                              );
     }
 
     if(!(pid_file = fopen(fname, "w"))) {
@@ -664,8 +674,8 @@ static void piped_log_cleanup(void *data)
        kill(pl->pid, SIGTERM);
     }
     ap_unregister_other_child(pl);
-    close(pl->fds[0]);
-    close(pl->fds[1]);
+    ap_close(pl->fds[0]);
+    ap_close(pl->fds[1]);
 }
 
 
@@ -673,8 +683,8 @@ static void piped_log_cleanup_for_exec(void *data)
 {
     piped_log *pl = data;
 
-    close(pl->fds[0]);
-    close(pl->fds[1]);
+    ap_close(pl->fds[0]);
+    ap_close(pl->fds[1]);
 }
 
 
@@ -686,7 +696,7 @@ API_EXPORT(piped_log *) ap_open_piped_log(ap_context_t *p, const char *program)
     pl->p = p;
     pl->program = ap_pstrdup(p, program);
     pl->pid = -1;
-    if (pipe(pl->fds) == -1) {
+    if (ap_create_pipe(p, &pl->fds[0], &pl->fds[1]) != APR_SUCCESS) {
        int save_errno = errno;
        errno = save_errno;
        return NULL;
@@ -695,8 +705,8 @@ API_EXPORT(piped_log *) ap_open_piped_log(ap_context_t *p, const char *program)
     if (piped_log_spawn(pl) == -1) {
        int save_errno = errno;
        ap_kill_cleanup(p, pl, piped_log_cleanup);
-       close(pl->fds[0]);
-       close(pl->fds[1]);
+       ap_close(pl->fds[0]);
+       ap_close(pl->fds[1]);
        errno = save_errno;
        return NULL;
     }
@@ -743,6 +753,7 @@ API_EXPORT(piped_log *) ap_open_piped_log(ap_context_t *p, const char *program)
 {
     piped_log *pl;
     FILE *dummy;
+    int dummyno;
 #ifdef TPF
     TPF_FORK_CHILD cld;
     cld.filename = (char *)program;
@@ -761,7 +772,8 @@ API_EXPORT(piped_log *) ap_open_piped_log(ap_context_t *p, const char *program)
     }
     pl = ap_palloc(p, sizeof (*pl));
     pl->p = p;
-    pl->write_f = dummy;
+    dummyno = fileno(dummy);
+    ap_put_os_file(p, &pl->write_f, &dummyno);
 
     return pl;
 }
@@ -769,6 +781,6 @@ API_EXPORT(piped_log *) ap_open_piped_log(ap_context_t *p, const char *program)
 
 API_EXPORT(void) ap_close_piped_log(piped_log *pl)
 {
-    ap_pfclose(pl->p, pl->write_f);
+    ap_close(pl->write_f);
 }
 #endif
index e127bdbbd80131f59a467b7e5f86cacc1663c75a..420549381b078376afcdfecceac3663fd7efdc8c 100644 (file)
@@ -57,6 +57,7 @@
  
 #define CORE_PRIVATE 
  
+#include "apr_portable.h"
 #include "httpd.h" 
 #include "http_main.h" 
 #include "http_log.h" 
@@ -677,7 +678,6 @@ static int setup_listeners(ap_context_t *pconf, server_rec *s)
 {
     ap_listen_rec *lr;
     int num_listeners = 0;
-
     if (ap_listen_open(pconf, s->port)) {
        return 0;
     }
@@ -800,12 +800,12 @@ static void * worker_thread(void * dummy)
     int thread_slot = ti->tid;
     ap_context_t *tpool = ti->tpool;
     struct sockaddr sa_client;
-    int csd = -1;
+    ap_socket_t *csd = NULL;
     ap_context_t *ptrans;              /* Pool for per-transaction stuff */
-    int sd = -1;
+    ap_socket_t *sd = NULL;
     int srv;
     int curr_pollfd, last_pollfd = 0;
-    size_t len = sizeof(struct sockaddr);
+    int thesock;
 
     free(ti);
 
@@ -853,7 +853,7 @@ static void * worker_thread(void * dummy)
             }
 
             if (num_listenfds == 1) {
-                sd = ap_listeners->fd;
+                sd = ap_listeners->sd;
                 goto got_fd;
             }
             else {
@@ -867,7 +867,7 @@ static void * worker_thread(void * dummy)
                     /* XXX: Should we check for POLLERR? */
                     if (listenfds[curr_pollfd].revents & POLLIN) {
                         last_pollfd = curr_pollfd;
-                        sd = listenfds[curr_pollfd].fd;
+                        ap_put_os_sock(tpool, &sd, &listenfds[curr_pollfd].fd); 
                         goto got_fd;
                     }
                 } while (curr_pollfd != last_pollfd);
@@ -875,7 +875,7 @@ static void * worker_thread(void * dummy)
         }
     got_fd:
         if (!workers_may_exit) {
-            csd = ap_accept(sd, &sa_client, &len);
+            ap_accept(sd, &csd);
             SAFE_ACCEPT(accept_mutex_off(0));
             SAFE_ACCEPT(intra_mutex_off(0));
         }
@@ -884,7 +884,8 @@ static void * worker_thread(void * dummy)
             SAFE_ACCEPT(intra_mutex_off(0));
             break;
         }
-        process_socket(ptrans, &sa_client, csd, process_slot, thread_slot);
+        ap_get_os_sock(csd, &thesock);
+        process_socket(ptrans, &sa_client, thesock, process_slot, thread_slot);
         ap_clear_pool(ptrans);
         requests_this_child--;
     }
@@ -948,7 +949,7 @@ static void child_main(int child_num_arg)
     listenfds[0].events = POLLIN;
     listenfds[0].revents = 0;
     for (lr = ap_listeners, i = 1; i <= num_listenfds; lr = lr->next, ++i) {
-        listenfds[i].fd = lr->fd;
+        ap_get_os_sock(lr->sd, &listenfds[i].fd);
         listenfds[i].events = POLLIN; /* should we add POLLPRI ?*/
         listenfds[i].revents = 0;
     }
@@ -1288,8 +1289,13 @@ int ap_mpm_run(ap_context_t *_pconf, ap_context_t *plog, server_rec *s)
                      "pipe: (pipe_of_death)");
         exit(1);
     }
+/*  XXXXXX  Removed because these functions don't exist anymore.  When
+    These pipes are changed to apr_types, these functions won't be needed
+    anyway.
     ap_note_cleanups_for_fd(pconf, pipe_of_death[0]);
     ap_note_cleanups_for_fd(pconf, pipe_of_death[1]);
+*/
+
     if (fcntl(pipe_of_death[0], F_SETFD, O_NONBLOCK) == -1) {
         ap_log_error(APLOG_MARK, APLOG_ERR,
                      (const server_rec*) server_conf,
@@ -1310,7 +1316,6 @@ int ap_mpm_run(ap_context_t *_pconf, ap_context_t *plog, server_rec *s)
     }
 
     set_signals();
-
     /* Don't thrash... */
     if (max_spare_threads < min_spare_threads + ap_threads_per_child)
        max_spare_threads = min_spare_threads + ap_threads_per_child;
index 8ffb390a3f06e52f7b2fadfa5df5a7900f8b13d5..430c4f002fc0b6ce3d3c5626c40e5085138d7c4b 100644 (file)
@@ -87,6 +87,7 @@
 
 #define CORE_PRIVATE
 
+#include "apr_portable.h"
 #include "httpd.h"
 #include "mpm_default.h"
 #include "http_main.h"
@@ -135,7 +136,7 @@ static char ap_coredump_dir[MAX_STRING_LEN];
 /* *Non*-shared http_main globals... */
 
 static server_rec *server_conf;
-static int sd;
+static ap_socket_t *sd;
 static fd_set listenfds;
 static int listenmaxfd;
 
@@ -528,7 +529,7 @@ static int lock_fd = -1;
  */
 static void accept_mutex_init(ap_context_t *p)
 {
-
+    ap_file_t *tempfile;
     lock_it.l_whence = SEEK_SET;       /* from current point */
     lock_it.l_start = 0;               /* -"- */
     lock_it.l_len = 0;                 /* until end of file */
@@ -541,7 +542,9 @@ static void accept_mutex_init(ap_context_t *p)
     unlock_it.l_pid = 0;               /* pid not actually interesting */
 
     expand_lock_fname(p);
-    lock_fd = ap_popenf(p, ap_lock_fname, O_CREAT | O_WRONLY | O_EXCL, 0644);
+    ap_open(p, ap_lock_fname, APR_CREATE | APR_WRITE | APR_EXCL,
+            APR_UREAD | APR_UWRITE | APR_GREAD | APR_WREAD, &tempfile);
+    ap_get_os_file(tempfile, &lock_fd);
     if (lock_fd == -1) {
        perror("open");
        fprintf(stderr, "Cannot open lock file: %s\n", ap_lock_fname);
@@ -1903,7 +1906,7 @@ static void sock_disable_nagle(int s)
  */
 
 static int srv;
-static int csd;
+static ap_socket_t *csd;
 static int requests_this_child;
 static fd_set main_fds;
 
@@ -1934,9 +1937,11 @@ static void child_main(int child_num_arg)
     ap_context_t *ptrans;
     conn_rec *current_conn;
     ap_iol *iol;
+    ap_status_t stat;
+    int sockdes;
 
     my_pid = getpid();
-    csd = -1;
+    csd = NULL;
     my_child_num = child_num_arg;
     requests_this_child = 0;
     last_lr = NULL;
@@ -2034,7 +2039,8 @@ static void child_main(int child_num_arg)
                }
                first_lr=lr;
                do {
-                   if (FD_ISSET(lr->fd, &main_fds))
+                    ap_get_os_sock(lr->sd, &sockdes);
+                   if (FD_ISSET(sockdes, &main_fds))
                        goto got_listener;
                    lr = lr->next;
                    if (!lr)
@@ -2047,11 +2053,11 @@ static void child_main(int child_num_arg)
                continue;
        got_listener:
                last_lr = lr;
-               sd = lr->fd;
+               sd = lr->sd;
            }
            else {
                /* only one socket, just pretend we did the other stuff */
-               sd = ap_listeners->fd;
+               sd = ap_listeners->sd;
            }
 
            /* if we accept() something we don't want to die, so we have to
@@ -2064,12 +2070,12 @@ static void child_main(int child_num_arg)
                    clean_child_exit(0);
                }
                clen = sizeof(sa_client);
-               csd = ap_accept(sd, &sa_client, &clen);
-               if (csd >= 0 || errno != EINTR)
+               stat = ap_accept(sd, &csd);
+               if (stat == APR_SUCCESS || stat != APR_EINTR)
                    break;
            }
 
-           if (csd >= 0)
+           if (stat == APR_SUCCESS)
                break;          /* We have a socket ready for reading */
            else {
 
@@ -2192,28 +2198,30 @@ static void child_main(int child_num_arg)
         * socket options, file descriptors, and read/write buffers.
         */
 
+        ap_get_os_sock(csd, &sockdes);
+
        clen = sizeof(sa_server);
-       if (getsockname(csd, &sa_server, &clen) < 0) {
+       if (getsockname(sockdes, &sa_server, &clen) < 0) {
            ap_log_error(APLOG_MARK, APLOG_ERR, server_conf, "getsockname");
-           close(csd);
+           ap_close_socket(csd);
            continue;
        }
 
-       sock_disable_nagle(csd);
+       sock_disable_nagle(sockdes);
 
-       iol = unix_attach_socket(csd);
+       iol = unix_attach_socket(sockdes);
        if (iol == NULL) {
            if (errno == EBADF) {
                ap_log_error(APLOG_MARK, APLOG_NOERRNO|APLOG_WARNING, NULL,
                    "filedescriptor (%u) larger than FD_SETSIZE (%u) "
                    "found, you probably need to rebuild Apache with a "
-                   "larger FD_SETSIZE", csd, FD_SETSIZE);
+                   "larger FD_SETSIZE", sockdes, FD_SETSIZE);
            }
            else {
                ap_log_error(APLOG_MARK, APLOG_WARNING, NULL,
                    "error attaching to socket");
            }
-           close(csd);
+           ap_close_socket(csd);
            continue;
        }
 
@@ -2517,6 +2525,7 @@ static void process_child_status(int pid, ap_wait_t status)
 static int setup_listeners(ap_context_t *p, server_rec *s)
 {
     ap_listen_rec *lr;
+    int sockdes;
 
     if (ap_listen_open(p, s->port)) {
        ap_log_error(APLOG_MARK, APLOG_NOERRNO|APLOG_ALERT, s,
@@ -2527,9 +2536,10 @@ static int setup_listeners(ap_context_t *p, server_rec *s)
     listenmaxfd = -1;
     FD_ZERO(&listenfds);
     for (lr = ap_listeners; lr; lr = lr->next) {
-       FD_SET(lr->fd, &listenfds);
-       if (lr->fd > listenmaxfd) {
-           listenmaxfd = lr->fd;
+        ap_get_os_sock(lr->sd, &sockdes);
+       FD_SET(sockdes, &listenfds);
+       if (sockdes > listenmaxfd) {
+           listenmaxfd = sockdes;
        }
     }
     return 0;
@@ -2547,7 +2557,7 @@ int ap_mpm_run(ap_context_t *_pconf, ap_context_t *plog, server_rec *s)
     pconf = _pconf;
 
     server_conf = s;
-
     ap_log_pid(pconf, ap_pid_fname);
 
     if (setup_listeners(pconf, s)) {
index 0ceb7e1bc1f198abee51ddc9a916a7acd388cb59..0fd9ef2e54c60d90ed181396e6f8f293e64fda72 100644 (file)
@@ -81,6 +81,7 @@
 #include "http_log.h"          /* for aplog_error */
 #include "rfc1413.h"
 #include "http_main.h"         /* set_callback_and_alarm */
+#include "apr_network_io.h"
 
 /* Local stuff. */
 /* Semi-well-known port */
@@ -102,12 +103,12 @@ static JMP_BUF timebuf;
 
 /* bind_connect - bind both ends of a socket */
 /* Ambarish fix this. Very broken */
-static int get_rfc1413(int sock, const struct sockaddr_in *our_sin,
-                      const struct sockaddr_in *rmt_sin
+static int get_rfc1413(ap_socket_t *sock, const char *local_ip,
+                      const char *rmt_ip
                       char user[RFC1413_USERLEN+1], server_rec *srv)
 {
-    struct sockaddr_in rmt_query_sin, our_query_sin;
     unsigned int rmt_port, our_port;
+    unsigned int sav_rmt_port, sav_our_port;
     int i;
     char *cp;
     char buffer[RFC1413_MAXDATA + 1];
@@ -122,29 +123,30 @@ static int get_rfc1413(int sock, const struct sockaddr_in *our_sin,
      * addresses from the query socket.
      */
 
-    our_query_sin = *our_sin;
-    our_query_sin.sin_port = htons(ANY_PORT);
-    rmt_query_sin = *rmt_sin;
-    rmt_query_sin.sin_port = htons(RFC1413_PORT);
+    ap_setport(sock, ANY_PORT);
+    ap_setipaddr(sock, local_ip); 
 
-    if (bind(sock, (struct sockaddr *) &our_query_sin,
-            sizeof(struct sockaddr_in)) < 0) {
+    if (ap_bind(sock) != APR_SUCCESS) {
        ap_log_error(APLOG_MARK, APLOG_CRIT, srv,
                    "bind: rfc1413: Error binding to local port");
        return -1;
     }
+    ap_getport(sock, &sav_our_port);
 
 /*
  * errors from connect usually imply the remote machine doesn't support
  * the service
  */
-    if (connect(sock, (struct sockaddr *) &rmt_query_sin,
-               sizeof(struct sockaddr_in)) < 0)
-                   return -1;
+    ap_setport(sock, RFC1413_PORT);
+    ap_setipaddr(sock, rmt_ip); 
+                    
+    if (ap_connect(sock, NULL) != APR_SUCCESS)
+        return -1;
+    ap_getport(sock, &sav_rmt_port);
 
 /* send the data */
-    buflen = ap_snprintf(buffer, sizeof(buffer), "%u,%u\r\n", ntohs(rmt_sin->sin_port),
-               ntohs(our_sin->sin_port));
+    buflen = ap_snprintf(buffer, sizeof(buffer), "%u,%u\r\n", sav_rmt_port,
+               sav_our_port);
 
     /* send query to server. Handle short write. */
 #ifdef CHARSET_EBCDIC
@@ -152,9 +154,10 @@ static int get_rfc1413(int sock, const struct sockaddr_in *our_sin,
 #endif
     i = 0;
     while(i < strlen(buffer)) {
-        int j;
-       j = write(sock, buffer+i, (strlen(buffer+i)));
-       if (j < 0 && errno != EINTR) {
+        int j = strlen(buffer + i);
+        ap_status_t stat;
+       stat  = ap_send(sock, buffer+i, &j);
+       if (stat != APR_SUCCESS && stat != APR_EINTR) {
          ap_log_error(APLOG_MARK, APLOG_CRIT, srv,
                       "write: rfc1413: error sending request");
          return -1;
@@ -177,9 +180,10 @@ static int get_rfc1413(int sock, const struct sockaddr_in *our_sin,
      * this allows it to work on both ASCII and EBCDIC machines.
      */
     while((cp = strchr(buffer, '\012')) == NULL && i < sizeof(buffer) - 1) {
-        int j;
-       j = read(sock, buffer+i, (sizeof(buffer) - 1) - i);
-       if (j < 0 && errno != EINTR) {
+        int j = sizeof(buffer) - 1 - i;
+        ap_status_t stat;
+       stat = ap_recv(sock, buffer+i, &j);
+       if (stat != APR_SUCCESS && stat != APR_EINTR) {
           ap_log_error(APLOG_MARK, APLOG_CRIT, srv,
                        "read: rfc1413: error reading response");
           return -1;
@@ -194,8 +198,8 @@ static int get_rfc1413(int sock, const struct sockaddr_in *our_sin,
     ascii2ebcdic(&buffer, &buffer, (size_t)i);
 #endif
     if (sscanf(buffer, "%u , %u : USERID :%*[^:]:%512s", &rmt_port, &our_port,
-              user) != 3 || ntohs(rmt_sin->sin_port) != rmt_port
-       || ntohs(our_sin->sin_port) != our_port)
+              user) != 3 || sav_rmt_port != rmt_port
+       || sav_our_port != our_port)
        return -1;
 
     /*
@@ -214,12 +218,11 @@ char *ap_rfc1413(conn_rec *conn, server_rec *srv)
 {
     static char user[RFC1413_USERLEN + 1];     /* XXX */
     static char *result;
-    static int sock;
+    static ap_socket_t *sock;
 
     result = FROM_UNKNOWN;
 
-    sock = ap_psocket(conn->pool, AF_INET, SOCK_STREAM, IPPROTO_TCP);
-    if (sock < 0) {
+    if (ap_create_tcp_socket(conn->pool, &sock) != APR_SUCCESS) {
        ap_log_error(APLOG_MARK, APLOG_CRIT, srv,
                    "socket: rfc1413: error creating socket");
        conn->remote_logname = result;
@@ -230,10 +233,10 @@ char *ap_rfc1413(conn_rec *conn, server_rec *srv)
      */
     if (ap_setjmp(timebuf) == 0) {
 
-       if (get_rfc1413(sock, &conn->local_addr, &conn->remote_addr, user, srv) >= 0)
+       if (get_rfc1413(sock, conn->local_ip, conn->remote_ip, user, srv) >= 0)
            result = user;
     }
-    ap_pclosesocket(conn->pool, sock);
+    ap_close_socket(sock);
     conn->remote_logname = result;
 
     return conn->remote_logname;
index fe8b63673699ef09265d8a0ae15bbe064d250c4f..9e142e0ae264e3404c33e088c617847263f491bd 100644 (file)
@@ -803,38 +803,37 @@ API_EXPORT(int) ap_cfg_closefile(configfile_t *cfp)
     return (cfp->close == NULL) ? 0 : cfp->close(cfp->param);
 }
 
-/* Common structure that holds the file and ap_context_t for ap_pcfg_openfile */
-typedef struct {
-    ap_context_t *pool;
-    FILE *file;
-} poolfile_t;
-
-static int cfg_close(void *param)
+static ap_status_t cfg_close(void *param)
 {
-    poolfile_t *cfp = (poolfile_t *) param;
-    return (ap_pfclose(cfp->pool, cfp->file));
+    ap_file_t *cfp = (ap_file_t *) param;
+    return (ap_close(cfp));
 }
 
 static int cfg_getch(void *param)
 {
-    poolfile_t *cfp = (poolfile_t *) param;
-    return (fgetc(cfp->file));
+    char ch;
+    ap_file_t *cfp = (ap_file_t *) param;
+    if (ap_getc(cfp, &ch) == APR_SUCCESS)
+        return ch;
+    return (int)EOF;
 }
 
 static void *cfg_getstr(void *buf, size_t bufsiz, void *param)
 {
-    poolfile_t *cfp = (poolfile_t *) param;
-    return (fgets(buf, bufsiz, cfp->file));
+    ap_file_t *cfp = (ap_file_t *) param;
+    if (ap_gets(cfp, buf, bufsiz) == APR_SUCCESS)
+        return buf;
+    return NULL;
 }
 
 /* Open a configfile_t as FILE, return open configfile_t struct pointer */
 API_EXPORT(configfile_t *) ap_pcfg_openfile(ap_context_t *p, const char *name)
 {
     configfile_t *new_cfg;
-    poolfile_t *new_pfile;
-    FILE *file;
-    struct stat stbuf;
+    ap_file_t *file;
     int saved_errno;
+    ap_status_t stat;
+    ap_filetype_e type;
 
     if (name == NULL) {
         ap_log_error(APLOG_MARK, APLOG_ERR | APLOG_NOERRNO, NULL,
@@ -850,41 +849,37 @@ API_EXPORT(configfile_t *) ap_pcfg_openfile(ap_context_t *p, const char *name)
         return NULL;
     }
  
-    /* ZZZ bopenf and use AP defines for flags. */
-    file = ap_pfopen(p, name, "r");
+    stat = ap_open(p, name, APR_READ | APR_BUFFERED, APR_OS_DEFAULT, &file);
 #ifdef DEBUG
     saved_errno = errno;
     ap_log_error(APLOG_MARK, APLOG_DEBUG | APLOG_NOERRNO, NULL,
                 "Opening config file %s (%s)",
-                name, (file == NULL) ? strerror(errno) : "successful");
+                name, (stat != APR_SUCCESS) ? strerror(errno) : "successful");
     errno = saved_errno;
 #endif
-    if (file == NULL)
+    if (stat != APR_SUCCESS)
         return NULL;
 
-    if (fstat(fileno(file), &stbuf) == 0 &&
-        !S_ISREG(stbuf.st_mode) &&
+    if (ap_get_filetype(file, &type) == APR_SUCCESS &&
+        type == APR_REG &&
 #if defined(WIN32) || defined(OS2)
         !(strcasecmp(name, "nul") == 0 ||
           (strlen(name) >= 4 &&
            strcasecmp(name + strlen(name) - 4, "/nul") == 0))) {
 #else
-        strcmp(name, "/dev/null") != 0) {
+        strcmp(name, "/dev/null") == 0) {
 #endif /* WIN32 || OS2 */
        saved_errno = errno;
         ap_log_error(APLOG_MARK, APLOG_ERR | APLOG_NOERRNO, NULL,
                     "Access to file %s denied by server: not a regular file",
                     name);
-        ap_pfclose(p, file);
+        ap_close(file);
        errno = saved_errno;
         return NULL;
     }
 
     new_cfg = ap_palloc(p, sizeof(*new_cfg));
-    new_pfile = ap_palloc(p, sizeof(*new_pfile));
-    new_pfile->file = file;
-    new_pfile->pool = p;
-    new_cfg->param = new_pfile;
+    new_cfg->param = file;
     new_cfg->name = ap_pstrdup(p, name);
     new_cfg->getch = (int (*)(void *)) cfg_getch;
     new_cfg->getstr = (void *(*)(void *, size_t, void *)) cfg_getstr;
index d59c717eaa91f9d4a59fbeb44cfecfee632beef9..f58d222c38c3d6031d3e2ba4773c89a55b592ddc 100644 (file)
@@ -84,6 +84,7 @@
 /* md5.c --Module Interface to MD5. */
 /* Jeff Hostetler, Spyglass, Inc., 1994. */
 
+#include "apr_portable.h"
 #include "httpd.h"
 #include "util_md5.h"
 
@@ -189,7 +190,7 @@ API_EXPORT(char *) ap_md5contextTo64(ap_context_t *a, AP_MD5_CTX * context)
 
 #ifdef CHARSET_EBCDIC
 
-API_EXPORT(char *) ap_md5digest(ap_context_t *p, APRFile infile, int convert)
+API_EXPORT(char *) ap_md5digest(ap_context_t *p, int infile, int convert)
 {
     AP_MD5_CTX context;
     unsigned char buf[1000];
@@ -212,7 +213,7 @@ API_EXPORT(char *) ap_md5digest(ap_context_t *p, APRFile infile, int convert)
 
 #else
 
-API_EXPORT(char *) ap_md5digest(ap_context_t *p, APRFile infile)
+API_EXPORT(char *) ap_md5digest(ap_context_t *p, int infile)
 {
     AP_MD5_CTX context;
     unsigned char buf[1000];
index 1eba115e84e8b15d66b89ebe13bc36b59bba6526..da65906826af7d258167b742569b6d9995938856 100644 (file)
@@ -688,6 +688,7 @@ API_EXPORT(int) ap_call_exec(request_rec *r, ap_child_info_t *pinfo, char *argv0
                             char **env, int shellcmd)
 {
     int pid = 0;
+    int errfileno = STDERR_FILENO;
 
 #if !defined(WIN32) && !defined(OS2)
     /* the fd on r->server->error_log is closed, but we need somewhere to
@@ -695,7 +696,7 @@ API_EXPORT(int) ap_call_exec(request_rec *r, ap_child_info_t *pinfo, char *argv0
      * since that is better than allowing errors to go unnoticed.  Don't do
      * this on Win32, though, since we haven't fork()'d.
      */
-    r->server->error_log = stderr;
+    ap_put_os_file(r->pool, &r->server->error_log, &errfileno);
 #endif
 
     /* TODO: all that RLimit stuff should become part of the spawning API,