metaproxy  1.21.0
Public Member Functions | Private Attributes | List of all members
metaproxy_1::filter::PresentChunk::Impl Class Reference
Collaboration diagram for metaproxy_1::filter::PresentChunk::Impl:
Collaboration graph

Public Member Functions

 Impl ()
 
 ~Impl ()
 
void process (metaproxy_1::Package &package)
 
void configure (const xmlNode *ptr)
 
void chunk_it (metaproxy_1::Package &package, Z_APDU *apdu)
 

Private Attributes

Odr_int chunk_number
 

Detailed Description

Definition at line 33 of file filter_present_chunk.cpp.

Constructor & Destructor Documentation

◆ Impl()

mp::filter::PresentChunk::Impl::Impl ( )

Definition at line 65 of file filter_present_chunk.cpp.

◆ ~Impl()

mp::filter::PresentChunk::Impl::~Impl ( )

Definition at line 69 of file filter_present_chunk.cpp.

70 {
71 }

Member Function Documentation

◆ chunk_it()

void mp::filter::PresentChunk::Impl::chunk_it ( metaproxy_1::Package &  package,
Z_APDU *  apdu 
)

Definition at line 92 of file filter_present_chunk.cpp.

94 {
95  mp::odr odr;
96  Z_PresentRequest *pr = apdu->u.presentRequest;
97 
98  Odr_int total = *pr->numberOfRecordsRequested;
99  Odr_int start = *pr->resultSetStartPoint;
100  Odr_int offset = 0;
101  Z_NamePlusRecordList *npl = (Z_NamePlusRecordList *)
102  odr_malloc(odr, sizeof(*npl));
103  npl->num_records = total;
104  npl->records = (Z_NamePlusRecord **)
105  odr_malloc(odr, sizeof(*npl->records) * total);
106  while (offset < total)
107  {
108  Odr_int left = total - offset;
109 
110  Package pp(package.session(), package.origin());
111 
112  *pr->numberOfRecordsRequested =
113  left > chunk_number ? chunk_number : left;
114 
115  *pr->resultSetStartPoint = start + offset;
116 
117  pp.copy_filter(package);
118  pp.request() = apdu;
119 
120  pp.move();
121 
122  if (pp.session().is_closed())
123  {
124  package.session().close();
125  return;
126  }
127  Z_GDU *gdu_res = pp.response().get();
128  if (gdu_res && gdu_res->which == Z_GDU_Z3950 &&
129  gdu_res->u.z3950->which == Z_APDU_presentResponse)
130  {
131  Z_PresentResponse *pres =
132  gdu_res->u.z3950->u.presentResponse;
133  if (pres->records &&
134  pres->records->which == Z_Records_DBOSD)
135  {
136  Z_NamePlusRecordList *nprl =
137  pres->records->u.databaseOrSurDiagnostics;
138  int i;
139  for (i = 0; i < nprl->num_records; i++)
140  {
141  ODR o = odr;
142  npl->records[offset+i] = yaz_clone_z_NamePlusRecord(
143  nprl->records[i], o->mem);
144  }
145  offset += nprl->num_records;
146  }
147  else
148  {
149  package.response() = pp.response();
150  return;
151  }
152  }
153  else
154  {
155  package.response() = pp.response();
156  return;
157  }
158  }
159 
160  yaz_log(YLOG_LOG, "building response . %lld", offset);
161 
162  Z_APDU *a = zget_APDU(odr, Z_APDU_presentResponse);
163  Z_PresentResponse *pres = a->u.presentResponse;
164  pres->records = (Z_Records *)
165  odr_malloc(odr, sizeof(Z_Records));
166  pres->records->which = Z_Records_DBOSD;
167  pres->records->u.databaseOrSurDiagnostics = npl;
168  npl->num_records = offset;
169  *pres->numberOfRecordsReturned = offset;
170 
171  package.response() = a;
172 }

◆ configure()

void mp::filter::PresentChunk::Impl::configure ( const xmlNode *  ptr)

Definition at line 73 of file filter_present_chunk.cpp.

74 {
75  for (ptr = ptr->children; ptr; ptr = ptr->next)
76  {
77  if (ptr->type != XML_ELEMENT_NODE)
78  continue;
79  if (!strcmp((const char *) ptr->name, "chunk"))
80  {
81  chunk_number = mp::xml::get_int(ptr, 0);
82  }
83  else
84  {
85  throw mp::filter::FilterException("Bad element "
86  + std::string((const char *)
87  ptr->name));
88  }
89  }
90 }

◆ process()

void mp::filter::PresentChunk::Impl::process ( metaproxy_1::Package &  package)

Definition at line 174 of file filter_present_chunk.cpp.

175 {
176  Z_GDU *gdu = package.request().get();
177  if (gdu && gdu->which == Z_GDU_Z3950)
178  {
179  Z_APDU *apdu = gdu->u.z3950;
180  if (apdu->which == Z_APDU_presentRequest && chunk_number > 0)
181  chunk_it(package, apdu);
182  else
183  package.move();
184  }
185  else
186  package.move();
187 }
void chunk_it(metaproxy_1::Package &package, Z_APDU *apdu)

Member Data Documentation

◆ chunk_number

Odr_int metaproxy_1::filter::PresentChunk::Impl::chunk_number
private

Definition at line 41 of file filter_present_chunk.cpp.


The documentation for this class was generated from the following file: