Added ZOOM.
[yazpp-moved-to-github.git] / zoom / zerr.cpp
1 // $Header: /home/cvsroot/yaz++/zoom/Attic/zerr.cpp,v 1.1 2002-08-08 13:31:54 mike Exp $
2
3 // Z39.50 Error classes
4
5 #include <errno.h>
6 #include <string.h>             // for strerror(), strlen(), strcpy()
7 #include <stdio.h>              // for sprintf()
8 #include <yaz/diagbib1.h>
9 #include "zoom++.h"
10
11
12 namespace ZOOM {
13     error::error(int errcode) {
14         code = errcode;
15     }
16
17     int error::errcode() const {
18         return code;
19     }
20
21     const char *error::errmsg() const {
22         static char buf[40];
23         sprintf(buf, "error #%d", code);
24         return buf;
25     }
26
27
28
29     systemError::systemError() : error::error(errno){
30         code = errno;
31     }
32
33     int systemError::errcode() const {
34         return code;
35     }
36
37     const char *systemError::errmsg() const {
38         return strerror(code);
39     }
40
41
42
43     bib1Error::bib1Error(int errcode, const char *addinfo) :
44         error::error(errcode) {
45         info = new char[strlen(addinfo)+1];
46         strcpy((char*) info, addinfo);
47     }
48
49     bib1Error::~bib1Error() {
50         delete info;
51     }
52
53     int bib1Error::errcode() const {
54         return code;
55     }
56
57     const char *bib1Error::errmsg() const {
58         return diagbib1_str(code);
59     }
60
61     const char *bib1Error::addinfo() const {
62         return info;
63     }
64
65
66
67     queryError::queryError(int qtype, const char *source) :
68         error::error(qtype) {
69         q = new char[strlen(source)+1];
70         strcpy((char*) q, source);
71     }
72
73     queryError::~queryError() {
74         delete q;
75     }
76
77     int queryError::errcode() const {
78         return code;
79     }
80
81     const char *queryError::errmsg() const {
82         switch (code) {
83         case PREFIX: return "bad prefix search";
84         case CCL: return "bad CCL search";
85         default: break;
86         }
87         return "bad search (unknown type)";
88     }
89
90     const char *queryError::addinfo() const {
91         return q;
92     }
93 }