• Main Page
  • Related Pages
  • Namespaces
  • Data Structures
  • Files
  • File List
  • Globals

LogAccessICP.cc

Go to the documentation of this file.
00001 /** @file
00002 
00003   A brief file description
00004 
00005   @section license License
00006 
00007   Licensed to the Apache Software Foundation (ASF) under one
00008   or more contributor license agreements.  See the NOTICE file
00009   distributed with this work for additional information
00010   regarding copyright ownership.  The ASF licenses this file
00011   to you under the Apache License, Version 2.0 (the
00012   "License"); you may not use this file except in compliance
00013   with the License.  You may obtain a copy of the License at
00014 
00015       http://www.apache.org/licenses/LICENSE-2.0
00016 
00017   Unless required by applicable law or agreed to in writing, software
00018   distributed under the License is distributed on an "AS IS" BASIS,
00019   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00020   See the License for the specific language governing permissions and
00021   limitations under the License.
00022  */
00023 
00024 /***************************************************************************
00025  LogAccessICP.cc
00026 
00027  This file implements the LogAccessICP class, which specializes the
00028  LogAccess class for ICP logging.  Some of the field requests are not
00029  relevant to ICP logging, and for those we simply return a default value
00030  (NULL strings, 0 values).
00031 
00032 
00033  ***************************************************************************/
00034 #include "libts.h"
00035 #include "Error.h"
00036 #include "HTTP.h"
00037 #include "ICP.h"
00038 #include "ICPlog.h"
00039 #include "LogAccessICP.h"
00040 #include "LogUtils.h"
00041 
00042 /*-------------------------------------------------------------------------
00043   LogAccessICP
00044   -------------------------------------------------------------------------*/
00045 
00046 LogAccessICP::LogAccessICP(ICPlog * icp_log)
00047   : m_icp_log(icp_log)
00048 {
00049   ink_assert(m_icp_log != NULL);
00050 }
00051 
00052 /*-------------------------------------------------------------------------
00053   LogAccessICP::~LogAccessICP
00054   -------------------------------------------------------------------------*/
00055 
00056 LogAccessICP::~LogAccessICP()
00057 {
00058 }
00059 
00060 /*-------------------------------------------------------------------------
00061   The marshalling routines ...
00062   -------------------------------------------------------------------------*/
00063 
00064 /*-------------------------------------------------------------------------
00065   -------------------------------------------------------------------------*/
00066 
00067 int
00068 LogAccessICP::marshal_client_host_ip(char *buf)
00069 {
00070   return marshal_ip(buf, m_icp_log->GetClientIP());
00071 }
00072 
00073 /*-------------------------------------------------------------------------
00074   -------------------------------------------------------------------------*/
00075 
00076 int
00077 LogAccessICP::marshal_client_host_port(char *buf)
00078 {
00079   if (buf) {
00080     uint16_t port = ntohs(m_icp_log->GetClientPort());
00081     marshal_int(buf, port);
00082   }
00083   return INK_MIN_ALIGN;
00084 }
00085 
00086 /*-------------------------------------------------------------------------
00087   -------------------------------------------------------------------------*/
00088 
00089 int
00090 LogAccessICP::marshal_client_auth_user_name(char *buf)
00091 {
00092   char *str = (char *) m_icp_log->GetIdent();
00093   int len = LogAccess::strlen(str);
00094   if (buf) {
00095     marshal_str(buf, str, len);
00096   }
00097   return len;
00098 }
00099 
00100 /*-------------------------------------------------------------------------
00101   -------------------------------------------------------------------------*/
00102 
00103 int
00104 LogAccessICP::marshal_client_req_text(char *buf)
00105 {
00106   int len = marshal_client_req_http_method(NULL) + marshal_client_req_url(NULL) + marshal_client_req_http_version(NULL);
00107 
00108   if (buf) {
00109     int offset = 0;
00110     offset += marshal_client_req_http_method(&buf[offset]);
00111     offset += marshal_client_req_url(&buf[offset]);
00112     offset += marshal_client_req_http_version(&buf[offset]);
00113     len = offset;
00114   }
00115   return len;
00116 }
00117 
00118 /*-------------------------------------------------------------------------
00119   -------------------------------------------------------------------------*/
00120 
00121 int
00122 LogAccessICP::marshal_client_req_http_method(char *buf)
00123 {
00124   char *str = (char *) m_icp_log->GetMethod();
00125   int len = LogAccess::strlen(str);
00126 
00127   if (buf) {
00128     marshal_str(buf, str, len);
00129   }
00130   return len;
00131 }
00132 
00133 /*-------------------------------------------------------------------------
00134   -------------------------------------------------------------------------*/
00135 
00136 int
00137 LogAccessICP::marshal_client_req_url(char *buf)
00138 {
00139   char *str = (char *) m_icp_log->GetURI();
00140   int len = LogAccess::strlen(str);
00141   if (buf) {
00142     marshal_str(buf, str, len);
00143   }
00144   return len;
00145 }
00146 
00147 /*-------------------------------------------------------------------------
00148   -------------------------------------------------------------------------*/
00149 
00150 int
00151 LogAccessICP::marshal_client_req_url_canon(char *buf)
00152 {
00153   int escapified_len;
00154   Arena arena;
00155 
00156   // FIXME: need to ensure that m_icp_log->GetURI() is NUL-terminated
00157   //
00158   char *uri_str = (char *) m_icp_log->GetURI();
00159   int uri_len =::strlen(uri_str);
00160   char *str = LogUtils::escapify_url(&arena, uri_str, uri_len,
00161                                      &escapified_len);
00162 
00163   int len = round_strlen(escapified_len + 1);   // the padded len
00164   if (buf)
00165     marshal_str(buf, str, len);
00166   return len;
00167 }
00168 
00169 /*-------------------------------------------------------------------------
00170   -------------------------------------------------------------------------*/
00171 
00172 int
00173 LogAccessICP::marshal_proxy_resp_content_type(char *buf)
00174 {
00175   // FIXME: need to ensure that m_icp_log->GetContentType() is NUL-terminated
00176   //
00177   char *ct_str = (char *) m_icp_log->GetContentType();
00178   int ct_len = ::strlen(ct_str);
00179 
00180   // FIXME: need to be sure remove_content_type_attributecan mutate ct_str
00181   //
00182   LogUtils::remove_content_type_attributes(ct_str, &ct_len);
00183   int len = LogAccess::strlen(ct_str);
00184   if (buf)
00185     marshal_str(buf, ct_str, len);
00186   return len;
00187 }
00188 
00189 /*-------------------------------------------------------------------------
00190   -------------------------------------------------------------------------*/
00191 
00192 int
00193 LogAccessICP::marshal_proxy_resp_squid_len(char *buf)
00194 {
00195   if (buf) {
00196     int64_t val = m_icp_log->GetSize();
00197     marshal_int(buf, val);
00198   }
00199   return INK_MIN_ALIGN;
00200 }
00201 
00202 /*-------------------------------------------------------------------------
00203   -------------------------------------------------------------------------*/
00204 
00205 int
00206 LogAccessICP::marshal_proxy_resp_content_len(char *buf)
00207 {
00208   if (buf) {
00209     int64_t val = m_icp_log->GetSize();
00210     marshal_int(buf, val);
00211   }
00212   return INK_MIN_ALIGN;
00213 }
00214 
00215 /*-------------------------------------------------------------------------
00216   -------------------------------------------------------------------------*/
00217 
00218 int
00219 LogAccessICP::marshal_proxy_resp_status_code(char *buf)
00220 {
00221   if (buf) {
00222     int64_t status = 0;         // '000' for ICP
00223     marshal_int(buf, status);
00224   }
00225   return INK_MIN_ALIGN;
00226 }
00227 
00228 /*-------------------------------------------------------------------------
00229   -------------------------------------------------------------------------*/
00230 
00231 int
00232 LogAccessICP::marshal_cache_result_code(char *buf)
00233 {
00234   if (buf) {
00235     SquidLogCode code = m_icp_log->GetAction();
00236     marshal_int(buf, (int64_t) code);
00237   }
00238   return INK_MIN_ALIGN;
00239 }
00240 
00241 /*-------------------------------------------------------------------------
00242   -------------------------------------------------------------------------*/
00243 
00244 int
00245 LogAccessICP::marshal_proxy_hierarchy_route(char *buf)
00246 {
00247   if (buf) {
00248     SquidHierarchyCode code = m_icp_log->GetHierarchy();
00249     marshal_int(buf, (int64_t) code);
00250   }
00251   return INK_MIN_ALIGN;
00252 }
00253 
00254 /*-------------------------------------------------------------------------
00255   -------------------------------------------------------------------------*/
00256 
00257 int
00258 LogAccessICP::marshal_server_host_name(char *buf)
00259 {
00260   char *str = (char *) m_icp_log->GetFromHost();
00261   int len = LogAccess::strlen(str);
00262   if (buf) {
00263     marshal_str(buf, str, len);
00264   }
00265   return len;
00266 }
00267 
00268 /*-------------------------------------------------------------------------
00269   -------------------------------------------------------------------------*/
00270 
00271 int
00272 LogAccessICP::marshal_transfer_time_ms(char *buf)
00273 {
00274   if (buf) {
00275     ink_hrtime elapsed = m_icp_log->GetElapsedTime();
00276     elapsed /= HRTIME_MSECOND;
00277     int64_t val = (int64_t) elapsed;
00278     marshal_int(buf, val);
00279   }
00280   return INK_MIN_ALIGN;
00281 }
00282 
00283 int
00284 LogAccessICP::marshal_transfer_time_s(char *buf)
00285 {
00286   if (buf) {
00287     ink_hrtime elapsed = m_icp_log->GetElapsedTime();
00288     elapsed /= HRTIME_SECOND;
00289     int64_t val = (int64_t) elapsed;
00290     marshal_int(buf, val);
00291   }
00292   return INK_MIN_ALIGN;
00293 }

Generated by  doxygen 1.7.1