summaryrefslogtreecommitdiffstats
path: root/branches/1.0/tinyMSRP/test/test/test_uri.h
blob: a59d7a314e9c003321f11655242c4570fbab4eb7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
/*
* Copyright (C) 2009 Mamadou Diop.
*
* Contact: Mamadou Diop <diopmamadou(at)yahoo.fr>
*
* This file is part of Open Source Doubango Framework.
*
* DOUBANGO is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* DOUBANGO is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with DOUBANGO.
*
*/
#ifndef _TEST_MSRPURI_H
#define _TEST_MSRPURI_H

#include "tinymsrp/parsers/tmsrp_parser_uri.h"

const char* uris[] = 
{
	"msrp://atlanta.example.com:7654/jshA7weztas;tcp;p1=1;p2=2",
	"msrps://atlanta.example.com:7654/jshA7weztas;tcp",

	// hostname, IPv4 and IPv6 (without userinfo and with port)
	"msrp://biloxi.msrp.com:12763/kjhd37s2s20w2a;sctp",
	"msrps://192.168.0.10:7654/jshA7weztas;tcp;p3=4",
	"msrps://[::127]:7654/jshA7weztas;tcp;p=0",

	// hostname, IPv4 and IPv6 (without userinfo and without port)
	"msrp://biloxi.msrp.com/kjhd37s2s20w2a;sctp",
	"msrps://192.168.0.10/jshA7weztas;tcp;p3=4",
	"msrps://[::127]/jshA7weztas;tcp;p=0",

	// hostname, IPv4 and IPv6 (with userinfo and with port)
	"msrp://bob@biloxi.msrp.com:12763/kjhd37s2s20w2a;sctp",
	"msrps://alice@192.168.0.10:7654/jshA7weztas;tcp;p3=4",
	"msrps://carol@[::127]:7654/jshA7weztas;tcp;p=0",

	// hostname, IPv4 and IPv6 (with userinfo and without port)
	"msrp://bob@biloxi.msrp.com/kjhd37s2s20w2a;sctp",
	"msrps://alice@192.168.0.10/jshA7weztas;tcp;p3=4",
	"msrps://carol@[::127]/jshA7weztas;tcp;p=0",

	// without session_id
	"msrps://[::127]:7654;tcp;p=0",
};

void test_uri_tostring(const tmsrp_uri_t *uri)
{
	char* ret = tmsrp_uri_tostring(uri);
	TSK_DEBUG_INFO("uri_to_string=%s", ret);
	TSK_FREE(ret);
}

void test_uri_parser()
{
	int i;
	tsk_list_item_t *item = 0;

	for(i=0; i<sizeof(uris)/sizeof(const char*); i++)
	{
		tmsrp_uri_t *uri = tmsrp_uri_parse(uris[i], strlen(uris[i]));
				
		printf("\n== Parsing {{ %s }} ==\n\n", uris[i]);
		
		if(uri)
		{
			printf("scheme: %s\n", uri->scheme);
			printf("userinfo: %s\n", uri->authority.userinfo);
			printf("host: %s\n", uri->authority.host);
			printf("port: %d\n", uri->authority.port);
			printf("host-type: %s\n", uri->authority.host_type == tmsrp_host_ipv4 ? "IPv4" : (uri->authority.host_type == tmsrp_host_ipv6 ? "IPv6" : (uri->authority.host_type == tmsrp_host_hostname ? "HOSTNAME" : "UNKNOWN")) );
			printf("session-id: %s\n", uri->session_id);
			printf("transport: %s\n", uri->transport);
			
			printf("---PARAMS---\n");

			/* dump all parameters */
			tsk_list_foreach(item, uri->params){
				tsk_param_t* param = item->data;
				printf("-->%s=%s\n", param->name, param->value);
			}

			printf("Is-secure: %s\n", TMSRP_URI_IS_SECURE(uri) ? "YES" : "NO");

			test_uri_tostring(uri);
		}
		else{
			printf("INVALID MSRP URI.\n");
		}

		printf("\n\n");
		getchar();
		
		TSK_OBJECT_SAFE_FREE(uri);
	}
}


void test_uri()
{
	test_uri_parser();
}

#endif /* _TEST_MSRPURI_H */
OpenPOWER on IntegriCloud