Avoid using unix path as "database name" for virt_db
[metaproxy-moved-to-github.git] / src / util.cpp
1 /* This file is part of Metaproxy.
2    Copyright (C) 2005-2012 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 <metaproxy/util.hpp>
21
22 #include <yaz/odr.h>
23 #include <yaz/comstack.h>
24 #include <yaz/pquery.h>
25 #include <yaz/otherinfo.h>
26 #include <yaz/querytowrbuf.h>
27 #include <yaz/oid_db.h>
28 #include <yaz/srw.h>
29
30 #include <iostream>
31
32 namespace mp = metaproxy_1;
33
34 // Doxygen doesn't like mp::util, so we use this instead
35 namespace mp_util = metaproxy_1::util;
36
37 const char * 
38 mp_util::record_composition_to_esn(Z_RecordComposition *comp)
39 {
40     if (comp && comp->which == Z_RecordComp_complex)
41     {
42         if (comp->u.complex->generic 
43             && comp->u.complex->generic->elementSpec
44             && (comp->u.complex->generic->elementSpec->which == 
45                 Z_ElementSpec_elementSetName))
46             return comp->u.complex->generic->elementSpec->u.elementSetName;
47     }
48     else if (comp && comp->which == Z_RecordComp_simple &&
49              comp->u.simple->which == Z_ElementSetNames_generic)
50         return comp->u.simple->u.generic;
51     return 0;
52 }
53
54
55
56 std::string mp_util::http_header_value(const Z_HTTP_Header* header, 
57                                        const std::string name)
58 {
59     while (header && header->name
60            && std::string(header->name) !=  name)
61         header = header->next;
62     
63     if (header && header->name && std::string(header->name) == name
64         && header->value)
65         return std::string(header->value);
66     
67     return std::string();
68 }
69     
70 std::string mp_util::http_headers_debug(const Z_HTTP_Request &http_req)
71 {
72     std::string message("<html>\n<body>\n<h1>"
73                         "Metaproxy SRUtoZ3950 filter"
74                         "</h1>\n");
75     
76     message += "<h3>HTTP Info</h3><br/>\n";
77     message += "<p>\n";
78     message += "<b>Method: </b> " + std::string(http_req.method) + "<br/>\n";
79     message += "<b>Version:</b> " + std::string(http_req.version) + "<br/>\n";
80     message += "<b>Path:   </b> " + std::string(http_req.path) + "<br/>\n";
81
82     message += "<b>Content-Type:</b>"
83         + mp_util::http_header_value(http_req.headers, "Content-Type")
84         + "<br/>\n";
85     message += "<b>Content-Length:</b>"
86         + mp_util::http_header_value(http_req.headers, "Content-Length")
87         + "<br/>\n";
88     message += "</p>\n";    
89     
90     message += "<h3>Headers</h3><br/>\n";
91     message += "<p>\n";    
92     Z_HTTP_Header* header = http_req.headers;
93     while (header){
94         message += "<b>Header: </b> <i>" 
95             + std::string(header->name) + ":</i> "
96             + std::string(header->value) + "<br/>\n";
97         header = header->next;
98     }
99     message += "</p>\n";    
100     message += "</body>\n</html>\n";
101     return message;
102 }
103
104
105 void mp_util::http_response(metaproxy_1::Package &package, 
106                      const std::string &content, 
107                      int http_code)
108 {
109
110     Z_GDU *zgdu_req = package.request().get(); 
111     Z_GDU *zgdu_res = 0; 
112     mp::odr odr;
113     zgdu_res 
114        = odr.create_HTTP_Response(package.session(), 
115                                   zgdu_req->u.HTTP_Request, 
116                                   http_code);
117         
118     zgdu_res->u.HTTP_Response->content_len = content.size();
119     zgdu_res->u.HTTP_Response->content_buf 
120         = (char*) odr_malloc(odr, zgdu_res->u.HTTP_Response->content_len);
121     
122     strncpy(zgdu_res->u.HTTP_Response->content_buf, 
123             content.c_str(),  zgdu_res->u.HTTP_Response->content_len);
124     
125     //z_HTTP_header_add(odr, &hres->headers,
126     //                  "Content-Type", content_type.c_str());
127     package.response() = zgdu_res;
128 }
129
130
131 int mp_util::memcmp2(const void *buf1, int len1,
132                      const void *buf2, int len2)
133 {
134     int d = len1 - len2;
135
136     // compare buffer (common length)
137     int c = memcmp(buf1, buf2, d > 0 ? len2 : len1);
138     if (c > 0)
139         return 1;
140     else if (c < 0)
141         return -1;
142     
143     // compare (remaining bytes)
144     if (d > 0)
145         return 1;
146     else if (d < 0)
147         return -1;
148     return 0;
149 }
150
151
152 std::string mp_util::database_name_normalize(const std::string &s)
153 {
154     std::string r = s;
155     size_t i;
156     for (i = 0; i < r.length(); i++)
157     {
158         int ch = r[i];
159         if (ch >= 'A' && ch <= 'Z')
160             r[i] = ch + 'a' - 'A';
161     }
162     return r;
163
164 }
165
166 void mp_util::piggyback_sr(Z_SearchRequest *sreq,
167                            Odr_int result_set_size,
168                            Odr_int &number_to_present,
169                            const char **element_set_name)
170 {
171     Z_ElementSetNames *esn;
172     const char *smallSetElementSetNames = 0;
173     const char *mediumSetElementSetNames = 0;
174
175     esn = sreq->smallSetElementSetNames;
176     if (esn && esn->which == Z_ElementSetNames_generic)
177         smallSetElementSetNames = esn->u.generic;
178
179     esn = sreq->mediumSetElementSetNames;
180     if (esn && esn->which == Z_ElementSetNames_generic)
181         mediumSetElementSetNames = esn->u.generic;
182
183     piggyback(*sreq->smallSetUpperBound,
184               *sreq->largeSetLowerBound,
185               *sreq->mediumSetPresentNumber,
186               smallSetElementSetNames,
187               mediumSetElementSetNames,
188               result_set_size,
189               number_to_present,
190               element_set_name);
191 }
192
193 void mp_util::piggyback(int smallSetUpperBound,
194                         int largeSetLowerBound,
195                         int mediumSetPresentNumber,
196                         int result_set_size,
197                         int &number_to_present)
198 {
199     Odr_int tmp = number_to_present;
200     piggyback(smallSetUpperBound, largeSetLowerBound, mediumSetPresentNumber,
201               0, 0, result_set_size, tmp, 0);
202     number_to_present = tmp;
203 }
204
205 void mp_util::piggyback(Odr_int smallSetUpperBound,
206                         Odr_int largeSetLowerBound,
207                         Odr_int mediumSetPresentNumber,
208                         const char *smallSetElementSetNames,
209                         const char *mediumSetElementSetNames,
210                         Odr_int result_set_size,
211                         Odr_int &number_to_present,
212                         const char **element_set_name)
213 {
214     // deal with piggyback
215
216     if (result_set_size < smallSetUpperBound)
217     {
218         // small set . Return all records in set
219         number_to_present = result_set_size;
220         if (element_set_name && smallSetElementSetNames)
221             *element_set_name = smallSetElementSetNames;
222             
223     }
224     else if (result_set_size > largeSetLowerBound)
225     {
226         // large set . Return no records
227         number_to_present = 0;
228         if (element_set_name)
229             *element_set_name = 0;
230     }
231     else
232     {
233         // medium set . Return mediumSetPresentNumber records
234         number_to_present = mediumSetPresentNumber;
235         if (number_to_present > result_set_size)
236             number_to_present = result_set_size;
237         if (element_set_name && mediumSetElementSetNames)
238             *element_set_name = mediumSetElementSetNames;
239     }
240 }
241
242 bool mp_util::pqf(ODR odr, Z_APDU *apdu, const std::string &q)
243 {
244     YAZ_PQF_Parser pqf_parser = yaz_pqf_create();
245     
246     Z_RPNQuery *rpn = yaz_pqf_parse(pqf_parser, odr, q.c_str());
247     if (!rpn)
248     {
249         yaz_pqf_destroy(pqf_parser);
250         return false;
251     }
252     yaz_pqf_destroy(pqf_parser);
253     Z_Query *query = (Z_Query *) odr_malloc(odr, sizeof(Z_Query));
254     query->which = Z_Query_type_1;
255     query->u.type_1 = rpn;
256     
257     apdu->u.searchRequest->query = query;
258     return true;
259 }
260
261
262 std::string mp_util::zQueryToString(Z_Query *query)
263 {
264     std::string query_str = "";
265
266     if (query && query->which == Z_Query_type_1)
267     {
268         Z_RPNQuery *rpn = query->u.type_1;
269         
270         if (rpn)
271         {
272             mp::wrbuf w;
273             
274             // put query in w
275             yaz_rpnquery_to_wrbuf(w, rpn);
276             
277             // from w to std::string
278             query_str = std::string(w.buf(), w.len());
279         }
280     }
281
282 #if 0
283     if (query && query->which == Z_Query_type_1){
284         
285         // allocate wrbuf (strings in YAZ!)
286         WRBUF w = wrbuf_alloc();
287         
288         // put query in w
289         yaz_query_to_wrbuf(w, query);
290         
291         // from w to std::string
292         query_str = std::string(wrbuf_buf(w), wrbuf_len(w));
293         
294         // destroy wrbuf
295         wrbuf_free(w, 1);
296     }    
297 #endif
298     return query_str;
299 }
300
301 void mp_util::get_default_diag(Z_DefaultDiagFormat *r,
302                                          int &error_code, std::string &addinfo)
303 {
304     error_code = *r->condition;
305     switch (r->which)
306     {
307     case Z_DefaultDiagFormat_v2Addinfo:
308         addinfo = std::string(r->u.v2Addinfo);
309         break;
310     case Z_DefaultDiagFormat_v3Addinfo:
311         addinfo = r->u.v3Addinfo;
312         break;
313     }
314 }
315
316 void mp_util::get_init_diagnostics(
317     Z_InitResponse *initrs, int &error_code, std::string &addinfo)
318 {
319     Z_External *uif = initrs->userInformationField;
320     
321     if (uif && uif->which == Z_External_userInfo1)
322     {
323         Z_OtherInformation *ui = uif->u.userInfo1;
324         int i;
325         for (i = 0; i < ui->num_elements; i++)
326         {
327             Z_OtherInformationUnit *unit = ui->list[i];
328             if (unit->which == Z_OtherInfo_externallyDefinedInfo &&
329                 unit->information.externallyDefinedInfo &&
330                 unit->information.externallyDefinedInfo->which ==
331                 Z_External_diag1) 
332             {
333                 Z_DiagnosticFormat *diag = 
334                     unit->information.externallyDefinedInfo->u.diag1;
335
336                 if (diag->num > 0)
337                 {
338                     Z_DiagnosticFormat_s *ds = diag->elements[0];
339                     if (ds->which == Z_DiagnosticFormat_s_defaultDiagRec)
340                         mp::util::get_default_diag(ds->u.defaultDiagRec,
341                                                     error_code, addinfo);
342                 }
343             } 
344         }
345     }
346 }
347
348 int mp_util::get_or_remove_vhost_otherinfo(
349     Z_OtherInformation **otherInformation,
350     bool remove_flag,
351     std::list<std::string> &vhosts)
352 {
353     int cat;
354     for (cat = 1; ; cat++)
355     {
356         // check virtual host
357         const char *vhost =
358             yaz_oi_get_string_oid(otherInformation,
359                                   yaz_oid_userinfo_proxy,
360                                   cat /* categoryValue */,
361                                   remove_flag /* delete flag */);
362         if (!vhost)
363             break;
364         vhosts.push_back(std::string(vhost));
365     }
366     --cat;
367     return cat;
368 }
369
370 void mp_util::get_vhost_otherinfo(
371     Z_OtherInformation *otherInformation,
372     std::list<std::string> &vhosts)
373 {
374     get_or_remove_vhost_otherinfo(&otherInformation, false, vhosts);
375 }
376
377 int mp_util::remove_vhost_otherinfo(
378     Z_OtherInformation **otherInformation,
379     std::list<std::string> &vhosts)
380 {
381     return get_or_remove_vhost_otherinfo(otherInformation, true, vhosts);
382 }
383
384 void mp_util::set_vhost_otherinfo(
385     Z_OtherInformation **otherInformation, ODR odr,
386     const std::list<std::string> &vhosts)
387 {
388     int cat;
389     std::list<std::string>::const_iterator it = vhosts.begin();
390
391     for (cat = 1; it != vhosts.end() ; cat++, it++)
392     {
393         yaz_oi_set_string_oid(otherInformation, odr,
394                               yaz_oid_userinfo_proxy, cat, it->c_str());
395     }
396 }
397
398 void mp_util::set_vhost_otherinfo(
399     Z_OtherInformation **otherInformation, ODR odr,
400     const std::string vhost, const int cat)
401 {
402     yaz_oi_set_string_oid(otherInformation, odr,
403                           yaz_oid_userinfo_proxy, cat, vhost.c_str());
404 }
405
406 void mp_util::split_zurl(std::string zurl, std::string &host,
407                          std::list<std::string> &db)
408 {
409     const char *zurl_cstr = zurl.c_str();
410     const char *args = 0;
411     cs_get_host_args(zurl_cstr, &args);
412
413     if (args && *args)
414     { 
415         host = std::string(zurl_cstr, args - zurl_cstr);
416
417         const char *cp1 = args + 1;
418         while (1)
419         {
420             const char *cp2 = strchr(cp1, '+');
421             if (cp2)
422                 db.push_back(std::string(cp1, cp2 - cp1));
423             else
424             {
425                 db.push_back(std::string(cp1));
426                 break;
427             }
428             cp1 = cp2+1;
429         }
430     }
431     else
432         host = zurl;
433 }
434
435 bool mp_util::set_databases_from_zurl(
436     ODR odr, std::string zurl,
437     int *db_num, char ***db_strings)
438 {
439     std::string host;
440     std::list<std::string> dblist;
441
442     split_zurl(zurl, host, dblist);
443    
444     if (dblist.size() == 0)
445         return false;
446     *db_num = dblist.size();
447     *db_strings = (char **) odr_malloc(odr, sizeof(char*) * (*db_num));
448
449     std::list<std::string>::const_iterator it = dblist.begin();
450     for (int i = 0; it != dblist.end(); it++, i++)
451         (*db_strings)[i] = odr_strdup(odr, it->c_str());
452     return true;
453 }
454
455 mp::odr::odr(int type)
456 {
457     m_odr = odr_createmem(type);
458 }
459
460 mp::odr::odr()
461 {
462     m_odr = odr_createmem(ODR_ENCODE);
463 }
464
465 mp::odr::~odr()
466 {
467     odr_destroy(m_odr);
468 }
469
470 mp::odr::operator ODR() const
471 {
472     return m_odr;
473 }
474
475 Z_APDU *mp::odr::create_close(const Z_APDU *in_apdu,
476                               int reason, const char *addinfo)
477 {
478     Z_APDU *apdu = create_APDU(Z_APDU_close, in_apdu);
479     
480     *apdu->u.close->closeReason = reason;
481     if (addinfo)
482         apdu->u.close->diagnosticInformation = odr_strdup(m_odr, addinfo);
483     return apdu;
484 }
485
486 Z_APDU *mp::odr::create_APDU(int type, const Z_APDU *in_apdu)
487 {
488     return mp::util::create_APDU(m_odr, type, in_apdu);
489 }
490
491 Z_APDU *mp_util::create_APDU(ODR odr, int type, const Z_APDU *in_apdu)
492 {
493     Z_APDU *out_apdu = zget_APDU(odr, type);
494     transfer_referenceId(odr, in_apdu, out_apdu);
495     return out_apdu;
496 }
497
498 void mp_util::transfer_referenceId(ODR odr, const Z_APDU *src, Z_APDU *dst)
499 {
500     Z_ReferenceId **id_to = mp::util::get_referenceId(dst);
501     *id_to = 0;
502     if (src)
503     {
504         Z_ReferenceId **id_from = mp::util::get_referenceId(src);
505         if (id_from && *id_from && id_to)
506         {
507             *id_to = (Z_ReferenceId*) odr_malloc (odr, sizeof(**id_to));
508             (*id_to)->size = (*id_to)->len = (*id_from)->len;
509             (*id_to)->buf = (unsigned char*) odr_malloc(odr, (*id_to)->len);
510             memcpy((*id_to)->buf, (*id_from)->buf, (*id_to)->len);
511         }
512         else if (id_to)
513             *id_to = 0;
514     }
515 }
516
517 Z_APDU *mp::odr::create_initResponse(const Z_APDU *in_apdu,
518                                      int error, const char *addinfo)
519 {
520     Z_APDU *apdu = create_APDU(Z_APDU_initResponse, in_apdu);
521     if (error)
522     {
523         apdu->u.initResponse->userInformationField =
524             zget_init_diagnostics(m_odr, error, addinfo);
525         *apdu->u.initResponse->result = 0;
526     }
527     apdu->u.initResponse->implementationName =
528         odr_prepend(m_odr, "Metaproxy",
529                     apdu->u.initResponse->implementationName);
530     apdu->u.initResponse->implementationVersion = 
531         odr_prepend(m_odr,
532                     VERSION, apdu->u.initResponse->implementationVersion);
533                    
534     return apdu;
535 }
536
537 Z_APDU *mp::odr::create_searchResponse(const Z_APDU *in_apdu,
538                                        int error, const char *addinfo)
539 {
540     Z_APDU *apdu = create_APDU(Z_APDU_searchResponse, in_apdu);
541     if (error)
542     {
543         Z_Records *rec = (Z_Records *) odr_malloc(m_odr, sizeof(Z_Records));
544         *apdu->u.searchResponse->searchStatus = 0;
545         apdu->u.searchResponse->records = rec;
546         rec->which = Z_Records_NSD;
547         rec->u.nonSurrogateDiagnostic =
548             zget_DefaultDiagFormat(m_odr, error, addinfo);
549         
550     }
551     return apdu;
552 }
553
554 Z_APDU *mp::odr::create_presentResponse(const Z_APDU *in_apdu,
555                                         int error, const char *addinfo)
556 {
557     Z_APDU *apdu = create_APDU(Z_APDU_presentResponse, in_apdu);
558     if (error)
559     {
560         Z_Records *rec = (Z_Records *) odr_malloc(m_odr, sizeof(Z_Records));
561         apdu->u.presentResponse->records = rec;
562         
563         rec->which = Z_Records_NSD;
564         rec->u.nonSurrogateDiagnostic =
565             zget_DefaultDiagFormat(m_odr, error, addinfo);
566         *apdu->u.presentResponse->presentStatus = Z_PresentStatus_failure;
567     }
568     return apdu;
569 }
570
571 Z_APDU *mp::odr::create_scanResponse(const Z_APDU *in_apdu,
572                                      int error, const char *addinfo)
573 {
574     Z_APDU *apdu = create_APDU(Z_APDU_scanResponse, in_apdu);
575     Z_ScanResponse *res = apdu->u.scanResponse;
576     res->entries = (Z_ListEntries *) odr_malloc(m_odr, sizeof(*res->entries));
577     res->entries->num_entries = 0;
578     res->entries->entries = 0;
579
580     if (error)
581     {
582         *res->scanStatus = Z_Scan_failure;
583
584         res->entries->num_nonsurrogateDiagnostics = 1;
585         res->entries->nonsurrogateDiagnostics = (Z_DiagRec **)
586             odr_malloc(m_odr, sizeof(Z_DiagRec *));
587         res->entries->nonsurrogateDiagnostics[0] = 
588             zget_DiagRec(m_odr, error, addinfo);
589     }
590     else
591     {
592         res->entries->num_nonsurrogateDiagnostics = 0;
593         res->entries->nonsurrogateDiagnostics = 0;
594     }
595     return apdu;
596 }
597
598 Z_GDU *mp::odr::create_HTTP_Response(mp::Session &session,
599                                      Z_HTTP_Request *hreq, int code)
600 {
601     const char *response_version = "1.0";
602     bool keepalive = false;
603     if (!strcmp(hreq->version, "1.0")) 
604     {
605         const char *v = z_HTTP_header_lookup(hreq->headers, "Connection");
606         if (v && !strcmp(v, "Keep-Alive"))
607             keepalive = true;
608         else
609             session.close();
610         response_version = "1.0";
611     }
612     else
613     {
614         const char *v = z_HTTP_header_lookup(hreq->headers, "Connection");
615         if (v && !strcmp(v, "close"))
616             session.close();
617         else
618             keepalive = true;
619         response_version = "1.1";
620     }
621
622     Z_GDU *gdu = z_get_HTTP_Response(m_odr, code);
623     Z_HTTP_Response *hres = gdu->u.HTTP_Response;
624     hres->version = odr_strdup(m_odr, response_version);
625     if (keepalive)
626         z_HTTP_header_add(m_odr, &hres->headers, "Connection", "Keep-Alive");
627     
628     return gdu;
629 }
630
631 Z_ReferenceId **mp_util::get_referenceId(const Z_APDU *apdu)
632 {
633     switch (apdu->which)
634     {
635     case  Z_APDU_initRequest:
636         return &apdu->u.initRequest->referenceId; 
637     case  Z_APDU_initResponse:
638         return &apdu->u.initResponse->referenceId;
639     case  Z_APDU_searchRequest:
640         return &apdu->u.searchRequest->referenceId;
641     case  Z_APDU_searchResponse:
642         return &apdu->u.searchResponse->referenceId;
643     case  Z_APDU_presentRequest:
644         return &apdu->u.presentRequest->referenceId;
645     case  Z_APDU_presentResponse:
646         return &apdu->u.presentResponse->referenceId;
647     case  Z_APDU_deleteResultSetRequest:
648         return &apdu->u.deleteResultSetRequest->referenceId;
649     case  Z_APDU_deleteResultSetResponse:
650         return &apdu->u.deleteResultSetResponse->referenceId;
651     case  Z_APDU_accessControlRequest:
652         return &apdu->u.accessControlRequest->referenceId;
653     case  Z_APDU_accessControlResponse:
654         return &apdu->u.accessControlResponse->referenceId;
655     case  Z_APDU_resourceControlRequest:
656         return &apdu->u.resourceControlRequest->referenceId;
657     case  Z_APDU_resourceControlResponse:
658         return &apdu->u.resourceControlResponse->referenceId;
659     case  Z_APDU_triggerResourceControlRequest:
660         return &apdu->u.triggerResourceControlRequest->referenceId;
661     case  Z_APDU_resourceReportRequest:
662         return &apdu->u.resourceReportRequest->referenceId;
663     case  Z_APDU_resourceReportResponse:
664         return &apdu->u.resourceReportResponse->referenceId;
665     case  Z_APDU_scanRequest:
666         return &apdu->u.scanRequest->referenceId;
667     case  Z_APDU_scanResponse:
668         return &apdu->u.scanResponse->referenceId;
669     case  Z_APDU_sortRequest:
670         return &apdu->u.sortRequest->referenceId;
671     case  Z_APDU_sortResponse:
672         return &apdu->u.sortResponse->referenceId;
673     case  Z_APDU_segmentRequest:
674         return &apdu->u.segmentRequest->referenceId;
675     case  Z_APDU_extendedServicesRequest:
676         return &apdu->u.extendedServicesRequest->referenceId;
677     case  Z_APDU_extendedServicesResponse:
678         return &apdu->u.extendedServicesResponse->referenceId;
679     case  Z_APDU_close:
680         return &apdu->u.close->referenceId;
681     }
682     return 0;
683 }
684
685 std::string mp_util::uri_encode(std::string s)
686 {
687     char *x = (char *) xmalloc(1 + s.length() * 3);
688     yaz_encode_uri_component(x, s.c_str());
689     std::string result(x);
690     xfree(x);
691     return result;
692 }
693
694
695 std::string mp_util::uri_decode(std::string s)
696 {
697     char *x = (char *) xmalloc(1 + s.length());
698     yaz_decode_uri_component(x, s.c_str(), s.length());
699     std::string result(x);
700     xfree(x);
701     return result;
702 }
703
704 mp::wrbuf::wrbuf()
705 {
706     m_wrbuf = wrbuf_alloc();
707 }
708
709 mp::wrbuf::~wrbuf()
710 {
711     wrbuf_destroy(m_wrbuf);
712 }
713
714 mp::wrbuf::operator WRBUF() const
715 {
716     return m_wrbuf;
717 }
718
719 size_t mp::wrbuf::len()
720 {
721     return wrbuf_len(m_wrbuf);
722 }
723
724 const char *mp::wrbuf::buf()
725 {
726     return wrbuf_buf(m_wrbuf);
727 }
728
729
730 /*
731  * Local variables:
732  * c-basic-offset: 4
733  * c-file-style: "Stroustrup"
734  * indent-tabs-mode: nil
735  * End:
736  * vim: shiftwidth=4 tabstop=8 expandtab
737  */
738