"Fossies" - the Fresh Open Source Software Archive 
As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style:
standard) with prefixed line numbers and
code folding option.
Alternatively you can here
view or
download the uninterpreted source code file.
For more information about "ftp_message.c" see the
Fossies "Dox" file reference documentation.
1 /* Licensed to the Apache Software Foundation (ASF) under one or more
2 * contributor license agreements. See the NOTICE file distributed with
3 * this work for additional information regarding copyright ownership.
4 * The ASF licenses this file to You under the Apache License, Version 2.0
5 * (the "License"); you may not use this file except in compliance with
6 * the License. You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 /*
18 * Original Copyright (c) 2005 Covalent Technologies
19 *
20 * FTP Protocol module for Apache 2.0
21 */
22
23 #include "mod_ftp.h"
24 #include "ftp_internal.h"
25
26 /* ftp_message_generate: Function to transform meta-characters
27 *
28 * Arguments: fc - The ftp connection
29 * inbuf - The input buffer
30 * outbuf - The output buffer
31 * outlen - The length of the output buffer
32 *
33 * Returns: nadda
34 */
35 void ftp_message_generate(ftp_connection *fc, const char *inbuf,
36 char *outbuf, size_t outlen)
37 {
38 conn_rec *c = fc->connection;
39 const char *inptr = inbuf;
40 char *outptr = outbuf;
41 char time_str[APR_CTIME_LEN];
42 char *remote_host, *local_host;
43
44 while ((outlen > 1) && (*inptr != '\0')) {
45 if (*inptr != '%') {
46 *outptr++ = *inptr;
47 outlen -= 1;
48 }
49 else {
50 switch (*++inptr) {
51 case 'T':
52 apr_ctime(time_str, apr_time_now());
53 apr_cpystrn(outptr, time_str, outlen);
54 break;
55 case 'C':
56 apr_snprintf(outptr, outlen, "%s", fc->cwd);
57 break;
58 case 'h':
59 apr_getnameinfo(&remote_host, c->remote_addr, 0);
60 apr_snprintf(outptr, outlen, "%s", remote_host);
61 break;
62 case 'L':
63 apr_getnameinfo(&local_host, c->local_addr, 0);
64 apr_snprintf(outptr, outlen, "%s", local_host);
65 break;
66 case 'E':
67 apr_snprintf(outptr, outlen, "%s",
68 fc->orig_server->server_admin);
69 break;
70 case 'A':
71 apr_snprintf(outptr, outlen, "%s", c->local_ip);
72 break;
73 case 'a':
74 apr_snprintf(outptr, outlen, "%s", c->remote_ip);
75 break;
76 case 'u':
77 apr_snprintf(outptr, outlen, "%s", fc->user);
78 break;
79 case 'f':
80 apr_snprintf(outptr, outlen, "%d", fc->files);
81 break;
82 case 't':
83 apr_snprintf(outptr, outlen, "%" APR_OFF_T_FMT, fc->bytes);
84 break;
85 case 'b':
86 apr_snprintf(outptr, outlen, "%" APR_OFF_T_FMT, fc->traffic);
87 break;
88 case 'x':
89 apr_snprintf(outptr, outlen, "%d", fc->transfers);
90 break;
91 case '%':
92 *outptr++ = '%';
93 outlen -= 1;
94 *outptr = '\0';
95 break;
96 default:
97 *outptr++ = '%';
98 outlen -= 1;
99 if (outlen > 1) {
100 *outptr++ = *inptr;
101 outlen -= 1;
102 }
103 *outptr = '\0';
104 break;
105 }
106 outptr[outlen - 1] = '\0';
107 while (*outptr) {
108 outptr++;
109 outlen -= 1;
110 }
111 }
112 inptr++;
113 }
114 if (outlen > 0) {
115 *outptr = '\0';
116 }
117 }