1 /*****************************************************************************/
2 /* Software Testing Automation Framework (STAF) */
3 /* (C) Copyright IBM Corp. 2001 */
4 /* */
5 /* This software is licensed under the Eclipse Public License (EPL) V1.0. */
6 /*****************************************************************************/
7
8 #ifndef STAF_STAFInlImpl
9 #define STAF_STAFInlImpl
10
11 #include "STAF.h"
12 #include "STAFString.h"
13 #include "STAFRefPtr.h"
14 #include "STAFUtil.h"
15 #include <stdarg.h>
16
create(const STAFString & name,STAFHandlePtr & handle)17 STAF_INLINE STAFRC_t STAFHandle::create(const STAFString &name,
18 STAFHandlePtr &handle)
19 {
20 STAFString theName(name);
21 STAFHandle_t theHandle = 0;
22
23 // Make sure it is NULL terminated
24 theName += kUTF8_NULL;
25
26 STAFRC_t rc = STAFRegisterUTF8(const_cast<char *>(theName.buffer()),
27 &theHandle);
28 if (rc) return rc;
29
30 handle = STAFHandlePtr(new STAFHandle(theHandle, true),
31 STAFHandlePtr::INIT);
32
33 return kSTAFOk;
34 }
35
36
create(STAFHandle_t handleT,STAFHandlePtr & handle,bool doUnreg)37 STAF_INLINE STAFRC_t STAFHandle::create(STAFHandle_t handleT,
38 STAFHandlePtr &handle, bool doUnreg)
39 {
40 handle = STAFHandlePtr(new STAFHandle(handleT, doUnreg),
41 STAFHandlePtr::INIT);
42 return kSTAFOk;
43 }
44
45
submit(const STAFString & where,const STAFString & service,const STAFString & request,const STAFSyncOption_t synchOption)46 STAF_INLINE STAFResultPtr STAFHandle::submit(const STAFString &where,
47 const STAFString &service,
48 const STAFString &request,
49 const STAFSyncOption_t synchOption)
50 {
51 STAFString theWhere(where);
52 STAFString theService(service);
53 unsigned int reqLength = 0;
54 const char *theRequest = request.buffer(&reqLength);
55
56 // Make sure they are NULL terminated
57 theWhere += kUTF8_NULL;
58 theService += kUTF8_NULL;
59
60 char *result = 0;
61 unsigned int resultLength = 0;
62 STAFRC_t rc = STAFSubmit2UTF8(fHandle, synchOption,
63 const_cast<char *>(theWhere.buffer()),
64 const_cast<char *>(theService.buffer()),
65 const_cast<char *>(theRequest),
66 reqLength, &result, &resultLength);
67
68 STAFResultPtr theResult(new STAFResult(rc, result, resultLength,
69 STAFString::kUTF8, fDoUnmarshallResult), STAFResultPtr::INIT);
70
71 STAFFree(fHandle, result);
72
73 return theResult;
74 }
75
76
77
wrapData(const STAFString & data)78 STAF_INLINE STAFString STAFHandle::wrapData(const STAFString &data)
79 {
80 STAFString outString(kUTF8_COLON);
81 outString += STAFString(data.length(STAFString::kChar));
82 outString += kUTF8_COLON;
83 outString += data;
84
85 return outString;
86 }
87
88
formatString(STAFStringConst_t formatString,...)89 STAF_INLINE STAFString STAFHandle::formatString(STAFStringConst_t formatString,
90 ...)
91 {
92 STAFString_t outString = 0;
93 va_list args;
94
95 va_start(args, formatString);
96
97 STAFRC_t rc = STAFUtilFormatString2(formatString, &outString, args);
98
99 va_end(args);
100
101 // XXX: Throw exception if bad rc?
102
103 return STAFString(outString, STAFString::kShallow);
104 }
105
106
stripPortFromEndpoint(const STAFString & endpoint)107 STAF_INLINE STAFString STAFHandle::stripPortFromEndpoint(
108 const STAFString &endpoint)
109 {
110 STAFString_t endpointNoPort = 0;
111
112 STAFRC_t rc = STAFUtilStripPortFromEndpoint(endpoint.getImpl(),
113 &endpointNoPort);
114
115 STAFException::checkRC(rc, "STAFStripPortFromEndpoint");
116
117 return STAFString(endpointNoPort, STAFString::kShallow);
118 }
119
120
addPrivacyDelimiters(const STAFString & data)121 STAF_INLINE STAFString STAFHandle::addPrivacyDelimiters(const STAFString &data)
122 {
123 STAFString_t result = 0;
124
125 STAFRC_t rc = STAFAddPrivacyDelimiters(data.getImpl(), &result);
126
127 STAFException::checkRC(rc, "STAFAddPrivacyDelimiters");
128
129 return STAFString(result, STAFString::kShallow);
130 }
131
132
removePrivacyDelimiters(const STAFString & data,unsigned int numLevels)133 STAF_INLINE STAFString STAFHandle::removePrivacyDelimiters(
134 const STAFString &data, unsigned int numLevels)
135 {
136 STAFString_t result = 0;
137
138 STAFRC_t rc = STAFRemovePrivacyDelimiters(
139 data.getImpl(), numLevels, &result);
140
141 STAFException::checkRC(rc, "STAFRemovePrivacyDelimiters");
142
143 return STAFString(result, STAFString::kShallow);
144 }
145
146
maskPrivateData(const STAFString & data)147 STAF_INLINE STAFString STAFHandle::maskPrivateData(const STAFString &data)
148 {
149 STAFString_t result = 0;
150
151 STAFRC_t rc = STAFMaskPrivateData(data.getImpl(), &result);
152
153 STAFException::checkRC(rc, "STAFMaskPrivateData");
154
155 return STAFString(result, STAFString::kShallow);
156 }
157
158
escapePrivacyDelimiters(const STAFString & data)159 STAF_INLINE STAFString STAFHandle::escapePrivacyDelimiters(
160 const STAFString &data)
161 {
162 STAFString_t result = 0;
163
164 STAFRC_t rc = STAFEscapePrivacyDelimiters(data.getImpl(), &result);
165
166 STAFException::checkRC(rc, "STAFEscapePrivacyDelimiters");
167
168 return STAFString(result, STAFString::kShallow);
169 }
170
171
adoptHandle()172 STAF_INLINE STAFHandle_t STAFHandle::adoptHandle()
173 {
174 STAFHandle_t temp = fHandle;
175
176 fHandle = 0;
177 fDoUnreg = false;
178
179 return temp;
180 }
181
182
~STAFHandle()183 STAF_INLINE STAFHandle::~STAFHandle()
184 {
185 if (fDoUnreg) STAFUnRegister(fHandle);
186 }
187
188 #endif
189