Qore Programming Language  1.12.0
QC_HTTPClient.h
1 /* -*- mode: c++; indent-tabs-mode: nil -*- */
2 /*
3  QC_HTTPClient.h
4 
5  Qore Programming Language
6 
7  Copyright (C) 2006 - 2022 Qore Technologies, s.r.o.
8 
9  Permission is hereby granted, free of charge, to any person obtaining a
10  copy of this software and associated documentation files (the "Software"),
11  to deal in the Software without restriction, including without limitation
12  the rights to use, copy, modify, merge, publish, distribute, sublicense,
13  and/or sell copies of the Software, and to permit persons to whom the
14  Software is furnished to do so, subject to the following conditions:
15 
16  The above copyright notice and this permission notice shall be included in
17  all copies or substantial portions of the Software.
18 
19  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
24  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
25  DEALINGS IN THE SOFTWARE.
26 
27  Note that the Qore library is released under a choice of three open-source
28  licenses: MIT (as above), LGPL 2+, or GPL 2+; see README-LICENSE for more
29  information.
30 */
31 
32 #ifndef QC_HTTP_CLIENT_H_
33 #define QC_HTTP_CLIENT_H_
34 
35 DLLEXPORT extern qore_classid_t CID_HTTPCLIENT;
36 DLLEXPORT extern QoreClass *QC_HTTPCLIENT;
37 DLLEXPORT extern QoreClass *QC_SOCKET;
38 DLLLOCAL QoreClass *initHTTPClientClass(QoreNamespace& ns);
39 
40 class HTTPInfoRefHelper {
41 protected:
42  const ReferenceNode *ref;
43  ExceptionSink *xsink;
45 
46 public:
47  DLLLOCAL HTTPInfoRefHelper(const ReferenceNode *n_ref, QoreStringNode *msg, ExceptionSink *n_xsink) : ref(n_ref), xsink(n_xsink), info(new QoreHashNode(autoTypeInfo), xsink) {
48  info->setKeyValue("request", msg, xsink);
49  }
50 
51  DLLLOCAL ~HTTPInfoRefHelper() {
52  // we have to create a temporary ExceptionSink if there is
53  // an active exception, otherwise writing back the reference will fail
54  assert(xsink);
55  ExceptionSink *txsink = *xsink ? new ExceptionSink : xsink;
56 
57  // write info hash to reference
58  AutoVLock vl(txsink);
59  QoreTypeSafeReferenceHelper rh(ref, vl, txsink);
60  if (!rh)
61  return;
62 
63  if (rh.assign(info.release()))
64  return;
65 
66  if (txsink != xsink)
67  xsink->assimilate(txsink);
68  }
69 
70  DLLLOCAL QoreHashNode *operator*() {
71  return *info;
72  }
73 };
74 
75 #endif
76 
77 // EOF
AutoVLock is a container for safely managing global variable and object lock handovers,...
Definition: AutoVLock.h:80
container for holding Qore-language exception information and also for registering a "thread_exit" ca...
Definition: ExceptionSink.h:48
DLLEXPORT void assimilate(ExceptionSink *xs)
assimilates all entries of the "xs" argument by appending them to the internal list and deletes the "...
defines a Qore-language class
Definition: QoreClass.h:249
This is the hash or associative list container type in Qore, dynamically allocated only,...
Definition: QoreHashNode.h:50
DLLEXPORT int setKeyValue(const char *key, QoreValue value, ExceptionSink *xsink)
sets the value of "key" to "value"
contains constants, classes, and subnamespaces in QoreProgram objects
Definition: QoreNamespace.h:65
Qore's string value type, reference counted, dynamically-allocated only.
Definition: QoreStringNode.h:50
helper class to manage variable references passed to functions and class methods, stack only,...
Definition: QoreTypeSafeReferenceHelper.h:57
DLLLOCAL T * release()
releases the pointer to the caller
Definition: ReferenceHolder.h:83
parse type: reference to a lvalue expression
Definition: ReferenceNode.h:45
unsigned qore_classid_t
used for the unique class ID for QoreClass objects
Definition: common.h:79