~ubuntu-branches/ubuntu/quantal/zeroc-ice/quantal

« back to all changes in this revision

Viewing changes to cpp/src/Ice/UdpEndpointI.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Cleto Martin Angelina
  • Date: 2011-04-25 18:44:24 UTC
  • mfrom: (6.1.14 sid)
  • Revision ID: james.westby@ubuntu.com-20110425184424-sep9i9euu434vq4c
Tags: 3.4.1-7
* Bug fix: "libdb5.1-java.jar was renamed to db.jar", thanks to Ondřej
  Surý (Closes: #623555).
* Bug fix: "causes noise in php5", thanks to Jayen Ashar (Closes:
  #623533).

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
// **********************************************************************
2
2
//
3
 
// Copyright (c) 2003-2009 ZeroC, Inc. All rights reserved.
 
3
// Copyright (c) 2003-2010 ZeroC, Inc. All rights reserved.
4
4
//
5
5
// This copy of Ice is licensed to you under the terms described in the
6
6
// ICE_LICENSE file included in this distribution.
16
16
#include <Ice/Instance.h>
17
17
#include <Ice/DefaultsAndOverrides.h>
18
18
#include <Ice/Protocol.h>
 
19
#include <Ice/HashUtil.h>
19
20
 
20
21
using namespace std;
21
22
using namespace Ice;
73
74
        if(option[0] != '-')
74
75
        {
75
76
            EndpointParseException ex(__FILE__, __LINE__);
76
 
            ex.str = "udp " + str;
 
77
            ex.str = "expected an endpoint option but found `" + option + "' in endpoint `udp " + str + "'";
77
78
            throw ex;
78
79
        }
79
80
 
88
89
                if(end == string::npos)
89
90
                {
90
91
                    EndpointParseException ex(__FILE__, __LINE__);
91
 
                    ex.str = "udp " + str;
 
92
                    ex.str = "mismatched quotes around `" + argument + "' in endpoint `udp " + str + "'";
92
93
                    throw ex;
93
94
                }
94
95
                else
116
117
            if(argument.empty())
117
118
            {
118
119
                EndpointParseException ex(__FILE__, __LINE__);
119
 
                ex.str = "udp " + str;
 
120
                ex.str = "no argument provided for -v option in endpoint `udp " + str + "'";
120
121
                throw ex;
121
122
            }
122
123
 
124
125
            if(pos == string::npos)
125
126
            {
126
127
                EndpointParseException ex(__FILE__, __LINE__);
127
 
                ex.str = "udp " + str;
 
128
                ex.str = "malformed protocol version `" + argument + "' in endpoint `udp " + str + "'";
128
129
                throw ex;
129
130
            }
130
131
            string majorStr = argument.substr(0, pos);
135
136
            if(!(majStr >> majVersion) || !majStr.eof())
136
137
            {
137
138
                EndpointParseException ex(__FILE__, __LINE__);
138
 
                ex.str = "udp " + str;
 
139
                ex.str = "invalid protocol major version `" + argument + "' in endpoint `udp " + str + "'";
139
140
                throw ex;
140
141
            }
141
142
 
144
145
            if(!(minStr >> minVersion) || !minStr.eof())
145
146
            {
146
147
                EndpointParseException ex(__FILE__, __LINE__);
147
 
                ex.str = "udp " + str;
 
148
                ex.str = "invalid protocol minor version `" + argument + "' in endpoint `udp " + str + "'";
148
149
                throw ex;
149
150
            }
150
151
 
151
152
            if(majVersion < 1 || majVersion > 255 || minVersion < 0 || minVersion > 255)
152
153
            {
153
154
                EndpointParseException ex(__FILE__, __LINE__);
154
 
                ex.str = "udp " + str;
 
155
                ex.str = "range error in protocol version `" + argument + "' in endpoint `udp " + str + "'";
155
156
                throw ex;
156
157
            }
157
158
 
173
174
            if(argument.empty())
174
175
            {
175
176
                EndpointParseException ex(__FILE__, __LINE__);
176
 
                ex.str = "udp " + str;
 
177
                ex.str = "no argument provided for -e option in endpoint `udp " + str + "'";
177
178
                throw ex;
178
179
            }
179
180
            string::size_type pos = argument.find('.');
185
186
            if(!(majStr >> majVersion) || !majStr.eof())
186
187
            {
187
188
                EndpointParseException ex(__FILE__, __LINE__);
188
 
                ex.str = "udp " + str;
 
189
                ex.str = "invalid encoding major version `" + argument + "' in endpoint `udp " + str + "'";
189
190
                throw ex;
190
191
            }
191
192
 
194
195
            if(!(minStr >> minVersion) || !minStr.eof())
195
196
            {
196
197
                EndpointParseException ex(__FILE__, __LINE__);
197
 
                ex.str = "udp " + str;
 
198
                ex.str = "invalid encoding minor version `" + argument + "' in endpoint `udp " + str + "'";
198
199
                throw ex;
199
200
            }
200
201
 
201
202
            if(majVersion < 1 || majVersion > 255 || minVersion < 0 || minVersion > 255)
202
203
            {
203
204
                EndpointParseException ex(__FILE__, __LINE__);
204
 
                ex.str = "udp " + str;
 
205
                ex.str = "range error in encoding version `" + argument + "' in endpoint `udp " + str + "'";
205
206
                throw ex;
206
207
            }
207
208
 
223
224
            if(argument.empty())
224
225
            {
225
226
                EndpointParseException ex(__FILE__, __LINE__);
226
 
                ex.str = "udp " + str;
 
227
                ex.str = "no argument provided for -h option in endpoint `udp " + str + "'";
227
228
                throw ex;
228
229
            }
229
230
            const_cast<string&>(_host) = argument;
230
231
        }
231
232
        else if(option == "-p")
232
233
        {
 
234
            if(argument.empty())
 
235
            {
 
236
                EndpointParseException ex(__FILE__, __LINE__);
 
237
                ex.str = "no argument provided for -p option in endpoint `udp " + str + "'";
 
238
                throw ex;
 
239
            }
233
240
            istringstream p(argument);
234
 
            if(!(p >> const_cast<Int&>(_port)) || !p.eof() || _port < 0 || _port > 65535)
235
 
            {
236
 
                EndpointParseException ex(__FILE__, __LINE__);
237
 
                ex.str = "udp " + str;
 
241
            if(!(p >> const_cast<Int&>(_port)) || !p.eof())
 
242
            {
 
243
                EndpointParseException ex(__FILE__, __LINE__);
 
244
                ex.str = "invalid port value `" + argument + "' in endpoint `udp " + str + "'";
 
245
                throw ex;
 
246
            }
 
247
            else if(_port < 0 || _port > 65535)
 
248
            {
 
249
                EndpointParseException ex(__FILE__, __LINE__);
 
250
                ex.str = "port value `" + argument + "' out of range in endpoint `udp " + str + "'";
238
251
                throw ex;
239
252
            }
240
253
        }
243
256
            if(!argument.empty())
244
257
            {
245
258
                EndpointParseException ex(__FILE__, __LINE__);
246
 
                ex.str = "udp " + str;
 
259
                ex.str = "unexpected argument `" + argument + "' provided for -c option in `udp " + str + "'";
247
260
                throw ex;
248
261
            }
249
262
            const_cast<bool&>(_connect) = true;
253
266
            if(!argument.empty())
254
267
            {
255
268
                EndpointParseException ex(__FILE__, __LINE__);
256
 
                ex.str = "udp " + str;
 
269
                ex.str = "unexpected argument `" + argument + "' provided for -z option in `udp " + str + "'";
257
270
                throw ex;
258
271
            }
259
272
            const_cast<bool&>(_compress) = true;
263
276
            if(argument.empty())
264
277
            {
265
278
                EndpointParseException ex(__FILE__, __LINE__);
266
 
                ex.str = "udp " + str;
 
279
                ex.str = "no argument provided for --interface option in endpoint `udp " + str + "'";
267
280
                throw ex;
268
281
            }
269
282
            const_cast<string&>(_mcastInterface) = argument;
270
283
        }
271
284
        else if(option == "--ttl")
272
285
        {
 
286
            if(argument.empty())
 
287
            {
 
288
                EndpointParseException ex(__FILE__, __LINE__);
 
289
                ex.str = "no argument provided for --ttl option in endpoint `udp " + str + "'";
 
290
                throw ex;
 
291
            }
273
292
            istringstream p(argument);
274
293
            if(!(p >> const_cast<Int&>(_mcastTtl)) || !p.eof())
275
294
            {
276
295
                EndpointParseException ex(__FILE__, __LINE__);
277
 
                ex.str = "udp " + str;
 
296
                ex.str = "invalid TTL value `" + argument + "' in endpoint `udp " + str + "'";
278
297
                throw ex;
279
298
            }
280
299
        }
281
300
        else
282
301
        {
283
302
            EndpointParseException ex(__FILE__, __LINE__);
284
 
            ex.str = "udp " + str;
 
303
            ex.str = "unknown option `" + option + "' in `udp " + str + "'";
285
304
            throw ex;
286
305
        }
287
306
    }
299
318
        else
300
319
        {
301
320
            EndpointParseException ex(__FILE__, __LINE__);
302
 
            ex.str = "udp " + str;
 
321
            ex.str = "`-h *' not valid for proxy endpoint `udp " + str + "'";
303
322
            throw ex;
304
323
        }
305
324
    }
350
369
void
351
370
IceInternal::UdpEndpointI::streamWrite(BasicStream* s) const
352
371
{
353
 
    s->write(UdpEndpointType);
 
372
    s->write(UDPEndpointType);
354
373
    s->startWriteEncaps();
355
374
    s->write(_host, false);
356
375
    s->write(_port);
432
451
    return s.str();
433
452
}
434
453
 
 
454
EndpointInfoPtr
 
455
IceInternal::UdpEndpointI::getInfo() const
 
456
{
 
457
    class InfoI : public Ice::UDPEndpointInfo
 
458
    {
 
459
    public:
 
460
 
 
461
        InfoI(bool comp, const string& host, Ice::Int port, Ice::Byte protocolMajor, Ice::Byte protocolMinor, 
 
462
              Ice::Byte encodingMajor, Ice::Byte encodingMinor, const std::string& mcastInterface, Ice::Int mcastTtl) :
 
463
            UDPEndpointInfo(-1, comp, host, port, protocolMajor, protocolMinor, encodingMajor, encodingMinor,
 
464
                            mcastInterface, mcastTtl)
 
465
        {
 
466
        }
 
467
 
 
468
        virtual Ice::Short
 
469
        type() const
 
470
        {
 
471
            return UDPEndpointType;
 
472
        }
 
473
        
 
474
        virtual bool
 
475
        datagram() const
 
476
        {
 
477
            return true;
 
478
        }
 
479
 
 
480
        virtual bool
 
481
        secure() const
 
482
        {
 
483
            return false;
 
484
        }
 
485
    };
 
486
 
 
487
    return new InfoI(_compress, _host, _port, _protocolMajor, _protocolMinor, _encodingMajor, _encodingMinor, 
 
488
                     _mcastInterface, _mcastTtl);
 
489
}
 
490
 
435
491
Short
436
492
IceInternal::UdpEndpointI::type() const
437
493
{
438
 
    return UdpEndpointType;
 
494
    return UDPEndpointType;
439
495
}
440
496
 
441
497
Int
496
552
    return false;
497
553
}
498
554
 
499
 
bool
500
 
IceInternal::UdpEndpointI::unknown() const
501
 
{
502
 
    return false;
503
 
}
504
 
 
505
555
TransceiverPtr
506
556
IceInternal::UdpEndpointI::transceiver(EndpointIPtr& endp) const
507
557
{
535
585
IceInternal::UdpEndpointI::expand() const
536
586
{
537
587
    vector<EndpointIPtr> endps;
538
 
    vector<string> hosts = getHostsForEndpointExpand(_host, _instance->protocolSupport());
 
588
    vector<string> hosts = getHostsForEndpointExpand(_host, _instance->protocolSupport(), false);
539
589
    if(hosts.empty())
540
590
    {
541
591
        endps.push_back(const_cast<UdpEndpointI*>(this));
564
614
}
565
615
 
566
616
bool
567
 
IceInternal::UdpEndpointI::operator==(const EndpointI& r) const
 
617
IceInternal::UdpEndpointI::operator==(const LocalObject& r) const
568
618
{
569
619
    const UdpEndpointI* p = dynamic_cast<const UdpEndpointI*>(&r);
570
620
    if(!p)
636
686
}
637
687
 
638
688
bool
639
 
IceInternal::UdpEndpointI::operator!=(const EndpointI& r) const
640
 
{
641
 
    return !operator==(r);
642
 
}
643
 
 
644
 
bool
645
 
IceInternal::UdpEndpointI::operator<(const EndpointI& r) const
 
689
IceInternal::UdpEndpointI::operator<(const LocalObject& r) const
646
690
{
647
691
    const UdpEndpointI* p = dynamic_cast<const UdpEndpointI*>(&r);
648
692
    if(!p)
649
693
    {
650
 
        return type() < r.type();
 
694
        const EndpointI* e = dynamic_cast<const EndpointI*>(&r);
 
695
        if(!e)
 
696
        {
 
697
            return false;
 
698
        }
 
699
        return type() < e->type();
651
700
    }
652
701
 
653
702
    if(this == p)
757
806
    return false;
758
807
}
759
808
 
 
809
Ice::Int
 
810
IceInternal::UdpEndpointI::hashInit() const
 
811
{
 
812
    Ice::Int h = 0;
 
813
    hashAdd(h, _host);
 
814
    hashAdd(h, _port);
 
815
    hashAdd(h, _mcastInterface);
 
816
    hashAdd(h, _mcastTtl);
 
817
    hashAdd(h, _connect);
 
818
    hashAdd(h, _connectionId);
 
819
    hashAdd(h, _compress);
 
820
    return h;
 
821
}
 
822
 
760
823
vector<ConnectorPtr>
761
824
IceInternal::UdpEndpointI::connectors(const vector<struct sockaddr_storage>& addresses) const
762
825
{
781
844
Short
782
845
IceInternal::UdpEndpointFactory::type() const
783
846
{
784
 
    return UdpEndpointType;
 
847
    return UDPEndpointType;
785
848
}
786
849
 
787
850
string