| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
# Copyright (C) 2004 Domingo Alcázar Larrea |
|
2
|
|
|
|
|
|
|
# |
|
3
|
|
|
|
|
|
|
# This program is free software; you can redistribute it and/or |
|
4
|
|
|
|
|
|
|
# modify it under the terms of the version 2 of the GNU General |
|
5
|
|
|
|
|
|
|
# Public License as published by the Free Software Foundation. |
|
6
|
|
|
|
|
|
|
# |
|
7
|
|
|
|
|
|
|
# This program is distributed in the hope that it will be useful, |
|
8
|
|
|
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
9
|
|
|
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
10
|
|
|
|
|
|
|
# GNU General Public License for more details. |
|
11
|
|
|
|
|
|
|
# |
|
12
|
|
|
|
|
|
|
# You should have received a copy of the GNU General Public License |
|
13
|
|
|
|
|
|
|
# along with this program; if not, write to the Free Software |
|
14
|
|
|
|
|
|
|
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307 |
|
15
|
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
package DIME::Tools; |
|
18
|
|
|
|
|
|
|
$DIME::Tools::VERSION = '0.05'; |
|
19
|
1
|
|
|
1
|
|
718
|
use 5.008; |
|
|
1
|
|
|
|
|
4
|
|
|
20
|
1
|
|
|
1
|
|
6
|
use strict; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
20
|
|
|
21
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
54
|
|
|
22
|
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
1; |
|
25
|
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
=encoding UTF-8 |
|
27
|
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
=head1 NAME |
|
29
|
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
DIME::Tools - modules for parsing and generate DIME messages |
|
31
|
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
33
|
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
Generating DIME messages |
|
35
|
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
my $payload = DIME::Payload->new(); |
|
37
|
|
|
|
|
|
|
$payload->attach(Path => "/mydata/index.html", |
|
38
|
|
|
|
|
|
|
MIMEType => 'text/html', |
|
39
|
|
|
|
|
|
|
Dynamic => 1); |
|
40
|
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
my $payload2 = DIME::Payload->new(); |
|
42
|
|
|
|
|
|
|
$payload2->attach( Data => "HELLO WORLD!!!", |
|
43
|
|
|
|
|
|
|
MIMEType => 'text/plain' ); |
|
44
|
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
my $message = DIME::Message->new(); |
|
46
|
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
my $payload = DIME::Payload->new(); |
|
48
|
|
|
|
|
|
|
$payload->attach(Path => "/mydata/index.html", |
|
49
|
|
|
|
|
|
|
MIMEType => 'text/html', |
|
50
|
|
|
|
|
|
|
Dynamic => 1); |
|
51
|
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
$message->add_payload($payload); |
|
53
|
|
|
|
|
|
|
$message->add_payload($payload2); |
|
54
|
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
# Print the encoded message to STDOUT |
|
56
|
|
|
|
|
|
|
$message->print(\*STDOUT); |
|
57
|
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
Parsing DIME messages |
|
59
|
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
my $parser = DIME::Parser->new(); |
|
61
|
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
# Open a file with a dime encoded message |
|
63
|
|
|
|
|
|
|
$f = IO::File->new("dime.message","r"); |
|
64
|
|
|
|
|
|
|
my $message = $parser->parse($f); |
|
65
|
|
|
|
|
|
|
$f->close(); |
|
66
|
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
# Print the content of each payload to STDOUT |
|
68
|
|
|
|
|
|
|
for my $i ($message->payloads()) |
|
69
|
|
|
|
|
|
|
{ |
|
70
|
|
|
|
|
|
|
print $i->print_content(\*STDOUT); |
|
71
|
|
|
|
|
|
|
} |
|
72
|
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
75
|
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
DIME-tools is a collection of DIME:: modules for parsing and generating DIME encoded messages |
|
77
|
|
|
|
|
|
|
(Direct Internet Message Encapsulation). |
|
78
|
|
|
|
|
|
|
DIME-tools support single-record and chunked payloads for sending big attachments. |
|
79
|
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
This distribution hasn't been actively developed since 2004. |
|
81
|
|
|
|
|
|
|
Subsequent releases have been to get the distribution following CPAN conventions, |
|
82
|
|
|
|
|
|
|
as there is one distribution depending on it |
|
83
|
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
=head1 GENERATING MESSAGES |
|
85
|
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
For any content you want to send in a message, you have to create a Payload object: |
|
87
|
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
my $payload = DIME::Payload->new(); |
|
89
|
|
|
|
|
|
|
$payload->attach(Path => "/mydata/index.html", |
|
90
|
|
|
|
|
|
|
MIMEType => 'text/html', |
|
91
|
|
|
|
|
|
|
Dynamic => 1); |
|
92
|
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
With the attach method you can specify the next keys: |
|
94
|
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
=over 4 |
|
96
|
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
=item B: |
|
98
|
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
the name of the file you want to attach to the payload object. |
|
100
|
|
|
|
|
|
|
If the data you want to attach isn't in a file, you can use the Data key. |
|
101
|
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
=item B: |
|
103
|
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
it's the reference to a scalar in which you store the data you want to attach. |
|
105
|
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
=item B: |
|
107
|
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
if Path is declared, the data is not loaded fully in memory. |
|
109
|
|
|
|
|
|
|
The only that you attach to the payload object is the name of the file of the Path key, |
|
110
|
|
|
|
|
|
|
not the content itself. |
|
111
|
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
=item B: |
|
113
|
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
if it's declared, it represents the size of the chunk records in bytes. |
|
115
|
|
|
|
|
|
|
If you don't declare it, the message will not be chunked. |
|
116
|
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
=item B: |
|
118
|
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
the type of the payload. It must be a string with a MIME standard type. Other possibility is to use URIType. |
|
120
|
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
=item B: |
|
122
|
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
specifies an URI that defines that type of the content. |
|
124
|
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
=back |
|
126
|
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
=head1 ATTACH A PAYLOAD TO A MESSAGE |
|
128
|
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
my $message = DIME::Message->new(); |
|
130
|
|
|
|
|
|
|
$message->add_payload($payload); |
|
131
|
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
=head1 PRINT A ENCODED MESSAGE |
|
133
|
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
# Print prints to any IO::Handle |
|
135
|
|
|
|
|
|
|
$message->print(\*STDOUT); |
|
136
|
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
or |
|
138
|
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
# print_data returns a reference to a scalar |
|
140
|
|
|
|
|
|
|
print ${$message->print_data()}; |
|
141
|
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
=head1 PARSING MESSAGES |
|
143
|
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
All you have to do is create a DIME::Parser object and call the parse method with a IO::Handle to a DIME message. Then you can iterate over the $message->payloads() array to get the contents of the message: |
|
145
|
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
my $parser = DIME::Parser->new(); |
|
147
|
|
|
|
|
|
|
$f = IO::File->new("dime.message","r"); |
|
148
|
|
|
|
|
|
|
my $message = $parser->parse($f); |
|
149
|
|
|
|
|
|
|
$f->close(); |
|
150
|
|
|
|
|
|
|
for my $i ($message->payloads()) |
|
151
|
|
|
|
|
|
|
{ |
|
152
|
|
|
|
|
|
|
print $i->print_content(\*STDOUTs); |
|
153
|
|
|
|
|
|
|
} |
|
154
|
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
You can also call to parse_data if you have a DIME message in a scalar variable: |
|
156
|
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
my $dime_message; |
|
158
|
|
|
|
|
|
|
my $message = $parser->parse_data(\$dime_message); |
|
159
|
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
And call print_content_data if what you want is to get a reference to the content-data. |
|
161
|
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
=head1 SEE ALSO |
|
163
|
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
Direct Internet Message Encapsulation draft: |
|
165
|
|
|
|
|
|
|
http://www.gotdotnet.com/team/xml_wsspecs/dime/dime.htm |
|
166
|
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
L, |
|
168
|
|
|
|
|
|
|
L, |
|
169
|
|
|
|
|
|
|
L. |
|
170
|
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
=head1 AUTHOR |
|
172
|
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
Domingo Alcazar Larrea, Edalcazar@cpan.orgE |
|
174
|
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
|
176
|
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
Copyright (C) 2004 Domingo Alcázar Larrea |
|
179
|
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or |
|
181
|
|
|
|
|
|
|
modify it under the terms of the version 2 of the GNU General |
|
182
|
|
|
|
|
|
|
Public License as published by the Free Software Foundation. |
|
183
|
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful, |
|
185
|
|
|
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
186
|
|
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
187
|
|
|
|
|
|
|
GNU General Public License for more details. |
|
188
|
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License |
|
190
|
|
|
|
|
|
|
along with this program; if not, write to the Free Software |
|
191
|
|
|
|
|
|
|
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307 |
|
192
|
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
=cut |