0% found this document useful (0 votes)
99 views16 pages

Uri and Uuid: Identifying Things On The Web

Poco URI and UUID

Uploaded by

Giap
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
99 views16 pages

Uri and Uuid: Identifying Things On The Web

Poco URI and UUID

Uploaded by

Giap
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 16

URI and UUID

Identifying things on the Web.

Overview
>
>
>

Uniform Resource Identifiers (URIs)


URIStreamOpener
Universally Unique Identifiers (UUIDs)

Uniform Resource Identifiers


>
>
>

Uniform Resource Identifiers (RFC 3986) are used to identify


resources on the Web.
POCO provides the POCO::URI class that can be used for building
and storing URIs and to split URIs into their components.
#include "Poco/URI.h"

URI Structure
>

An URI consists of:

>
>
>
>
>

a Scheme (or protocol name) part


an Authority part
(user information, host name and port number)
a Path part
a Query part
and a Fragment part

URI Examples
http://www.google.com/search?q=POCO

Scheme

Host

Path

Query

URI Examples (cont'd)


http://appinf.com/poco/docs/Poco.URI.html#5589

Scheme

Host

Path

Fragment

URI Examples (cont'd)


ftp://[email protected]/incoming

Scheme

User

Host

Path

#include "Poco/URI.h"
#include <iostream>
int main(int argc, char** argv)
{
Poco::URI uri1("http://www.appinf.com:88/sample?example-query#frag");
std::string scheme(uri1.getScheme());
std::string auth(uri1.getAuthority());
std::string host(uri1.getHost());
unsigned short port = uri1.getPort();
std::string path(uri1.getPath());
std::string query(uri1.getQuery());
std::string frag(uri1.getFragment());
std::string pathEtc(uri1.getPathEtc());
query#frag"

//
//
//
//
//
//
//
//

"http"
"www.appinf.com:88"
"www.appinf.com"
88
"/sample"
"example-query"
"frag"
"/sample?example-

Poco::URI uri2;
uri2.setScheme("https");
uri2.setAuthority("www.appinf.com");
uri2.setPath("/another sample");
std::string s(uri2.toString());
// "https://www.appinf.com/another%20sample"

std::string uri3("http://www.appinf.com");
uri3.resolve("/poco/info/index.html");
s = uri3.toString(); // "http://www.appinf.com/poco/info/index.html"
uri3.resolve("support.html");
s = uri3.toString(); // "http://www.appinf.com/poco/info/support.html"
uri3.resolve("http://sourceforge.net/projects/poco");
s = uri3.toString(); // "http://sourceforge.net/projects/poco"
}

return 0;

URIStreamOpener
>
>
>
>

Poco::URIStreamOpener is used to create and open input streams


for resources identified by URIs.
#include "Poco/URIStreamOpener.h"
For every URI scheme used, a subclass of Poco::URIStreamFactory
must be registered.
POCO provides stream factories for files, HTTP, HTTPS and FTP
resources.

#include
#include
#include
#include

"Poco/URIStreamOpener.h"
"Poco/Net/HTTPStreamFactory.h"
"Poco/Net/FTPStreamFactory.h"
<memory>

int main(int argc, char** argv)


{
Poco::Net::HTTPStreamFactory::registerFactory();
Poco::Net::FTPStreamFactory::registerFactory();
Poco::URIStreamOpener& opener =
Poco::URIStreamOpener::defaultOpener();

std::auto_ptr<std::istream> istr1(
opener.open("http://www.appinf.com/index.html")
);
std::auto_ptr<std::istream> istr2(
opener.open("ftp://ftp.appinf.com/pub/poco/poco-1.2.5.tar.gz")
);
std::auto_ptr<std::istream> istr3(
opener.open("file:///usr/include/stdio.h")
);
return 0;

UUIDs
>
>

A UUID (Universally Unique Identifier) is an identifier that is


unique across both space and time, with respect to the space of
all UUIDs.
Three flavors:

>
>
>

time-based
name-based
random

The UUID Class


>
>
>

Poco::UUID stores a UUID, supporting full value semantics


including all relational operators.
#include "Poco/UUID.h"
UUIDs can be converted to and from strings.

The UUIDGenerator Class


>
>
>

Poco::UUIDGenerator is used to create UUIDs.


#include "Poco/UUIDGenerator.h"
UUIDs can be created

>
>
>

time based (ethernet MAC address + timestamp)


name-based (usually from an URI)
random

#include "Poco/UUID.h"
#include "Poco/UUIDGenerator.h"
#include <iostream>
using Poco::UUID;
using Poco::UUIDGenerator;
int main(int argc, char** argv)
{
UUIDGenerator& generator = UUIDGenerator::defaultGenerator();
UUID uuid1(generator.create()); // time based
UUID uuid2(generator.createRandom());
UUID uuid3(generator.createFromName(UUID::uri(), "http://appinf.com");
std::cout << uuid1.toString() << std::endl;
std::cout << uuid2.toString() << std::endl;
std::cout << uuid3.toString() << std::endl;
}

return 0;

Copyright 2006-2010 by Applied Informatics Software Engineering GmbH.


Some rights reserved.
www.appinf.com | [email protected]
T +43 4253 32596 | F +43 4253 32096

You might also like