747641706353ea458ccfcc8f3abe867603430145
[metaproxy-moved-to-github.git] / src / filter_zoom.cpp
1 /* This file is part of Metaproxy.
2    Copyright (C) 2005-2011 Index Data
3
4 Metaproxy is free software; you can redistribute it and/or modify it under
5 the terms of the GNU General Public License as published by the Free
6 Software Foundation; either version 2, or (at your option) any later
7 version.
8
9 Metaproxy is distributed in the hope that it will be useful, but WITHOUT ANY
10 WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12 for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
17 */
18
19 #include "config.hpp"
20 #include "filter_zoom.hpp"
21 #include <yaz/zoom.h>
22 #include <yaz/yaz-version.h>
23 #include <yaz/tpath.h>
24 #include <yaz/srw.h>
25 #include <metaproxy/package.hpp>
26 #include <metaproxy/util.hpp>
27 #include <metaproxy/xmlutil.hpp>
28 #include "torus.hpp"
29
30 #include <libxslt/xsltutils.h>
31 #include <libxslt/transform.h>
32
33 #include <boost/thread/mutex.hpp>
34 #include <boost/thread/condition.hpp>
35 #include <yaz/ccl_xml.h>
36 #include <yaz/ccl.h>
37 #include <yaz/rpn2cql.h>
38 #include <yaz/rpn2solr.h>
39 #include <yaz/pquery.h>
40 #include <yaz/cql.h>
41 #include <yaz/oid_db.h>
42 #include <yaz/diagbib1.h>
43 #include <yaz/log.h>
44 #include <yaz/zgdu.h>
45 #include <yaz/querytowrbuf.h>
46
47 namespace mp = metaproxy_1;
48 namespace yf = mp::filter;
49
50 namespace metaproxy_1 {
51     namespace filter {
52         struct Zoom::Searchable : boost::noncopyable {
53             std::string authentication;
54             std::string cfAuth;
55             std::string cfProxy;
56             std::string cfSubDb;
57             std::string udb;
58             std::string target;
59             std::string query_encoding;
60             std::string sru;
61             std::string request_syntax;
62             std::string element_set;
63             std::string record_encoding;
64             std::string transform_xsl_fname;
65             std::string urlRecipe;
66             std::string contentConnector;
67             bool use_turbomarc;
68             bool piggyback;
69             CCL_bibset ccl_bibset;
70             Searchable(CCL_bibset base);
71             ~Searchable();
72         };
73         class Zoom::Backend : boost::noncopyable {
74             friend class Impl;
75             friend class Frontend;
76             std::string zurl;
77             ZOOM_connection m_connection;
78             ZOOM_resultset m_resultset;
79             std::string m_frontend_database;
80             SearchablePtr sptr;
81             xsltStylesheetPtr xsp;
82         public:
83             Backend(SearchablePtr sptr);
84             ~Backend();
85             void connect(std::string zurl, int *error, char **addinfo,
86                          ODR odr);
87             void search_pqf(const char *pqf, Odr_int *hits,
88                             int *error, char **addinfo, ODR odr);
89             void search_cql(const char *cql, Odr_int *hits,
90                             int *error, char **addinfo, ODR odr);
91             void present(Odr_int start, Odr_int number, ZOOM_record *recs,
92                          int *error, char **addinfo, ODR odr);
93             void set_option(const char *name, const char *value);
94             const char *get_option(const char *name);
95             void get_zoom_error(int *error, char **addinfo, ODR odr);
96         };
97         class Zoom::Frontend : boost::noncopyable {
98             friend class Impl;
99             Impl *m_p;
100             bool m_is_virtual;
101             bool m_in_use;
102             yazpp_1::GDU m_init_gdu;
103             BackendPtr m_backend;
104             void handle_package(mp::Package &package);
105             void handle_search(mp::Package &package);
106             void handle_present(mp::Package &package);
107             BackendPtr get_backend_from_databases(std::string &database,
108                                                   int *error,
109                                                   char **addinfo,
110                                                   ODR odr);
111             Z_Records *get_records(Odr_int start,
112                                    Odr_int number_to_present,
113                                    int *error,
114                                    char **addinfo,
115                                    Odr_int *number_of_records_returned,
116                                    ODR odr, BackendPtr b,
117                                    Odr_oid *preferredRecordSyntax,
118                                    const char *element_set_name);
119         public:
120             Frontend(Impl *impl);
121             ~Frontend();
122         };
123         class Zoom::Impl {
124             friend class Frontend;
125         public:
126             Impl();
127             ~Impl();
128             void process(metaproxy_1::Package & package);
129             void configure(const xmlNode * ptr, bool test_only,
130                            const char *path);
131         private:
132             void configure_local_records(const xmlNode * ptr, bool test_only);
133             FrontendPtr get_frontend(mp::Package &package);
134             void release_frontend(mp::Package &package);
135             SearchablePtr parse_torus_record(const xmlNode *ptr);
136             struct cql_node *convert_cql_fields(struct cql_node *cn, ODR odr);
137             std::map<mp::Session, FrontendPtr> m_clients;            
138             boost::mutex m_mutex;
139             boost::condition m_cond_session_ready;
140             std::string torus_url;
141             std::map<std::string,std::string> fieldmap;
142             std::string xsldir;
143             std::string file_path;
144             std::string content_proxy_server;
145             CCL_bibset bibset;
146             std::string element_transform;
147             std::string element_raw;
148             std::map<std::string,SearchablePtr> s_map;
149         };
150     }
151 }
152
153 // define Pimpl wrapper forwarding to Impl
154  
155 yf::Zoom::Zoom() : m_p(new Impl)
156 {
157 }
158
159 yf::Zoom::~Zoom()
160 {  // must have a destructor because of boost::scoped_ptr
161 }
162
163 void yf::Zoom::configure(const xmlNode *xmlnode, bool test_only,
164                          const char *path)
165 {
166     m_p->configure(xmlnode, test_only, path);
167 }
168
169 void yf::Zoom::process(mp::Package &package) const
170 {
171     m_p->process(package);
172 }
173
174
175 // define Implementation stuff
176
177 yf::Zoom::Backend::Backend(SearchablePtr ptr) : sptr(ptr)
178 {
179     m_connection = ZOOM_connection_create(0);
180     m_resultset = 0;
181     xsp = 0;
182 }
183
184 yf::Zoom::Backend::~Backend()
185 {
186     if (xsp)
187         xsltFreeStylesheet(xsp);
188     ZOOM_connection_destroy(m_connection);
189     ZOOM_resultset_destroy(m_resultset);
190 }
191
192
193 void yf::Zoom::Backend::get_zoom_error(int *error, char **addinfo,
194                                        ODR odr)
195 {
196     const char *msg = 0;
197     const char *zoom_addinfo = 0;
198     *error = ZOOM_connection_error(m_connection, &msg, &zoom_addinfo);
199     if (*error)
200     {
201         if (*error >= ZOOM_ERROR_CONNECT)
202         {
203             // turn ZOOM diagnostic into a Bib-1 2: with addinfo=zoom err msg
204             *error = YAZ_BIB1_TEMPORARY_SYSTEM_ERROR;
205             *addinfo = (char *) odr_malloc(
206                 odr, 20 + strlen(msg) + 
207                 (zoom_addinfo ? strlen(zoom_addinfo) : 0));
208             strcpy(*addinfo, msg);
209             if (zoom_addinfo)
210             {
211                 strcat(*addinfo, ": ");
212                 strcat(*addinfo, zoom_addinfo);
213                 strcat(*addinfo, " ");
214             }
215         }
216         else
217         {
218             *addinfo = (char *) odr_malloc(
219                 odr, 20 + (zoom_addinfo ? strlen(zoom_addinfo) : 0));
220             **addinfo = '\0';
221             if (zoom_addinfo && *zoom_addinfo)
222             {
223                 strcpy(*addinfo, zoom_addinfo);
224                 strcat(*addinfo, " ");
225             }
226             strcat(*addinfo, "(backend)");
227         }
228     }
229 }
230
231 void yf::Zoom::Backend::connect(std::string zurl,
232                                 int *error, char **addinfo,
233                                 ODR odr)
234 {
235     ZOOM_connection_connect(m_connection, zurl.c_str(), 0);
236     get_zoom_error(error, addinfo, odr);
237 }
238
239 void yf::Zoom::Backend::search_pqf(const char *pqf, Odr_int *hits,
240                                    int *error, char **addinfo, ODR odr)
241 {
242     m_resultset = ZOOM_connection_search_pqf(m_connection, pqf);
243     get_zoom_error(error, addinfo, odr);
244     if (*error == 0)
245         *hits = ZOOM_resultset_size(m_resultset);
246     else
247         *hits = 0;
248 }
249
250 void yf::Zoom::Backend::search_cql(const char *cql, Odr_int *hits,
251                                    int *error, char **addinfo, ODR odr)
252 {
253     ZOOM_query q = ZOOM_query_create();
254
255     ZOOM_query_cql(q, cql);
256
257     m_resultset = ZOOM_connection_search(m_connection, q);
258     ZOOM_query_destroy(q);
259     get_zoom_error(error, addinfo, odr);
260     if (*error == 0)
261         *hits = ZOOM_resultset_size(m_resultset);
262     else
263         *hits = 0;
264 }
265
266 void yf::Zoom::Backend::present(Odr_int start, Odr_int number,
267                                 ZOOM_record *recs,
268                                 int *error, char **addinfo, ODR odr)
269 {
270     ZOOM_resultset_records(m_resultset, recs, start, number);
271     get_zoom_error(error, addinfo, odr);
272 }
273
274 void yf::Zoom::Backend::set_option(const char *name, const char *value)
275 {
276     ZOOM_connection_option_set(m_connection, name, value);
277     if (m_resultset)
278         ZOOM_resultset_option_set(m_resultset, name, value);
279 }
280
281 const char *yf::Zoom::Backend::get_option(const char *name)
282 {
283     return ZOOM_connection_option_get(m_connection, name);
284 }
285
286 yf::Zoom::Searchable::Searchable(CCL_bibset base)
287 {
288     piggyback = true;
289     use_turbomarc = true;
290     ccl_bibset = ccl_qual_dup(base);
291 }
292
293 yf::Zoom::Searchable::~Searchable()
294 {
295     ccl_qual_rm(&ccl_bibset);
296 }
297
298 yf::Zoom::Frontend::Frontend(Impl *impl) : 
299     m_p(impl), m_is_virtual(false), m_in_use(true)
300 {
301 }
302
303 yf::Zoom::Frontend::~Frontend()
304 {
305 }
306
307 yf::Zoom::FrontendPtr yf::Zoom::Impl::get_frontend(mp::Package &package)
308 {
309     boost::mutex::scoped_lock lock(m_mutex);
310
311     std::map<mp::Session,yf::Zoom::FrontendPtr>::iterator it;
312     
313     while(true)
314     {
315         it = m_clients.find(package.session());
316         if (it == m_clients.end())
317             break;
318         
319         if (!it->second->m_in_use)
320         {
321             it->second->m_in_use = true;
322             return it->second;
323         }
324         m_cond_session_ready.wait(lock);
325     }
326     FrontendPtr f(new Frontend(this));
327     m_clients[package.session()] = f;
328     f->m_in_use = true;
329     return f;
330 }
331
332 void yf::Zoom::Impl::release_frontend(mp::Package &package)
333 {
334     boost::mutex::scoped_lock lock(m_mutex);
335     std::map<mp::Session,yf::Zoom::FrontendPtr>::iterator it;
336     
337     it = m_clients.find(package.session());
338     if (it != m_clients.end())
339     {
340         if (package.session().is_closed())
341         {
342             m_clients.erase(it);
343         }
344         else
345         {
346             it->second->m_in_use = false;
347         }
348         m_cond_session_ready.notify_all();
349     }
350 }
351
352 yf::Zoom::Impl::Impl() : element_transform("pz2") , element_raw("raw")
353 {
354     bibset = ccl_qual_mk();
355 }
356
357 yf::Zoom::Impl::~Impl()
358
359     ccl_qual_rm(&bibset);
360 }
361
362 yf::Zoom::SearchablePtr yf::Zoom::Impl::parse_torus_record(const xmlNode *ptr)
363 {
364     Zoom::SearchablePtr s(new Searchable(bibset));
365     
366     for (ptr = ptr->children; ptr; ptr = ptr->next)
367     {
368         if (ptr->type != XML_ELEMENT_NODE)
369             continue;
370         if (!strcmp((const char *) ptr->name, "layer"))
371             ptr = ptr->children;
372         else if (!strcmp((const char *) ptr->name,
373                          "authentication"))
374         {
375             s->authentication = mp::xml::get_text(ptr);
376         }
377         else if (!strcmp((const char *) ptr->name,
378                          "cfAuth"))
379         {
380             s->cfAuth = mp::xml::get_text(ptr);
381         } 
382         else if (!strcmp((const char *) ptr->name,
383                          "cfProxy"))
384         {
385             s->cfProxy = mp::xml::get_text(ptr);
386         }  
387         else if (!strcmp((const char *) ptr->name,
388                          "cfSubDb"))
389         {
390             s->cfSubDb = mp::xml::get_text(ptr);
391         }  
392         else if (!strcmp((const char *) ptr->name,
393                          "contentConnector"))
394         {
395             s->contentConnector = mp::xml::get_text(ptr);
396         }  
397         else if (!strcmp((const char *) ptr->name, "udb"))
398         {
399             s->udb = mp::xml::get_text(ptr);
400         }
401         else if (!strcmp((const char *) ptr->name, "zurl"))
402         {
403             s->target = mp::xml::get_text(ptr);
404         }
405         else if (!strcmp((const char *) ptr->name, "sru"))
406         {
407             s->sru = mp::xml::get_text(ptr);
408         }
409         else if (!strcmp((const char *) ptr->name,
410                          "queryEncoding"))
411         {
412             s->query_encoding = mp::xml::get_text(ptr);
413         }
414         else if (!strcmp((const char *) ptr->name,
415                          "piggyback"))
416         {
417             s->piggyback = mp::xml::get_bool(ptr, true);
418         }
419         else if (!strcmp((const char *) ptr->name,
420                          "requestSyntax"))
421         {
422             s->request_syntax = mp::xml::get_text(ptr);
423         }
424         else if (!strcmp((const char *) ptr->name,
425                          "elementSet"))
426         {
427             s->element_set = mp::xml::get_text(ptr);
428         }
429         else if (!strcmp((const char *) ptr->name,
430                          "recordEncoding"))
431         {
432             s->record_encoding = mp::xml::get_text(ptr);
433         }
434         else if (!strcmp((const char *) ptr->name,
435                          "transform"))
436         {
437             s->transform_xsl_fname = mp::xml::get_text(ptr);
438         }
439         else if (!strcmp((const char *) ptr->name,
440                          "urlRecipe"))
441         {
442             s->urlRecipe = mp::xml::get_text(ptr);
443         }
444         else if (!strcmp((const char *) ptr->name,
445                          "useTurboMarc"))
446         {
447             ; // useTurboMarc is ignored
448         }
449         else if (!strncmp((const char *) ptr->name,
450                           "cclmap_", 7))
451         {
452             std::string value = mp::xml::get_text(ptr);
453             ccl_qual_fitem(s->ccl_bibset, value.c_str(),
454                            (const char *) ptr->name + 7);
455         }
456     }
457     return s;
458 }
459
460 void yf::Zoom::Impl::configure_local_records(const xmlNode *ptr, bool test_only)
461 {
462     while (ptr && ptr->type != XML_ELEMENT_NODE)
463         ptr = ptr->next;
464     
465     if (ptr)
466     {
467         if (!strcmp((const char *) ptr->name, "records"))
468         {
469             for (ptr = ptr->children; ptr; ptr = ptr->next)
470             {
471                 if (ptr->type != XML_ELEMENT_NODE)
472                     continue;
473                 if (!strcmp((const char *) ptr->name, "record"))
474                 {
475                     SearchablePtr s = parse_torus_record(ptr);
476                     if (s)
477                     {
478                         std::string udb = s->udb;
479                         if (udb.length())
480                             s_map[s->udb] = s;
481                         else
482                         {
483                             throw mp::filter::FilterException
484                                 ("No udb for local torus record");
485                         }
486                     }
487                 }
488                 else
489                 {
490                     throw mp::filter::FilterException
491                         ("Bad element " 
492                          + std::string((const char *) ptr->name)
493                          + " in zoom filter inside element "
494                          "<torus><records>");
495                 }
496             }
497         }
498         else
499         {
500             throw mp::filter::FilterException
501                 ("Bad element " 
502                  + std::string((const char *) ptr->name)
503                  + " in zoom filter inside element <torus>");
504         }
505     }
506 }
507
508 void yf::Zoom::Impl::configure(const xmlNode *ptr, bool test_only,
509                                const char *path)
510 {
511     if (path && *path)
512     {
513         file_path = path;
514     }
515     for (ptr = ptr->children; ptr; ptr = ptr->next)
516     {
517         if (ptr->type != XML_ELEMENT_NODE)
518             continue;
519         else if (!strcmp((const char *) ptr->name, "torus"))
520         {
521             const struct _xmlAttr *attr;
522             for (attr = ptr->properties; attr; attr = attr->next)
523             {
524                 if (!strcmp((const char *) attr->name, "url"))
525                     torus_url = mp::xml::get_text(attr->children);
526                 else if (!strcmp((const char *) attr->name, "xsldir"))
527                     xsldir = mp::xml::get_text(attr->children);
528                 else if (!strcmp((const char *) attr->name, "element_transform"))
529                     element_transform = mp::xml::get_text(attr->children);
530                 else if (!strcmp((const char *) attr->name, "element_raw"))
531                     element_raw = mp::xml::get_text(attr->children);
532                 else
533                     throw mp::filter::FilterException(
534                         "Bad attribute " + std::string((const char *)
535                                                        attr->name));
536             }
537             configure_local_records(ptr->children, test_only);
538         }
539         else if (!strcmp((const char *) ptr->name, "cclmap"))
540         {
541             const char *addinfo = 0;
542             ccl_xml_config(bibset, ptr, &addinfo);
543         }
544         else if (!strcmp((const char *) ptr->name, "fieldmap"))
545         {
546             const struct _xmlAttr *attr;
547             std::string ccl_field;
548             std::string cql_field;
549             for (attr = ptr->properties; attr; attr = attr->next)
550             {
551                 if (!strcmp((const char *) attr->name, "ccl"))
552                     ccl_field = mp::xml::get_text(attr->children);
553                 else if (!strcmp((const char *) attr->name, "cql"))
554                     cql_field = mp::xml::get_text(attr->children);
555                 else
556                     throw mp::filter::FilterException(
557                         "Bad attribute " + std::string((const char *)
558                                                        attr->name));
559             }
560             if (cql_field.length())
561                 fieldmap[cql_field] = ccl_field;
562         }
563         else if (!strcmp((const char *) ptr->name, "contentProxy"))
564         {
565             const struct _xmlAttr *attr;
566             for (attr = ptr->properties; attr; attr = attr->next)
567             {
568                 if (!strcmp((const char *) attr->name, "server"))
569                     content_proxy_server = mp::xml::get_text(attr->children);
570                 else
571                     throw mp::filter::FilterException(
572                         "Bad attribute " + std::string((const char *)
573                                                        attr->name));
574             }
575         }
576         else
577         {
578             throw mp::filter::FilterException
579                 ("Bad element " 
580                  + std::string((const char *) ptr->name)
581                  + " in zoom filter");
582         }
583     }
584 }
585
586 yf::Zoom::BackendPtr yf::Zoom::Frontend::get_backend_from_databases(
587     std::string &database, int *error, char **addinfo, ODR odr)
588 {
589     std::list<BackendPtr>::const_iterator map_it;
590     if (m_backend && m_backend->m_frontend_database == database)
591         return m_backend;
592
593     const char *sru_proxy = 0;
594     std::string db_args;
595     std::string torus_db;
596     size_t db_arg_pos = database.find(',');
597     if (db_arg_pos != std::string::npos)
598     {
599         torus_db = database.substr(0, db_arg_pos);
600         db_args = database.substr(db_arg_pos + 1);
601     }
602     else
603         torus_db = database;
604  
605     SearchablePtr sptr;
606
607     std::map<std::string,SearchablePtr>::iterator it;
608     it = m_p->s_map.find(torus_db);
609     if (it != m_p->s_map.end())
610         sptr = it->second;
611     else
612     {
613         xmlDoc *doc = mp::get_searchable(m_p->torus_url, torus_db);
614         if (!doc)
615         {
616             *error = YAZ_BIB1_DATABASE_DOES_NOT_EXIST;
617             *addinfo = odr_strdup(odr, database.c_str());
618             BackendPtr b;
619             return b;
620         }
621         const xmlNode *ptr = xmlDocGetRootElement(doc);
622         if (ptr)
623         {   // presumably ptr is a records element node
624             // parse first record in document
625             for (ptr = ptr->children; ptr; ptr = ptr->next)
626             {
627                 if (ptr->type == XML_ELEMENT_NODE
628                     && !strcmp((const char *) ptr->name, "record"))
629                 {
630                     sptr = m_p->parse_torus_record(ptr);
631                     break;
632                 }
633             }
634         }
635         xmlFreeDoc(doc);
636     }
637
638     if (!sptr)
639     {
640         *error = YAZ_BIB1_DATABASE_DOES_NOT_EXIST;
641         *addinfo = odr_strdup(odr, database.c_str());
642         BackendPtr b;
643         return b;
644     }
645         
646     xsltStylesheetPtr xsp = 0;
647     if (sptr->transform_xsl_fname.length())
648     {
649         const char *path = 0;
650
651         if (m_p->xsldir.length())
652             path = m_p->xsldir.c_str();
653         else
654             path = m_p->file_path.c_str();
655         std::string fname;
656
657         char fullpath[1024];
658         char *cp = yaz_filepath_resolve(sptr->transform_xsl_fname.c_str(),
659                                         path, 0, fullpath);
660         if (cp)
661             fname.assign(cp);
662         else
663         {
664             *error = YAZ_BIB1_TEMPORARY_SYSTEM_ERROR;
665             *addinfo = (char *)
666                 odr_malloc(odr, 40 + sptr->transform_xsl_fname.length());
667             sprintf(*addinfo, "File could not be read: %s", 
668                     sptr->transform_xsl_fname.c_str());
669             BackendPtr b;
670             return b;
671         }
672         xmlDoc *xsp_doc = xmlParseFile(fname.c_str());
673         if (!xsp_doc)
674         {
675             *error = YAZ_BIB1_TEMPORARY_SYSTEM_ERROR;
676             *addinfo = (char *) odr_malloc(odr, 40 + fname.length());
677             sprintf(*addinfo, "xmlParseFile failed. File: %s", fname.c_str());
678             BackendPtr b;
679             return b;
680         }
681         xsp = xsltParseStylesheetDoc(xsp_doc);
682         if (!xsp)
683         {
684             *error = YAZ_BIB1_DATABASE_DOES_NOT_EXIST;
685             *addinfo = odr_strdup(odr, "xsltParseStylesheetDoc failed");
686             BackendPtr b;
687             xmlFreeDoc(xsp_doc);
688             return b;
689         }
690     }
691
692     m_backend.reset();
693
694     BackendPtr b(new Backend(sptr));
695
696     b->xsp = xsp;
697     b->m_frontend_database = database;
698     std::string authentication = sptr->authentication;
699         
700     b->set_option("timeout", "40");
701
702     if (sptr->query_encoding.length())
703         b->set_option("rpnCharset", sptr->query_encoding.c_str());
704
705     if (sptr->cfAuth.length())
706     {
707         // A CF target
708         b->set_option("user", sptr->cfAuth.c_str());
709         if (db_args.length() == 0)
710         {
711             if (authentication.length())
712             {
713                 // no database (auth) args specified already.. and the
714                 // Torus authentication has it.. Generate the args that CF
715                 // understands..
716                 size_t found = authentication.find('/');
717                 if (found != std::string::npos)
718                 {
719                     db_args += "user=" + mp::util::uri_encode(authentication.substr(0, found))
720                         + "&password=" + mp::util::uri_encode(authentication.substr(found+1));
721                 }
722                 else
723                     db_args += "user=" + mp::util::uri_encode(authentication);
724             }
725             if (sptr->cfProxy.length())
726             {
727                 if (db_args.length())
728                     db_args += "&";
729                 db_args += "proxy=" + mp::util::uri_encode(sptr->cfProxy);
730             }
731         }
732         if (sptr->cfSubDb.length())
733         {
734             if (db_args.length())
735                 db_args += "&";
736             db_args += "subdatabase=" + mp::util::uri_encode(sptr->cfSubDb);
737         }
738     }
739     else
740     {
741         // A non-CF target
742         if (db_args.length())
743         {
744             // user has specified backend authentication
745             const char *param_user = 0;
746             const char *param_password = 0;
747             char **names;
748             char **values;
749             int i;
750             int no_parms = yaz_uri_to_array(db_args.c_str(),
751                                             odr, &names, &values);
752             for (i = 0; i < no_parms; i++)
753             {
754                 const char *name = names[i];
755                 const char *value = values[i];
756                 if (!strcmp(name, "user"))
757                     param_user = value;
758                 else if (!strcmp(name, "password"))
759                     param_password = value;
760                 else if (!strcmp(name, "proxy"))
761                     sru_proxy = value;
762                 else
763                 {
764                     BackendPtr notfound;
765                     char *msg = (char*) odr_malloc(odr, strlen(name) + 30);
766                     *error = YAZ_BIB1_TEMPORARY_SYSTEM_ERROR;
767                     sprintf(msg, "Bad database argument: %s", name);
768                     *addinfo = msg;
769                     return notfound;
770                 }
771             }
772             if (param_user && param_password)
773             {
774                 char *auth = (char*) odr_malloc(
775                     odr, strlen(param_user) + strlen(param_password) + 2);
776                 strcpy(auth, param_user);
777                 strcat(auth, "/");
778                 strcat(auth, param_password);
779                 b->set_option("user", auth);
780             }
781             db_args.clear(); // no arguments to be passed (non-CF)
782         }
783         else
784         {
785             // use authentication from Torus, if given
786             if (authentication.length())
787                 b->set_option("user", authentication.c_str());
788         }
789     }
790
791     if (sru_proxy)
792         b->set_option("proxy", sru_proxy);
793
794     std::string url;
795     if (sptr->sru.length())
796     {
797         url = "http://" + sptr->target;
798         b->set_option("sru", sptr->sru.c_str());
799     }
800     else
801     {
802         url = sptr->target;
803     }
804     if (db_args.length())
805         url += "," + db_args;
806     yaz_log(YLOG_LOG, "url=%s", url.c_str());
807     b->connect(url, error, addinfo, odr);
808     if (*error == 0)
809     {
810         m_backend = b;
811     }
812     return b;
813 }
814
815 Z_Records *yf::Zoom::Frontend::get_records(Odr_int start,
816                                            Odr_int number_to_present,
817                                            int *error,
818                                            char **addinfo,
819                                            Odr_int *number_of_records_returned,
820                                            ODR odr,
821                                            BackendPtr b,
822                                            Odr_oid *preferredRecordSyntax,
823                                            const char *element_set_name)
824 {
825     *number_of_records_returned = 0;
826     Z_Records *records = 0;
827     bool enable_pz2_retrieval = false; // whether target profile is used
828     bool enable_pz2_transform = false; // whether XSLT is used as well
829     bool assume_marc8_charset = false;
830
831     if (start < 0 || number_to_present <= 0)
832         return records;
833     
834     if (number_to_present > 10000)
835         number_to_present = 10000;
836     
837     ZOOM_record *recs = (ZOOM_record *)
838         odr_malloc(odr, number_to_present * sizeof(*recs));
839
840     char oid_name_str[OID_STR_MAX];
841     const char *syntax_name = 0;
842     
843     if (preferredRecordSyntax &&
844         !oid_oidcmp(preferredRecordSyntax, yaz_oid_recsyn_xml)
845         && element_set_name)
846     {
847         if (!strcmp(element_set_name, m_p->element_transform.c_str()))
848         {
849             enable_pz2_retrieval = true;
850             enable_pz2_transform = true;
851         }
852         else if (!strcmp(element_set_name, m_p->element_raw.c_str()))
853         {
854             enable_pz2_retrieval = true;
855         }
856     }
857     
858     if (enable_pz2_retrieval)
859     {
860         if (b->sptr->request_syntax.length())
861         {
862             syntax_name = b->sptr->request_syntax.c_str();
863             const Odr_oid *syntax_oid = 
864                 yaz_string_to_oid(yaz_oid_std(), CLASS_RECSYN, syntax_name);
865             if (!oid_oidcmp(syntax_oid, yaz_oid_recsyn_usmarc)
866                 || !oid_oidcmp(syntax_oid, yaz_oid_recsyn_opac))
867                 assume_marc8_charset = true;
868         }
869     }
870     else if (preferredRecordSyntax)
871         syntax_name =
872             yaz_oid_to_string_buf(preferredRecordSyntax, 0, oid_name_str);
873
874     b->set_option("preferredRecordSyntax", syntax_name);
875
876     if (enable_pz2_retrieval)
877     {
878         element_set_name = 0;
879         if (b->sptr->element_set.length())
880             element_set_name = b->sptr->element_set.c_str();
881     }
882
883     b->set_option("elementSetName", element_set_name);
884
885     b->present(start, number_to_present, recs, error, addinfo, odr);
886
887     Odr_int i = 0;
888     if (!*error)
889     {
890         for (i = 0; i < number_to_present; i++)
891             if (!recs[i])
892                 break;
893     }
894     if (i > 0)
895     {  // only return records if no error and at least one record
896         char *odr_database = odr_strdup(odr,
897                                         b->m_frontend_database.c_str());
898         Z_NamePlusRecordList *npl = (Z_NamePlusRecordList *)
899             odr_malloc(odr, sizeof(*npl));
900         *number_of_records_returned = i;
901         npl->num_records = i;
902         npl->records = (Z_NamePlusRecord **)
903             odr_malloc(odr, i * sizeof(*npl->records));
904         for (i = 0; i < number_to_present; i++)
905         {
906             Z_NamePlusRecord *npr = 0;
907             const char *addinfo;
908             int sur_error = ZOOM_record_error(recs[i], 0 /* msg */,
909                                               &addinfo, 0 /* diagset */);
910                 
911             if (sur_error)
912             {
913                 npr = zget_surrogateDiagRec(odr, odr_database, sur_error,
914                                             addinfo);
915             }
916             else if (enable_pz2_retrieval)
917             {
918                 char rec_type_str[100];
919                 const char *record_encoding = 0;
920
921                 if (b->sptr->record_encoding.length())
922                     record_encoding = b->sptr->record_encoding.c_str();
923                 else if (assume_marc8_charset)
924                     record_encoding = "marc8";
925
926                 strcpy(rec_type_str, b->sptr->use_turbomarc ? "txml" : "xml");
927                 if (record_encoding)
928                 {
929                     strcat(rec_type_str, "; charset=");
930                     strcat(rec_type_str, record_encoding);
931                 }
932                 
933                 int rec_len;
934                 xmlChar *xmlrec_buf = 0;
935                 const char *rec_buf = ZOOM_record_get(recs[i], rec_type_str,
936                                                       &rec_len);
937                 if (rec_buf && b->xsp && enable_pz2_transform)
938                 {
939                     xmlDoc *rec_doc = xmlParseMemory(rec_buf, rec_len);
940                     if (rec_doc)
941                     { 
942                         xmlDoc *rec_res;
943                         rec_res = xsltApplyStylesheet(b->xsp, rec_doc, 0);
944
945                         if (rec_res)
946                             xsltSaveResultToString(&xmlrec_buf, &rec_len,
947                                                    rec_res, b->xsp);
948                         rec_buf = (const char *) xmlrec_buf;
949                         xmlFreeDoc(rec_doc);
950                         xmlFreeDoc(rec_res);
951                     }
952                 }
953
954                 if (rec_buf)
955                 {
956                     xmlDoc *doc = xmlParseMemory(rec_buf, rec_len);
957                     std::string res = 
958                         mp::xml::url_recipe_handle(doc, b->sptr->urlRecipe);
959                     if (res.length() && b->sptr->contentConnector.length())
960                     {
961                         yaz_log(YLOG_LOG, "contentConnector: %s",
962                                 b->sptr->contentConnector.c_str());
963                         size_t off = res.find_first_of("://");
964                         if (off != std::string::npos)
965                         {
966                             char tmp[1024];
967                             long id = 12345;
968                             sprintf(tmp, "%ld.%s/",
969                                     id, m_p->content_proxy_server.c_str());
970                             res.insert(off + 3, tmp);
971                         }
972                     }
973                     if (res.length())
974                     {
975                         xmlNode *ptr = xmlDocGetRootElement(doc);
976                         while (ptr && ptr->type != XML_ELEMENT_NODE)
977                             ptr = ptr->next;
978                         xmlNode *c = 
979                             xmlNewChild(ptr, 0, BAD_CAST "generated-url", 0);
980                         xmlNode * t = xmlNewText(BAD_CAST res.c_str());
981                         xmlAddChild(c, t);
982
983                         if (xmlrec_buf)
984                             xmlFree(xmlrec_buf);
985
986                         xmlDocDumpMemory(doc, &xmlrec_buf, &rec_len);
987                         rec_buf = (const char *) xmlrec_buf;
988                     }
989                     xmlFreeDoc(doc);
990                 }
991                 if (rec_buf)
992                 {
993                     npr = (Z_NamePlusRecord *) odr_malloc(odr, sizeof(*npr));
994                     npr->databaseName = odr_database;
995                     npr->which = Z_NamePlusRecord_databaseRecord;
996                     npr->u.databaseRecord =
997                         z_ext_record_xml(odr, rec_buf, rec_len);
998                 }
999                 else
1000                 {
1001                     npr = zget_surrogateDiagRec(
1002                         odr, odr_database, 
1003                         YAZ_BIB1_SYSTEM_ERROR_IN_PRESENTING_RECORDS,
1004                         rec_type_str);
1005                 }
1006                 if (xmlrec_buf)
1007                     xmlFree(xmlrec_buf);
1008             }
1009             else
1010             {
1011                 Z_External *ext =
1012                     (Z_External *) ZOOM_record_get(recs[i], "ext", 0);
1013                 if (ext)
1014                 {
1015                     npr = (Z_NamePlusRecord *) odr_malloc(odr, sizeof(*npr));
1016                     npr->databaseName = odr_database;
1017                     npr->which = Z_NamePlusRecord_databaseRecord;
1018                     npr->u.databaseRecord = ext;
1019                 }
1020                 else
1021                 {
1022                     npr = zget_surrogateDiagRec(
1023                         odr, odr_database, 
1024                         YAZ_BIB1_SYSTEM_ERROR_IN_PRESENTING_RECORDS,
1025                         "ZOOM_record, type ext");
1026                 }
1027             }
1028             npl->records[i] = npr;
1029         }
1030         records = (Z_Records*) odr_malloc(odr, sizeof(*records));
1031         records->which = Z_Records_DBOSD;
1032         records->u.databaseOrSurDiagnostics = npl;
1033     }
1034     return records;
1035 }
1036     
1037 struct cql_node *yf::Zoom::Impl::convert_cql_fields(struct cql_node *cn,
1038                                                     ODR odr)
1039 {
1040     struct cql_node *r = 0;
1041     if (!cn)
1042         return 0;
1043     switch (cn->which)
1044     {
1045     case CQL_NODE_ST:
1046         if (cn->u.st.index)
1047         {
1048             std::map<std::string,std::string>::const_iterator it;
1049             it = fieldmap.find(cn->u.st.index);
1050             if (it == fieldmap.end())
1051                 return cn;
1052             if (it->second.length())
1053                 cn->u.st.index = odr_strdup(odr, it->second.c_str());
1054             else
1055                 cn->u.st.index = 0;
1056         }
1057         break;
1058     case CQL_NODE_BOOL:
1059         r = convert_cql_fields(cn->u.boolean.left, odr);
1060         if (!r)
1061             r = convert_cql_fields(cn->u.boolean.right, odr);
1062         break;
1063     case CQL_NODE_SORT:
1064         r = convert_cql_fields(cn->u.sort.search, odr);
1065         break;
1066     }
1067     return r;
1068 }
1069
1070 void yf::Zoom::Frontend::handle_search(mp::Package &package)
1071 {
1072     Z_GDU *gdu = package.request().get();
1073     Z_APDU *apdu_req = gdu->u.z3950;
1074     Z_APDU *apdu_res = 0;
1075     mp::odr odr;
1076     Z_SearchRequest *sr = apdu_req->u.searchRequest;
1077     if (sr->num_databaseNames != 1)
1078     {
1079         apdu_res = odr.create_searchResponse(
1080             apdu_req, YAZ_BIB1_TOO_MANY_DATABASES_SPECIFIED, 0);
1081         package.response() = apdu_res;
1082         return;
1083     }
1084
1085     int error = 0;
1086     char *addinfo = 0;
1087     std::string db(sr->databaseNames[0]);
1088     BackendPtr b = get_backend_from_databases(db, &error, &addinfo, odr);
1089     if (error)
1090     {
1091         apdu_res = 
1092             odr.create_searchResponse(apdu_req, error, addinfo);
1093         package.response() = apdu_res;
1094         return;
1095     }
1096
1097     b->set_option("setname", "default");
1098
1099     Odr_int hits = 0;
1100     Z_Query *query = sr->query;
1101     WRBUF ccl_wrbuf = 0;
1102     WRBUF pqf_wrbuf = 0;
1103
1104     if (query->which == Z_Query_type_1 || query->which == Z_Query_type_101)
1105     {
1106         // RPN
1107         pqf_wrbuf = wrbuf_alloc();
1108         yaz_rpnquery_to_wrbuf(pqf_wrbuf, query->u.type_1);
1109     }
1110     else if (query->which == Z_Query_type_2)
1111     {
1112         // CCL
1113         ccl_wrbuf = wrbuf_alloc();
1114         wrbuf_write(ccl_wrbuf, (const char *) query->u.type_2->buf,
1115                     query->u.type_2->len);
1116     }
1117     else if (query->which == Z_Query_type_104 &&
1118              query->u.type_104->which == Z_External_CQL)
1119     {
1120         // CQL
1121         const char *cql = query->u.type_104->u.cql;
1122         CQL_parser cp = cql_parser_create();
1123         int r = cql_parser_string(cp, cql);
1124         if (r)
1125         {
1126             cql_parser_destroy(cp);
1127             apdu_res = 
1128                 odr.create_searchResponse(apdu_req, 
1129                                           YAZ_BIB1_MALFORMED_QUERY,
1130                                           "CQL syntax error");
1131             package.response() = apdu_res;
1132             return;
1133         }
1134         struct cql_node *cn = cql_parser_result(cp);
1135         struct cql_node *cn_error = m_p->convert_cql_fields(cn, odr);
1136         if (cn_error)
1137         {
1138             // hopefully we are getting a ptr to a index+relation+term node
1139             addinfo = 0;
1140             if (cn_error->which == CQL_NODE_ST)
1141                 addinfo = cn_error->u.st.index;
1142
1143             apdu_res = 
1144                 odr.create_searchResponse(apdu_req, 
1145                                           YAZ_BIB1_UNSUPP_USE_ATTRIBUTE,
1146                                           addinfo);
1147             package.response() = apdu_res;
1148             return;
1149         }
1150         char ccl_buf[1024];
1151
1152         r = cql_to_ccl_buf(cn, ccl_buf, sizeof(ccl_buf));
1153         if (r == 0)
1154         {
1155             ccl_wrbuf = wrbuf_alloc();
1156             wrbuf_puts(ccl_wrbuf, ccl_buf);
1157         }
1158         cql_parser_destroy(cp);
1159         if (r)
1160         {
1161             apdu_res = 
1162                 odr.create_searchResponse(apdu_req, 
1163                                           YAZ_BIB1_MALFORMED_QUERY,
1164                                           "CQL to CCL conversion error");
1165             package.response() = apdu_res;
1166             return;
1167         }
1168     }
1169     else
1170     {
1171         apdu_res = 
1172             odr.create_searchResponse(apdu_req, YAZ_BIB1_QUERY_TYPE_UNSUPP, 0);
1173         package.response() = apdu_res;
1174         return;
1175     }
1176
1177     if (ccl_wrbuf)
1178     {
1179         // CCL to PQF
1180         assert(pqf_wrbuf == 0);
1181         int cerror, cpos;
1182         struct ccl_rpn_node *cn;
1183         yaz_log(YLOG_LOG, "CCL: %s", wrbuf_cstr(ccl_wrbuf));
1184         cn = ccl_find_str(b->sptr->ccl_bibset, wrbuf_cstr(ccl_wrbuf),
1185                           &cerror, &cpos);
1186         wrbuf_destroy(ccl_wrbuf);
1187         if (!cn)
1188         {
1189             char *addinfo = odr_strdup(odr, ccl_err_msg(cerror));
1190             int z3950_diag = YAZ_BIB1_MALFORMED_QUERY;
1191
1192             switch (cerror)
1193             {
1194             case CCL_ERR_UNKNOWN_QUAL:
1195                 z3950_diag = YAZ_BIB1_UNSUPP_USE_ATTRIBUTE;
1196                 break;
1197             case CCL_ERR_TRUNC_NOT_LEFT: 
1198             case CCL_ERR_TRUNC_NOT_RIGHT:
1199             case CCL_ERR_TRUNC_NOT_BOTH:
1200                 z3950_diag = YAZ_BIB1_UNSUPP_TRUNCATION_ATTRIBUTE;
1201                 break;
1202             }
1203             apdu_res = 
1204                 odr.create_searchResponse(apdu_req, z3950_diag, addinfo);
1205             package.response() = apdu_res;
1206             return;
1207         }
1208         pqf_wrbuf = wrbuf_alloc();
1209         ccl_pquery(pqf_wrbuf, cn);
1210         ccl_rpn_delete(cn);
1211     }
1212     
1213     assert(pqf_wrbuf);
1214     if (b->get_option("sru"))
1215     {
1216         int status = 0;
1217         Z_RPNQuery *zquery;
1218         zquery = p_query_rpn(odr, wrbuf_cstr(pqf_wrbuf));
1219         WRBUF wrb = wrbuf_alloc();
1220             
1221         if (!strcmp(b->get_option("sru"), "solr"))
1222         {
1223             solr_transform_t cqlt = solr_transform_create();
1224             
1225             status = solr_transform_rpn2solr_wrbuf(cqlt, wrb, zquery);
1226             
1227             solr_transform_close(cqlt);
1228         }
1229         else
1230         {
1231             cql_transform_t cqlt = cql_transform_create();
1232             
1233             status = cql_transform_rpn2cql_wrbuf(cqlt, wrb, zquery);
1234             
1235             cql_transform_close(cqlt);
1236         }
1237         if (status == 0)
1238         {
1239             yaz_log(YLOG_LOG, "search CQL: %s", wrbuf_cstr(wrb));
1240             b->search_cql(wrbuf_cstr(wrb), &hits, &error, &addinfo, odr);
1241         }
1242         
1243         wrbuf_destroy(wrb);
1244         wrbuf_destroy(pqf_wrbuf);
1245         if (status)
1246         {
1247             apdu_res = 
1248                 odr.create_searchResponse(apdu_req, YAZ_BIB1_MALFORMED_QUERY,
1249                                           "can not convert from RPN to CQL/SOLR");
1250             package.response() = apdu_res;
1251             return;
1252         }
1253     }
1254     else
1255     {
1256         yaz_log(YLOG_LOG, "search PQF: %s", wrbuf_cstr(pqf_wrbuf));
1257         b->search_pqf(wrbuf_cstr(pqf_wrbuf), &hits, &error, &addinfo, odr);
1258         wrbuf_destroy(pqf_wrbuf);
1259     }
1260     
1261     
1262     const char *element_set_name = 0;
1263     Odr_int number_to_present = 0;
1264     if (!error)
1265         mp::util::piggyback_sr(sr, hits, number_to_present, &element_set_name);
1266     
1267     Odr_int number_of_records_returned = 0;
1268     Z_Records *records = get_records(
1269         0, number_to_present, &error, &addinfo,
1270         &number_of_records_returned, odr, b, sr->preferredRecordSyntax,
1271         element_set_name);
1272     apdu_res = odr.create_searchResponse(apdu_req, error, addinfo);
1273     if (records)
1274     {
1275         apdu_res->u.searchResponse->records = records;
1276         apdu_res->u.searchResponse->numberOfRecordsReturned =
1277             odr_intdup(odr, number_of_records_returned);
1278     }
1279     apdu_res->u.searchResponse->resultCount = odr_intdup(odr, hits);
1280     package.response() = apdu_res;
1281 }
1282
1283 void yf::Zoom::Frontend::handle_present(mp::Package &package)
1284 {
1285     Z_GDU *gdu = package.request().get();
1286     Z_APDU *apdu_req = gdu->u.z3950;
1287     Z_APDU *apdu_res = 0;
1288     Z_PresentRequest *pr = apdu_req->u.presentRequest;
1289
1290     mp::odr odr;
1291     if (!m_backend)
1292     {
1293         package.response() = odr.create_presentResponse(
1294             apdu_req, YAZ_BIB1_SPECIFIED_RESULT_SET_DOES_NOT_EXIST, 0);
1295         return;
1296     }
1297     const char *element_set_name = 0;
1298     Z_RecordComposition *comp = pr->recordComposition;
1299     if (comp && comp->which != Z_RecordComp_simple)
1300     {
1301         package.response() = odr.create_presentResponse(
1302             apdu_req, 
1303             YAZ_BIB1_PRESENT_COMP_SPEC_PARAMETER_UNSUPP, 0);
1304         return;
1305     }
1306     if (comp && comp->u.simple->which == Z_ElementSetNames_generic)
1307         element_set_name = comp->u.simple->u.generic;
1308     Odr_int number_of_records_returned = 0;
1309     int error = 0;
1310     char *addinfo = 0;
1311     Z_Records *records = get_records(
1312         *pr->resultSetStartPoint - 1, *pr->numberOfRecordsRequested,
1313         &error, &addinfo, &number_of_records_returned, odr, m_backend,
1314         pr->preferredRecordSyntax, element_set_name);
1315
1316     apdu_res = odr.create_presentResponse(apdu_req, error, addinfo);
1317     if (records)
1318     {
1319         apdu_res->u.presentResponse->records = records;
1320         apdu_res->u.presentResponse->numberOfRecordsReturned =
1321             odr_intdup(odr, number_of_records_returned);
1322     }
1323     package.response() = apdu_res;
1324 }
1325
1326 void yf::Zoom::Frontend::handle_package(mp::Package &package)
1327 {
1328     Z_GDU *gdu = package.request().get();
1329     if (!gdu)
1330         ;
1331     else if (gdu->which == Z_GDU_Z3950)
1332     {
1333         Z_APDU *apdu_req = gdu->u.z3950;
1334         if (apdu_req->which == Z_APDU_initRequest)
1335         {
1336             mp::odr odr;
1337             package.response() = odr.create_close(
1338                 apdu_req,
1339                 Z_Close_protocolError,
1340                 "double init");
1341         }
1342         else if (apdu_req->which == Z_APDU_searchRequest)
1343         {
1344             handle_search(package);
1345         }
1346         else if (apdu_req->which == Z_APDU_presentRequest)
1347         {
1348             handle_present(package);
1349         }
1350         else
1351         {
1352             mp::odr odr;
1353             package.response() = odr.create_close(
1354                 apdu_req,
1355                 Z_Close_protocolError,
1356                 "zoom filter cannot handle this APDU");
1357             package.session().close();
1358         }
1359     }
1360     else
1361     {
1362         package.session().close();
1363     }
1364 }
1365
1366 void yf::Zoom::Impl::process(mp::Package &package)
1367 {
1368     FrontendPtr f = get_frontend(package);
1369     Z_GDU *gdu = package.request().get();
1370
1371     if (f->m_is_virtual)
1372     {
1373         f->handle_package(package);
1374     }
1375     else if (gdu && gdu->which == Z_GDU_Z3950 && gdu->u.z3950->which ==
1376              Z_APDU_initRequest)
1377     {
1378         Z_InitRequest *req = gdu->u.z3950->u.initRequest;
1379         f->m_init_gdu = gdu;
1380         
1381         mp::odr odr;
1382         Z_APDU *apdu = odr.create_initResponse(gdu->u.z3950, 0, 0);
1383         Z_InitResponse *resp = apdu->u.initResponse;
1384         
1385         int i;
1386         static const int masks[] = {
1387             Z_Options_search,
1388             Z_Options_present,
1389             -1 
1390         };
1391         for (i = 0; masks[i] != -1; i++)
1392             if (ODR_MASK_GET(req->options, masks[i]))
1393                 ODR_MASK_SET(resp->options, masks[i]);
1394         
1395         static const int versions[] = {
1396             Z_ProtocolVersion_1,
1397             Z_ProtocolVersion_2,
1398             Z_ProtocolVersion_3,
1399             -1
1400         };
1401         for (i = 0; versions[i] != -1; i++)
1402             if (ODR_MASK_GET(req->protocolVersion, versions[i]))
1403                 ODR_MASK_SET(resp->protocolVersion, versions[i]);
1404             else
1405                 break;
1406         
1407         *resp->preferredMessageSize = *req->preferredMessageSize;
1408         *resp->maximumRecordSize = *req->maximumRecordSize;
1409         
1410         package.response() = apdu;
1411         f->m_is_virtual = true;
1412     }
1413     else
1414         package.move();
1415
1416     release_frontend(package);
1417 }
1418
1419
1420 static mp::filter::Base* filter_creator()
1421 {
1422     return new mp::filter::Zoom;
1423 }
1424
1425 extern "C" {
1426     struct metaproxy_1_filter_struct metaproxy_1_filter_zoom = {
1427         0,
1428         "zoom",
1429         filter_creator
1430     };
1431 }
1432
1433
1434 /*
1435  * Local variables:
1436  * c-basic-offset: 4
1437  * c-file-style: "Stroustrup"
1438  * indent-tabs-mode: nil
1439  * End:
1440  * vim: shiftwidth=4 tabstop=8 expandtab
1441  */
1442