libqtaws  0.1.0
UnofficialAWSlibraryforQt-InternalDocumentation
Classes | Public Member Functions | Public Attributes | Protected Types | Static Protected Member Functions | Static Protected Attributes | Private Attributes | Friends | List of all members
AwsEndpointPrivate Class Reference

Private implementation for AwsEndpoint. More...

Collaboration diagram for AwsEndpointPrivate:
Collaboration graph
[legend]

Classes

struct  HostInfo
 The per-host information to load from the endpoints.xml file. More...
 
struct  RegionEndpointInfo
 The per-region endpoint-specific information to load from the endpoints.xml file. More...
 
struct  RegionInfo
 The per-region information to load from the endpoints.xml file. More...
 
struct  ServiceInfo
 The per-service information to load from the endpoints.xml file. More...
 

Public Member Functions

 AwsEndpointPrivate (AwsEndpoint *const q)
 Constructs a new AwsEndpointPrivate object. More...
 

Public Attributes

QString hostName
 This endpoint's hostname.
 
QString regionName
 This endpoint's region name.
 
QString serviceName
 This endpoint's service name.
 

Protected Types

typedef QHash< QString, RegionEndpointInfoRegionServices
 Hash of service names to RegionEndpointInfo.
 

Static Protected Member Functions

static void loadEndpointData (const QString &fileName=QLatin1String(":/aws/endpoints.xml"))
 Load endpoint data. More...
 
static void loadEndpointData (QIODevice &device)
 Load endpoint data. More...
 
static void loadEndpointData (QXmlStreamReader &xml)
 Load endpoint data. More...
 
static void parseRegion (QXmlStreamReader &xml)
 Parse a Region element from Amazon's endpoint XML data. More...
 
static void parseRegions (QXmlStreamReader &xml)
 Parse a Regions element from Amazon's endpoint XML data. More...
 
static void parseService (QXmlStreamReader &xml)
 Parse a Service element from Amazon's endpoint XML data. More...
 
static void parseServices (QXmlStreamReader &xml)
 Parse a Services element from Amazon's endpoint XML data. More...
 

Static Protected Attributes

static QHash< QString, HostInfohosts
 Hash of hostnames to HostInfo.
 
static QHash< QString, RegionInforegions
 Hash of region names to RegionInfo.
 
static QHash< QString, ServiceInfoservices
 Hash of service names to ServiceInfo.
 
static QMutex mutex
 Mutex for protecting access to static members.
 

Private Attributes

AwsEndpoint *const q_ptr
 Internal q-pointer.
 

Friends

class TestAwsEndpoint
 
class TestAwsSignatureV4
 

Detailed Description

Private implementation for AwsEndpoint.

Definition at line 37 of file awsendpoint_p.h.

Constructor & Destructor Documentation

AwsEndpointPrivate::AwsEndpointPrivate ( AwsEndpoint *const  q)

Constructs a new AwsEndpointPrivate object.

Parameters
qPointer to this object's public AwsEndpoint instance.
See also
http://aws-sdk-configurations.amazonwebservices.com/endpoints.xml

Definition at line 417 of file awsendpoint.cpp.

References loadEndpointData().

418  : q_ptr(q)
419 {
421 }
static void loadEndpointData(const QString &fileName=QLatin1String(":/aws/endpoints.xml"))
Load endpoint data.
AwsEndpoint *const q_ptr
Internal q-pointer.
Definition: awsendpoint_p.h:89

Member Function Documentation

void AwsEndpointPrivate::loadEndpointData ( const QString &  fileName = QLatin1String(":/aws/endpoints.xml"))
staticprotected

Load endpoint data.

This function parses AWS endpoint data in XML format. The XML data is expected to match the same format as the file provided by Amazon at http://aws-sdk-configurations.amazonwebservices.com/endpoints.xml

If any data has been loaded previously, this function will return immediately with no parsing performed.

Parameters
fileNameName of the endpoint XML data file to load.

Definition at line 437 of file awsendpoint.cpp.

References hosts, and mutex.

Referenced by AwsEndpointPrivate(), AwsEndpoint::fullServiceName(), AwsEndpoint::getEndpoint(), AwsEndpoint::isSupported(), loadEndpointData(), AwsEndpoint::supportedRegions(), and AwsEndpoint::supportedServices().

438 {
439  QMutexLocker locker(&mutex);
440  if (!hosts.empty()) {
441  return; // Already loaded.
442  }
443 
444  // Open the data file.
445  QFile file(fileName);
446  loadEndpointData(file);
447 }
static QMutex mutex
Mutex for protecting access to static members.
Definition: awsendpoint_p.h:77
static void loadEndpointData(const QString &fileName=QLatin1String(":/aws/endpoints.xml"))
Load endpoint data.
static QHash< QString, HostInfo > hosts
Hash of hostnames to HostInfo.
Definition: awsendpoint_p.h:73
void AwsEndpointPrivate::loadEndpointData ( QIODevice &  device)
staticprotected

Load endpoint data.

This function parses AWS endpoint data in XML format. The XML data is expected to match the same format as the file provided by Amazon at http://aws-sdk-configurations.amazonwebservices.com/endpoints.xml

If any data has been loaded previously, this function will return immediately with no parsing performed.

Parameters
deviceDevice to parse XML data from.

Definition at line 463 of file awsendpoint.cpp.

References hosts, loadEndpointData(), and mutex.

464 {
465  QMutexLocker locker(&mutex);
466  if (!hosts.empty()) {
467  return; // Already loaded.
468  }
469 
470  // Open the device, if not already open.
471  if ((!device.isOpen()) && (!device.open(QIODevice::ReadOnly))) {
472  qWarning() << "AwsEndpoint:" << device.errorString();
473  return;
474  }
475 
476  // Parse the data.
477  QXmlStreamReader xml(&device);
478  loadEndpointData(xml);
479 }
static QMutex mutex
Mutex for protecting access to static members.
Definition: awsendpoint_p.h:77
static void loadEndpointData(const QString &fileName=QLatin1String(":/aws/endpoints.xml"))
Load endpoint data.
static QHash< QString, HostInfo > hosts
Hash of hostnames to HostInfo.
Definition: awsendpoint_p.h:73
void AwsEndpointPrivate::loadEndpointData ( QXmlStreamReader &  xml)
staticprotected

Load endpoint data.

This function parses AWS endpoint data in XML format. The XML data is expected to match the same format as the file provided by Amazon at http://aws-sdk-configurations.amazonwebservices.com/endpoints.xml

If any data has been loaded previously, this function will return immediately with no parsing performed.

Parameters
xmlXML document to parse.

Definition at line 495 of file awsendpoint.cpp.

References hosts, mutex, parseRegions(), parseServices(), regions, and services.

496 {
497  QMutexLocker locker(&mutex);
498  if (!hosts.empty()) {
499  return; // Already loaded.
500  }
501 
502  // Parse the XML data.
503  while (xml.readNextStartElement()) {
504  if (xml.name() == QLatin1String("Regions")) {
505  parseRegions(xml);
506  } else if (xml.name() == QLatin1String("Services")) {
507  parseServices(xml);
508  } else if (xml.name() != QLatin1String("XML")) {
509  qDebug() << Q_FUNC_INFO << "ignoring" << xml.name();
510  }
511  }
512  if (xml.hasError()) {
513  qWarning() << "AwsEndpoint:" << xml.errorString();
514  }
515  Q_ASSERT(!xml.hasError());
516  Q_ASSERT(!hosts.isEmpty());
517  Q_ASSERT(!regions.isEmpty());
518  Q_ASSERT(!services.isEmpty());
519 }
static QMutex mutex
Mutex for protecting access to static members.
Definition: awsendpoint_p.h:77
static QHash< QString, RegionInfo > regions
Hash of region names to RegionInfo.
Definition: awsendpoint_p.h:74
static void parseServices(QXmlStreamReader &xml)
Parse a Services element from Amazon's endpoint XML data.
static QHash< QString, ServiceInfo > services
Hash of service names to ServiceInfo.
Definition: awsendpoint_p.h:75
static void parseRegions(QXmlStreamReader &xml)
Parse a Regions element from Amazon's endpoint XML data.
static QHash< QString, HostInfo > hosts
Hash of hostnames to HostInfo.
Definition: awsendpoint_p.h:73
void AwsEndpointPrivate::parseRegion ( QXmlStreamReader &  xml)
staticprotected

Parse a Region element from Amazon's endpoint XML data.

This function parses XML elements like:

1 <Region>
2  <Name>us-east-1</Name>
3  <Endpoint>
4  <ServiceName>cloudformation</ServiceName>
5  <Http>false</Http>
6  <Https>true</Https>
7  <Hostname>cloudformation.us-east-1.amazonaws.com</Hostname>
8  </Endpoint>
9  <Endpoint>
10  <ServiceName>cloudfront</ServiceName>
11  <Http>true</Http>
12  <Https>true</Https>
13  <Hostname>cloudfront.amazonaws.com</Hostname>
14  </Endpoint>
15 </Region>

The parsed entries are automatically added to AwsEndpointPrivate::hosts and AwsEndpointPrivate::regions.

Parameters
xmlXML element to parse.
See also
parseRegion

Definition at line 553 of file awsendpoint.cpp.

References hosts, regionName, regions, and serviceName.

Referenced by parseRegions().

554 {
555  QString regionName;
556  while ((!xml.atEnd()) && (xml.readNextStartElement())) {
557  if (xml.name() == QLatin1String("Name")) {
558  regionName = xml.readElementText();
559  } else if (xml.name() == QLatin1String("Endpoint")) {
560  Q_ASSERT(!regionName.isEmpty());
561  RegionEndpointInfo endpoint;
562  QString serviceName;
563  while ((!xml.atEnd()) && (xml.readNextStartElement())) {
564  if (xml.name() == QLatin1String("ServiceName")) {
565  serviceName = xml.readElementText();
566  } else if (xml.name() == QLatin1String("Http")) {
567  if (xml.readElementText() == QLatin1String("true")) {
568  endpoint.transports |= AwsEndpoint::HTTP;
569  }
570  } else if (xml.name() == QLatin1String("Https")) {
571  if (xml.readElementText() == QLatin1String("true")) {
572  endpoint.transports |= AwsEndpoint::HTTPS;
573  }
574  } else if (xml.name() == QLatin1String("Hostname")) {
575  endpoint.hostName = xml.readElementText();
576  } else {
577  qDebug() << Q_FUNC_INFO << "ignoring" << xml.name();
578  xml.skipCurrentElement();
579  }
580  }
581  Q_ASSERT(!serviceName.isEmpty());
582 
583  if (serviceName == QLatin1String("email")) {
584  endpoint.transports |= AwsEndpoint::SMTP;
585  }
586 
587  Q_ASSERT((!hosts.contains(endpoint.hostName)) || (hosts.value(endpoint.hostName).serviceName == serviceName));
588  hosts[endpoint.hostName].regionNames.append(regionName);
589  hosts[endpoint.hostName].serviceName = serviceName;
590  regions[regionName].services[serviceName] = endpoint;
591  //qDebug() << Q_FUNC_INFO << regionName << serviceName << (int)endpoint.transports << endpoint.hostName;
592  } else {
593  qDebug() << Q_FUNC_INFO << "ignoring" << xml.name();
594  xml.skipCurrentElement();
595  }
596  }
597 }
static QHash< QString, RegionInfo > regions
Hash of region names to RegionInfo.
Definition: awsendpoint_p.h:74
QString regionName
This endpoint's region name.
Definition: awsendpoint_p.h:41
QString serviceName
This endpoint's service name.
Definition: awsendpoint_p.h:42
static QHash< QString, HostInfo > hosts
Hash of hostnames to HostInfo.
Definition: awsendpoint_p.h:73
void AwsEndpointPrivate::parseRegions ( QXmlStreamReader &  xml)
staticprotected

Parse a Regions element from Amazon's endpoint XML data.

This function parse an XML element containing a list of Region elements. See AwsEndpointPrivate::parseRegion for the Region element format.

The parsed entries are automatically added to AwsEndpointPrivate::hosts and AwsEndpointPrivate::regions.

Parameters
xmlXML element containing regions to parse.
See also
parseRegion

Definition at line 614 of file awsendpoint.cpp.

References parseRegion().

Referenced by loadEndpointData().

615 {
616  while ((!xml.atEnd()) && (xml.readNextStartElement())) {
617  if (xml.name() == QLatin1String("Region")) {
618  parseRegion(xml);
619  } else {
620  qDebug() << Q_FUNC_INFO << "ignoring" << xml.name();
621  xml.skipCurrentElement();
622  }
623  }
624 }
static void parseRegion(QXmlStreamReader &xml)
Parse a Region element from Amazon's endpoint XML data.
void AwsEndpointPrivate::parseService ( QXmlStreamReader &  xml)
staticprotected

Parse a Service element from Amazon's endpoint XML data.

This function parses XML elements like:

1 <Service>
2  <Name>cloudformation</Name>
3  <FullName>Amazon CloudFormation</FullName>
4  <RegionName>us-east-1</RegionName>
5  <RegionName>us-west-1</RegionName>
6  <RegionName>us-west-2</RegionName>
7  <RegionName>eu-west-1</RegionName>
8  <RegionName>ap-northeast-1</RegionName>
9  <RegionName>ap-southeast-1</RegionName>
10  <RegionName>ap-southeast-2</RegionName>
11  <RegionName>sa-east-1</RegionName>
12 </Service>

The parsed entries are automatically added to AwsEndpointPrivate::services.

Parameters
xmlXML element to parse.
See also
parseServices

Definition at line 654 of file awsendpoint.cpp.

References regionName, serviceName, and services.

Referenced by parseServices().

655 {
656  QString serviceName;
657  while ((!xml.atEnd()) && (xml.readNextStartElement())) {
658  if (xml.name() == QLatin1String("Name")) {
659  serviceName = xml.readElementText();
660  } else if (xml.name() == QLatin1String("FullName")) {
661  Q_ASSERT(!serviceName.isEmpty());
662  services[serviceName].fullName = xml.readElementText();
663  } else if (xml.name() == QLatin1String("RegionName")) {
664  Q_ASSERT(!serviceName.isEmpty());
665  const QString &regionName = xml.readElementText();
666  services[serviceName].regionNames.append(regionName);
667  //qDebug() << Q_FUNC_INFO << serviceName << services[serviceName].fullName << regionName;
668  } else {
669  qDebug() << Q_FUNC_INFO << "ignoring" << xml.name();
670  xml.skipCurrentElement();
671  }
672  }
673 }
QString regionName
This endpoint's region name.
Definition: awsendpoint_p.h:41
QString serviceName
This endpoint's service name.
Definition: awsendpoint_p.h:42
static QHash< QString, ServiceInfo > services
Hash of service names to ServiceInfo.
Definition: awsendpoint_p.h:75
void AwsEndpointPrivate::parseServices ( QXmlStreamReader &  xml)
staticprotected

Parse a Services element from Amazon's endpoint XML data.

This function parses an XML element containing a list of Service elements. See AwsEndpointPrivate::parseServices for the Service element format.

The parsed entries are automatically added to AwsEndpointPrivate::services.

Parameters
xmlXML element containing services to parse.
See also
parseService

Definition at line 689 of file awsendpoint.cpp.

References parseService().

Referenced by loadEndpointData().

690 {
691  while ((!xml.atEnd()) && (xml.readNextStartElement())) {
692  if (xml.name() == QLatin1String("Service")) {
693  parseService(xml);
694  } else {
695  qDebug() << Q_FUNC_INFO << "ignoring" << xml.name();
696  xml.skipCurrentElement();
697  }
698  }
699 }
static void parseService(QXmlStreamReader &xml)
Parse a Service element from Amazon's endpoint XML data.

The documentation for this class was generated from the following files: