metaproxy 1.22.1
Classes | Namespaces | Functions | Variables
filter_log.cpp File Reference
#include "config.hpp"
#include "filter_log.hpp"
#include <metaproxy/package.hpp>
#include <string>
#include <sstream>
#include <iomanip>
#include <boost/thread/mutex.hpp>
#include "gduutil.hpp"
#include <metaproxy/util.hpp>
#include <metaproxy/xmlutil.hpp>
#include <yaz/oid_db.h>
#include <yaz/zgdu.h>
#include <yaz/wrbuf.h>
#include <yaz/log.h>
#include <yaz/querytowrbuf.h>
#include <yaz/timing.h>
#include <stdio.h>
#include <time.h>
Include dependency graph for filter_log.cpp:

Go to the source code of this file.

Classes

class  metaproxy_1::filter::Log::Impl
 
class  metaproxy_1::filter::Log::Impl::LFile
 

Namespaces

namespace  metaproxy_1
 
namespace  metaproxy_1::filter
 

Functions

static void log_DefaultDiagFormat (WRBUF w, Z_DefaultDiagFormat *e)
 
static void log_DiagRecs (WRBUF w, int num_diagRecs, Z_DiagRec **diags)
 
static void log_syntax (WRBUF w, const Odr_oid *syntax)
 
static void log_1line_Z_APDU (Z_APDU *z_req, Z_APDU *z_res, WRBUF w)
 
static void log_1line_Z_HTTP (Z_HTTP_Request *req, Z_HTTP_Response *res, WRBUF w)
 
static void log_1line_Z_GDU (Z_GDU *gdu_req, Z_GDU *gdu_res, WRBUF w)
 
static mp::filter::Base * filter_creator ()
 

Variables

static std::list< yf::Log::Impl::LFilePtr > metaproxy_1::filter::filter_log_files
 
struct metaproxy_1_filter_struct metaproxy_1_filter_log
 

Function Documentation

◆ filter_creator()

static mp::filter::Base * filter_creator ( )
static

Definition at line 872 of file filter_log.cpp.

873{
874 return new mp::filter::Log;
875}

◆ log_1line_Z_APDU()

static void log_1line_Z_APDU ( Z_APDU *  z_req,
Z_APDU *  z_res,
WRBUF  w 
)
static

Definition at line 185 of file filter_log.cpp.

186{
187 switch (z_req->which)
188 {
189 case Z_APDU_initRequest:
190 wrbuf_puts(w, "Init ");
191 if (!z_res)
192 wrbuf_puts(w, "?");
193 else if (z_res->which != Z_APDU_initResponse)
194 wrbuf_printf(w, "? response=%d", z_res->which);
195 else
196 {
197 Z_InitRequest *req = z_req->u.initRequest;
198 Z_InitResponse *res = z_res->u.initResponse;
199 if (res->result && *res->result)
200 wrbuf_printf(w, "OK -");
201 else
202 {
203 Z_External *uif = res->userInformationField;
204 bool got_code = false;
205 wrbuf_printf(w, "ERROR ");
206 if (uif && uif->which == Z_External_userInfo1)
207 {
208 Z_OtherInformation *ui = uif->u.userInfo1;
209 if (ui->num_elements >= 1)
210 {
211 Z_OtherInformationUnit *unit = ui->list[0];
212 if (unit->which == Z_OtherInfo_externallyDefinedInfo &&
213 unit->information.externallyDefinedInfo &&
214 unit->information.externallyDefinedInfo->which ==
215 Z_External_diag1)
216 {
217 Z_DiagnosticFormat *diag =
218 unit->information.externallyDefinedInfo->
219 u.diag1;
220 if (diag->num >= 1)
221 {
222 Z_DiagnosticFormat_s *ds = diag->elements[0];
223 if (ds->which ==
224 Z_DiagnosticFormat_s_defaultDiagRec)
225 {
227 ds->u.defaultDiagRec);
228 got_code = true;
229 }
230 }
231
232 }
233 }
234 }
235 if (!got_code)
236 wrbuf_puts(w, "-");
237 }
238 wrbuf_printf(w, " ID:%s Name:%s Version:%s",
239 req->implementationId ? req->implementationId :"-",
240 req->implementationName ?req->implementationName : "-",
241 req->implementationVersion ?
242 req->implementationVersion : "-");
243 }
244 break;
245 case Z_APDU_searchRequest:
246 wrbuf_puts(w, "Search ");
247 if (!z_res)
248 wrbuf_puts(w, "?");
249 else if (z_res->which != Z_APDU_searchResponse)
250 wrbuf_printf(w, "? response=%d", z_res->which);
251 else
252 {
253 Z_SearchRequest *req = z_req->u.searchRequest;
254 Z_SearchResponse *res = z_res->u.searchResponse;
255 int i;
256 for (i = 0 ; i < req->num_databaseNames; i++)
257 {
258 if (i)
259 wrbuf_printf(w, "+");
260 wrbuf_puts(w, req->databaseNames[i]);
261 }
262 wrbuf_printf(w, " ");
263 if (!res->records)
264 {
265 wrbuf_printf(w, "OK " ODR_INT_PRINTF " %s", *res->resultCount,
266 req->resultSetName);
267 }
268 else if (res->records->which == Z_Records_DBOSD)
269 {
270 wrbuf_printf(w, "OK " ODR_INT_PRINTF " %s", *res->resultCount,
271 req->resultSetName);
272 }
273 else if (res->records->which == Z_Records_NSD)
274 {
275 wrbuf_puts(w, "ERROR ");
277 res->records->u.nonSurrogateDiagnostic);
278 }
279 else if (res->records->which == Z_Records_multipleNSD)
280 {
281 wrbuf_puts(w, "ERROR ");
283 w,
284 res->records->u.multipleNonSurDiagnostics->num_diagRecs,
285 res->records->u.multipleNonSurDiagnostics->diagRecs);
286 }
287 wrbuf_puts(w, " ");
288 log_syntax(w, req->preferredRecordSyntax);
289 wrbuf_printf(w, " 1+" ODR_INT_PRINTF " ",
290 res->numberOfRecordsReturned
291 ? *res->numberOfRecordsReturned : 0);
292 yaz_query_to_wrbuf(w, req->query);
293 }
294 break;
295 case Z_APDU_presentRequest:
296 wrbuf_puts(w, "Present ");
297 if (!z_res)
298 wrbuf_puts(w, "?");
299 else if (z_res->which != Z_APDU_presentResponse)
300 wrbuf_printf(w, "? response=%d", z_res->which);
301 else
302 {
303 Z_PresentRequest *req = z_req->u.presentRequest;
304 Z_PresentResponse *res = z_res->u.presentResponse;
305
306 if (!res->records)
307 {
308 wrbuf_printf(w, "OK");
309 }
310 else if (res->records->which == Z_Records_DBOSD)
311 {
312 wrbuf_printf(w, "OK");
313 }
314 else if (res->records->which == Z_Records_NSD)
315 {
316 wrbuf_puts(w, "ERROR ");
318 res->records->u.nonSurrogateDiagnostic);
319 }
320 else if (res->records->which == Z_Records_multipleNSD)
321 {
322 wrbuf_puts(w, "ERROR ");
324 w,
325 res->records->u.multipleNonSurDiagnostics->num_diagRecs,
326 res->records->u.multipleNonSurDiagnostics->diagRecs);
327 }
328 wrbuf_puts(w, " ");
329 log_syntax(w, req->preferredRecordSyntax);
330
331 wrbuf_printf(w, " %s " ODR_INT_PRINTF "+" ODR_INT_PRINTF " ",
332 req->resultSetId, *req->resultSetStartPoint,
333 *req->numberOfRecordsRequested);
334 }
335 break;
336 case Z_APDU_deleteResultSetRequest:
337 wrbuf_puts(w, "deleteResultSet ");
338 break;
339 case Z_APDU_accessControlRequest:
340 wrbuf_puts(w, "accessControl ");
341 break;
342 case Z_APDU_resourceControlRequest:
343 wrbuf_puts(w, "resourceControl ");
344 break;
345 case Z_APDU_triggerResourceControlRequest:
346 wrbuf_puts(w, "triggerResourceControlRequest");
347 break;
348 case Z_APDU_resourceReportRequest:
349 wrbuf_puts(w, "resourceReport ");
350 break;
351 case Z_APDU_scanRequest:
352 wrbuf_puts(w, "Scan ");
353 if (!z_res)
354 wrbuf_puts(w, "?");
355 else if (z_res->which != Z_APDU_scanResponse)
356 wrbuf_printf(w, "? response=%d", z_res->which);
357 else
358 {
359 Z_ScanRequest *req = z_req->u.scanRequest;
360 Z_ScanResponse *res = z_res->u.scanResponse;
361 int i;
362 for (i = 0 ; i < req->num_databaseNames; i++)
363 {
364 if (i)
365 wrbuf_printf(w, "+");
366 wrbuf_puts(w, req->databaseNames[i]);
367 }
368 wrbuf_puts(w, " ");
369 if (!res->scanStatus || *res->scanStatus == 0)
370 wrbuf_puts(w, "OK");
371 else if (*res->scanStatus == 6)
372 wrbuf_puts(w, "ERROR");
373 else
374 wrbuf_printf(w, "PARTIAL" ODR_INT_PRINTF, *res->scanStatus);
375
376 wrbuf_printf(w, " " ODR_INT_PRINTF " " ODR_INT_PRINTF "+"
377 ODR_INT_PRINTF "+" ODR_INT_PRINTF " ",
378 res->numberOfEntriesReturned ?
379 *res->numberOfEntriesReturned : 0,
380 req->preferredPositionInResponse ?
381 *req->preferredPositionInResponse : 1,
382 *req->numberOfTermsRequested,
383 res->stepSize ? *res->stepSize : 1);
384
385 yaz_scan_to_wrbuf(w, req->termListAndStartPoint,
386 req->attributeSet);
387 }
388 break;
389 case Z_APDU_sortRequest:
390 wrbuf_puts(w, "sort ");
391 if (!z_res)
392 wrbuf_puts(w, "?");
393 else if (z_res->which != Z_APDU_sortResponse)
394 wrbuf_printf(w, "? response=%d", z_res->which);
395 else
396 {
397 Z_SortResponse *res = z_res->u.sortResponse;
398 Z_SortRequest *req = z_res->u.sortRequest;
399 int i;
400
401 if (*res->sortStatus == Z_SortResponse_success)
402 wrbuf_puts(w, "OK");
403 else if (*res->sortStatus == Z_SortResponse_partial_1)
404 wrbuf_puts(w, "PARTIAL");
405 else if (*res->sortStatus == Z_SortResponse_failure)
406 wrbuf_puts(w, "ERROR");
407
408 wrbuf_puts(w, " ");
409 if (res->diagnostics && res->num_diagnostics >= 1)
410 log_DiagRecs(w, res->num_diagnostics,res->diagnostics);
411 else
412 wrbuf_puts(w, "-");
413
414 wrbuf_puts(w, " (");
415 for (i = 0; i < req->num_inputResultSetNames; i++)
416 {
417 if (i)
418 wrbuf_puts(w, "+");
419 wrbuf_puts(w, req->inputResultSetNames[i]);
420 }
421 wrbuf_printf(w, ")->%s ",req->sortedResultSetName);
422
423 }
424 break;
425 case Z_APDU_segmentRequest:
426 wrbuf_puts(w, "segmentRequest");
427 break;
428 case Z_APDU_extendedServicesRequest:
429 wrbuf_puts(w, "extendedServices ");
430 if (!z_res)
431 wrbuf_puts(w, "?");
432 else if (z_res->which != Z_APDU_extendedServicesResponse)
433 wrbuf_printf(w, "? response=%d", z_res->which);
434 else
435 {
436 Z_ExtendedServicesResponse *res =
437 z_res->u.extendedServicesResponse;
438 switch (*res->operationStatus)
439 {
440 case Z_ExtendedServicesResponse_done:
441 wrbuf_puts(w, "DONE"); break;
442 case Z_ExtendedServicesResponse_accepted:
443 wrbuf_puts(w, "ACCEPTED"); break;
444 case Z_ExtendedServicesResponse_failure:
445 wrbuf_puts(w, "ERROR"); break;
446 default:
447 wrbuf_printf(w, ODR_INT_PRINTF, *res->operationStatus);
448 }
449 wrbuf_puts(w, " ");
450 if (res->diagnostics && res->num_diagnostics >= 1)
451 log_DiagRecs(w, res->num_diagnostics,res->diagnostics);
452 else
453 wrbuf_puts(w, "-");
454 }
455 break;
456 case Z_APDU_close:
457 wrbuf_puts(w, "close");
458 break;
459 case Z_APDU_duplicateDetectionRequest:
460 wrbuf_puts(w, "duplicateDetention ");
461 if (!z_res)
462 wrbuf_puts(w, "?");
463 else if (z_res->which != Z_APDU_duplicateDetectionResponse)
464 wrbuf_printf(w, "? response=%d", z_res->which);
465 else
466 {
467 Z_DuplicateDetectionResponse *res =
468 z_res->u.duplicateDetectionResponse;
469 if (*res->status)
470 wrbuf_puts(w, "OK");
471 else
472 wrbuf_puts(w, "ERROR");
473
474 wrbuf_puts(w, " ");
475 if (res->diagnostics && res->num_diagnostics >= 1)
476 log_DiagRecs(w, res->num_diagnostics, res->diagnostics);
477 else
478 wrbuf_puts(w, "-");
479 }
480 break;
481 default:
482 wrbuf_printf(w, "REQ=%d RES=%d", z_req->which, z_res->which);
483 }
484}
static void log_syntax(WRBUF w, const Odr_oid *syntax)
static void log_DefaultDiagFormat(WRBUF w, Z_DefaultDiagFormat *e)
static void log_DiagRecs(WRBUF w, int num_diagRecs, Z_DiagRec **diags)

References log_DefaultDiagFormat(), log_DiagRecs(), and log_syntax().

Referenced by log_1line_Z_GDU().

Here is the call graph for this function:

◆ log_1line_Z_GDU()

static void log_1line_Z_GDU ( Z_GDU *  gdu_req,
Z_GDU *  gdu_res,
WRBUF  w 
)
static

Definition at line 496 of file filter_log.cpp.

497{
498 if (gdu_req && gdu_req->which == Z_GDU_Z3950)
499 {
500 log_1line_Z_APDU(gdu_req->u.z3950,
501 (gdu_res && gdu_res->which == Z_GDU_Z3950) ?
502 gdu_res->u.z3950 : 0, w);
503 }
504 else if (gdu_req && gdu_req->which == Z_GDU_HTTP_Request)
505 {
506 log_1line_Z_HTTP(gdu_req->u.HTTP_Request,
507 (gdu_res && gdu_res->which == Z_GDU_HTTP_Response) ?
508 gdu_res->u.HTTP_Response : 0, w);
509 }
510}
static void log_1line_Z_APDU(Z_APDU *z_req, Z_APDU *z_res, WRBUF w)
static void log_1line_Z_HTTP(Z_HTTP_Request *req, Z_HTTP_Response *res, WRBUF w)

References log_1line_Z_APDU(), and log_1line_Z_HTTP().

Referenced by metaproxy_1::filter::Log::Impl::process().

Here is the call graph for this function:

◆ log_1line_Z_HTTP()

static void log_1line_Z_HTTP ( Z_HTTP_Request *  req,
Z_HTTP_Response *  res,
WRBUF  w 
)
static

Definition at line 487 of file filter_log.cpp.

488{
489 wrbuf_printf(w, "%s %s HTTP/%s", req->method, req->path, req->version);
490 if (res)
491 wrbuf_printf(w, " %d %d", res->code, res->content_len);
492 else
493 wrbuf_printf(w, " ?");
494}

Referenced by log_1line_Z_GDU().

◆ log_DefaultDiagFormat()

static void log_DefaultDiagFormat ( WRBUF  w,
Z_DefaultDiagFormat *  e 
)
static

Definition at line 141 of file filter_log.cpp.

142{
143 if (e->condition)
144 wrbuf_printf(w, ODR_INT_PRINTF " ", *e->condition);
145 else
146 wrbuf_puts(w, "?? ");
147 if (e->which == Z_DefaultDiagFormat_v2Addinfo && e->u.v2Addinfo)
148 {
149 wrbuf_puts(w, "\"");
150 wrbuf_puts(w, e->u.v2Addinfo);
151 wrbuf_puts(w, "\"");
152 }
153 else if (e->which == Z_DefaultDiagFormat_v3Addinfo && e->u.v3Addinfo)
154 {
155 wrbuf_puts(w, "\"");
156 wrbuf_puts(w, e->u.v3Addinfo);
157 wrbuf_puts(w, "\"");
158 }
159 else
160 wrbuf_puts(w, "-");
161}

Referenced by log_1line_Z_APDU(), and log_DiagRecs().

◆ log_DiagRecs()

static void log_DiagRecs ( WRBUF  w,
int  num_diagRecs,
Z_DiagRec **  diags 
)
static

Definition at line 163 of file filter_log.cpp.

164{
165 if (diags[0]->which != Z_DiagRec_defaultFormat)
166 wrbuf_puts(w ,"(diag not in default format?)");
167 else
168 {
169 Z_DefaultDiagFormat *e = diags[0]->u.defaultFormat;
171 }
172}

References log_DefaultDiagFormat().

Referenced by log_1line_Z_APDU().

Here is the call graph for this function:

◆ log_syntax()

static void log_syntax ( WRBUF  w,
const Odr_oid *  syntax 
)
static

Definition at line 174 of file filter_log.cpp.

175{
176 if (syntax)
177 {
178 char oid_name[OID_STR_MAX+1];
179 wrbuf_puts(w, yaz_oid_to_string_buf(syntax, 0, oid_name));
180 }
181 else
182 wrbuf_puts(w, "-");
183}

Referenced by log_1line_Z_APDU().

Variable Documentation

◆ metaproxy_1_filter_log

struct metaproxy_1_filter_struct metaproxy_1_filter_log
Initial value:
= {
0,
"log",
}
static mp::filter::Base * filter_creator()

Definition at line 878 of file filter_log.cpp.

878 {
879 0,
880 "log",
882 };

Referenced by metaproxy_1::FactoryStatic::FactoryStatic().