NCBI C++ ToolKit
myncbi_request.cpp
Go to the documentation of this file.

Go to the SVN repository for this file.

1 /* $Id: myncbi_request.cpp 100868 2023-09-21 15:07:42Z saprykin $
2  * ===========================================================================
3  *
4  * PUBLIC DOMAIN NOTICE
5  * National Center for Biotechnology Information
6  *
7  * This software/database is a "United States Government Work" under the
8  * terms of the United States Copyright Act. It was written as part of
9  * the author's official duties as a United States Government employee and
10  * thus cannot be copyrighted. This software/database is freely available
11  * to the public for use. The National Library of Medicine and the U.S.
12  * Government have not placed any restriction on its use or reproduction.
13  *
14  * Although all reasonable efforts have been taken to ensure the accuracy
15  * and reliability of the software and data, the NLM and the U.S.
16  * Government do not and cannot warrant the performance or results that
17  * may be obtained by using this software or data. The NLM and the U.S.
18  * Government disclaim all warranties, express or implied, including
19  * warranties of performance, merchantability or fitness for any particular
20  * purpose.
21  *
22  * Please cite the author in any work or product based on this material.
23  *
24  * ===========================================================================
25  *
26  * Authors: Dmitrii Saprykin
27  *
28  * File Description: MyNCBIAccount request factory
29  *
30  */
31 
32 #include <ncbi_pch.hpp>
33 
35 
37 
39 
41 {
42  m_HttpResponseData.append(data);
43 }
44 
46 {
47  return m_HttpResponseData;
48 }
49 
51 {
52  m_HttpResponseStatus = status;
53 }
54 
56 {
57  return m_HttpResponseStatus;
58 }
59 
61 {
62  m_ResponseStatus = status;
63 }
64 
66 {
67  return m_ResponseStatus;
68 }
69 
71 {
72  if (m_HttpResponseStatus != 200)
73  {
76  "Request failed: MyNCBI response status - " + to_string(m_HttpResponseStatus)
77  + "; MyNCBI response text - '" + GetHttpResponseData() + "'");
78  }
79 }
80 
82 {
85  string response = GetHttpResponseData();
86  auto xml = xml::document(response.c_str(), response.size(), nullptr);
87  for (auto node = xml.begin(); node != xml.end(); ++node) {
88  if (strcmp(node->get_name(), "MyNcbiResponse") == 0) {
89  for (auto data_node = node->begin(); data_node != node->end(); ++data_node) {
90  if (strcmp(data_node->get_name(), "UserId") == 0) {
91  m_UserInfo.user_id = NStr::StringToNumeric<Int8>(data_node->get_content(), NStr::fConvErr_NoThrow);
92  }
93  else if (strcmp(data_node->get_name(), "UserName") == 0) {
94  m_UserInfo.username = data_node->get_content();
95  }
96  else if (strcmp(data_node->get_name(), "EmailAddress") == 0) {
97  m_UserInfo.email_address = data_node->get_content();
98  }
99  }
100  }
101  }
102  if (m_UserInfo.user_id > 0 && !m_UserInfo.username.empty() && !m_UserInfo.email_address.empty()) {
105  }
106  else {
109  "MyNCBIUser data not found: MyNCBI response status - " + to_string(GetHttpResponseStatus())
110  + "; MyNCBI response text - '" + GetHttpResponseData() + "'");
111  }
112  }
113 }
114 
116 {
119  string response = GetHttpResponseData();
120  auto xml = xml::document(response.c_str(), response.size(), nullptr);
121  xml::xpath_expression expr("/myncbi-account-response/result/wcu");
122  const xml::node_set nset( xml.get_root_node().run_xpath_query(expr) );
124  for (auto item = nset.begin() ; item != nset.end(); ++item ) {
125  if (m_Cookie.empty()) {
126  m_Cookie = item->get_content();
127  }
128  }
129 
130  if (!m_Cookie.empty()) {
132  }
133  else {
136  "MyNCBIUser data not found: MyNCBI response status - " + to_string(GetHttpResponseStatus())
137  + "; MyNCBI response text - '" + GetHttpResponseData() + "'");
138  }
139  }
140 }
141 
void HandleResponse() override
void HandleResponse() override
void ReceiveHttpResponseData(string data)
virtual void HandleResponse()
void SetHttpResponseStatus(long status)
EPSG_MyNCBIResponseStatus GetResponseStatus() const
TDataErrorCallback m_ErrorCallback
string GetHttpResponseData() const
long GetHttpResponseStatus() const
void SetResponseStatus(EPSG_MyNCBIResponseStatus status)
EPSG_MyNCBIResponseStatus m_ResponseStatus
The xml::document class is used to hold the XML tree and various bits of information about it.
Definition: document.hpp:80
The xml::node_set::const_iterator class is used to iterate over nodes in a node set.
Definition: node_set.hpp:226
The xml::node_set class is used to store xpath query result set.
Definition: node_set.hpp:68
iterator begin()
Get an iterator that points to the beginning of the xpath query result node set.
Definition: node_set.cpp:173
iterator end()
Get an iterator that points one past the last node in the xpath query result node set.
Definition: node_set.cpp:185
The xml::xpath_expression class is used to store xpath query string and optional XML namespaces.
char data[12]
Definition: iconv.c:80
@ eDiag_Error
Error message.
Definition: ncbidiag.hpp:653
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
@ fConvErr_NoThrow
Do not throw an exception on error.
Definition: ncbistr.hpp:285
EPSG_MyNCBIResponseStatus
int strcmp(const char *str1, const char *str2)
Definition: odbc_utils.hpp:160
XML library namespace.
Definition: attributes.hpp:57
Modified on Fri Sep 20 14:57:20 2024 by modify_doxy.py rev. 669887