~ubuntu-branches/ubuntu/breezy/orbit2/breezy

« back to all changes in this revision

Viewing changes to src/orb/orb-core/iop-profiles.c

  • Committer: Bazaar Package Importer
  • Author(s): Sebastien Bacher
  • Date: 2005-09-06 16:37:02 UTC
  • mfrom: (1.2.1 upstream) (2.1.1 sarge)
  • Revision ID: james.westby@ubuntu.com-20050906163702-hrqi0ctymth53bnn
Tags: 1:2.12.4-0ubuntu1
* New upstream version.
* debian/patches/100-compile-name-server.patch:
  - updated.

Show diffs side-by-side

added added

removed removed

Lines of Context:
7
7
#include "iop-profiles.h"
8
8
#include "orb-core-private.h"
9
9
#include "../poa/orbit-poa-export.h"
 
10
#include "orbit-debug.h"
10
11
 
11
12
#undef DEBUG
12
13
 
16
17
 
17
18
static void IOP_profile_free (IOP_Profile_info *p);
18
19
 
19
 
#ifdef LINC_SSL_SUPPORT
 
20
#ifdef LINK_SSL_SUPPORT
20
21
static IOP_Component_info *
21
22
IOP_component_find (GSList *list, IOP_ComponentId type, GSList **pos)
22
23
{
29
30
 
30
31
  return NULL;
31
32
}
32
 
#endif /* LINC_SSL_SUPPORT */
 
33
#endif /* LINK_SSL_SUPPORT */
33
34
 
34
35
static gchar *
35
36
IOP_ObjectKey_dump (ORBit_ObjectKey *objkey)
38
39
        GString *str = g_string_sized_new (objkey->_length * 2 + 4);
39
40
 
40
41
        for (i = 0; i < objkey->_length; i++)
41
 
                g_string_append_printf (str, "%2x", objkey->_buffer [i]);
 
42
                g_string_append_printf (str, "%02x", objkey->_buffer [i]);
42
43
 
43
44
        return g_string_free (str, FALSE);
44
45
}
61
62
                key = IOP_ObjectKey_dump (obj->object_key);
62
63
                g_string_printf (str, "P-IIOP %s:0x%x '%s'",
63
64
                                 iiop->host, iiop->port, key);
64
 
                break;
 
65
                g_free (key);
 
66
                break;
65
67
        }
66
68
        
67
69
        case IOP_TAG_GENERIC_IOP: {
82
84
                g_string_printf (str, "P-OS %s:0x%x '%s'",
83
85
                                 os->unix_sock_path, os->ipv6_port,
84
86
                                 key);
 
87
 
 
88
                g_free (key);
85
89
                break;
86
90
        }
87
91
        case IOP_TAG_MULTIPLE_COMPONENTS:
90
94
                break;
91
95
        }
92
96
 
93
 
        g_free (key);
94
 
        
95
97
        return g_string_free (str, FALSE);
96
98
}
97
99
 
229
231
      *host = iiop->host;
230
232
      *service = tmpbuf;
231
233
      g_snprintf(tmpbuf, 8, "%d", iiop->port);
232
 
#ifdef LINC_SSL_SUPPORT
 
234
#ifdef LINK_SSL_SUPPORT
233
235
      {
234
236
        IOP_TAG_SSL_SEC_TRANS_info *ssli;
235
237
        ssli = (IOP_TAG_SSL_SEC_TRANS_info *)
249
251
      *proto = giop->proto;
250
252
      *host = giop->host;
251
253
      *service = giop->service;
252
 
#ifdef LINC_SSL_SUPPORT
 
254
#ifdef LINK_SSL_SUPPORT
253
255
      {
254
256
        IOP_TAG_GENERIC_SSL_SEC_TRANS_info *ssli;
255
257
        ssli = (IOP_TAG_GENERIC_SSL_SEC_TRANS_info *)
312
314
        return TRUE;
313
315
}
314
316
 
 
317
static guint
 
318
IOP_mem_hash (gconstpointer key, gulong len)
 
319
{
 
320
        guint h = 0;
 
321
        const char *p, *pend;
 
322
 
 
323
        for (p = key, pend = p + len; p < pend; p++)
 
324
                h = (h << 5) - h + *p;
 
325
 
 
326
        return h;
 
327
}
 
328
 
 
329
guint
 
330
IOP_ObjectKey_hash (ORBit_ObjectKey *k)
 
331
{
 
332
        return IOP_mem_hash (k->_buffer, k->_length);
 
333
}
 
334
 
315
335
gboolean
316
336
IOP_profile_equal (CORBA_Object obj1, CORBA_Object obj2,
317
337
                   gpointer d1, gpointer d2)
340
360
 
341
361
                if (strcmp (iiop1->host, iiop2->host))
342
362
                        return FALSE;
 
363
 
 
364
                /* FIXME, also compare ssl ports */ 
 
365
 
343
366
                break;
344
367
        }
345
368
 
390
413
        return TRUE;
391
414
}
392
415
 
393
 
static guint
394
 
IOP_mem_hash (gconstpointer key, gulong len)
395
 
{
396
 
  const char *p, *pend;
397
 
  guint h = 0;
398
 
 
399
 
  for(p = key, pend = p + len; p < pend; p++)
400
 
    h = (h << 5) - h + *p;
401
 
 
402
 
  return h;
403
 
}
404
 
 
 
416
/*
 
417
 * This performs really badly, and is pretty useless.
 
418
 */
405
419
void
406
 
IOP_profile_hash(gpointer item, gpointer data)
 
420
IOP_profile_hash (gpointer item, gpointer data)
407
421
{
408
 
  IOP_Profile_info *p = item;
409
 
  guint *h = data;
410
 
  IOP_TAG_INTERNET_IOP_info *iiop;
411
 
  IOP_TAG_GENERIC_IOP_info *giop;
412
 
  IOP_TAG_ORBIT_SPECIFIC_info *osi;
413
 
  IOP_TAG_MULTIPLE_COMPONENTS_info *mci;
414
 
  IOP_UnknownProfile_info *upi;
 
422
        IOP_Profile_info *p = item;
 
423
        guint *h = data;
 
424
        IOP_TAG_INTERNET_IOP_info *iiop;
 
425
        IOP_TAG_GENERIC_IOP_info *giop;
 
426
        IOP_TAG_ORBIT_SPECIFIC_info *osi;
 
427
        IOP_TAG_MULTIPLE_COMPONENTS_info *mci;
 
428
        IOP_UnknownProfile_info *upi;
415
429
 
416
 
  *h ^= p->profile_type;
417
 
  switch(p->profile_type)
418
 
    {
419
 
    case IOP_TAG_ORBIT_SPECIFIC:
420
 
      osi = item;
421
 
      *h ^= g_str_hash(osi->unix_sock_path);
422
 
      break;
423
 
    case IOP_TAG_INTERNET_IOP:
424
 
      iiop = item;
425
 
      *h ^= g_str_hash(iiop->host);
426
 
      *h ^= iiop->port;
427
 
      break;
428
 
    case IOP_TAG_GENERIC_IOP:
429
 
      giop = item;
430
 
      *h ^= g_str_hash(giop->proto);
431
 
      *h ^= g_str_hash(giop->host);
432
 
      *h ^= g_str_hash(giop->service);
433
 
      break;
434
 
    case IOP_TAG_MULTIPLE_COMPONENTS:
435
 
      mci = item;
436
 
      *h ^= g_slist_length(mci->components);
437
 
      break;
438
 
    default:
439
 
      upi = item;
440
 
      *h ^= IOP_mem_hash(upi->data._buffer, upi->data._length);
441
 
      break;
442
 
    }
 
430
        *h ^= p->profile_type;
 
431
        switch (p->profile_type) {
 
432
        case IOP_TAG_ORBIT_SPECIFIC:
 
433
                osi = item;
 
434
                *h ^= g_str_hash(osi->unix_sock_path);
 
435
                break;
 
436
        case IOP_TAG_INTERNET_IOP:
 
437
                iiop = item;
 
438
                *h ^= g_str_hash(iiop->host);
 
439
                *h ^= iiop->port;
 
440
                break;
 
441
        case IOP_TAG_GENERIC_IOP:
 
442
                giop = item;
 
443
                *h ^= g_str_hash(giop->proto);
 
444
                *h ^= g_str_hash(giop->host);
 
445
                *h ^= g_str_hash(giop->service);
 
446
                break;
 
447
        case IOP_TAG_MULTIPLE_COMPONENTS:
 
448
                mci = item;
 
449
                *h ^= g_slist_length(mci->components);
 
450
                break;
 
451
        default:
 
452
                upi = item;
 
453
                *h ^= IOP_mem_hash(upi->data._buffer, upi->data._length);
 
454
                break;
 
455
        }
443
456
}
444
457
 
445
458
void
450
463
                return;
451
464
 
452
465
        if (orb && *profiles == orb->profiles)
453
 
                return;
454
 
 
455
 
        g_slist_foreach (*profiles, (GFunc)IOP_profile_free, NULL);
456
 
        g_slist_free (*profiles);
457
 
        *profiles = NULL;
 
466
                *profiles = NULL;
 
467
        else {
 
468
                g_slist_foreach (*profiles,
 
469
                                 (GFunc)IOP_profile_free, NULL);
 
470
                g_slist_free (*profiles);
 
471
                *profiles = NULL;
 
472
        }
458
473
}
459
474
 
460
475
GSList *
468
483
        IOP_TAG_INTERNET_IOP_info        *iiop = NULL;
469
484
 
470
485
        for (l = orb->servers ; l != NULL ; l = l->next) {
471
 
                LINCServer *serv = l->data;
 
486
                LinkServer *serv = l->data;
472
487
                gboolean   ipv4, ipv6, uds, ssl;
473
488
 
474
489
                ipv4 = !strcmp (serv->proto->name, "IPv4");
475
490
                ipv6 = !strcmp (serv->proto->name, "IPv6");
476
491
                uds  = !strcmp (serv->proto->name, "UNIX");
477
492
 
478
 
                ssl  = (serv->create_options & LINC_CONNECTION_SSL);
 
493
                ssl  = (serv->create_options & LINK_CONNECTION_SSL);
479
494
 
480
 
                if (!osi && (uds || (ipv6 && !ssl))) {
 
495
                if (!osi && uds) {
481
496
                        osi = g_new0 (IOP_TAG_ORBIT_SPECIFIC_info, 1);
482
497
                        osi->parent.profile_type = IOP_TAG_ORBIT_SPECIFIC;
483
498
                }
485
500
                if (uds && !osi->unix_sock_path)
486
501
                        osi->unix_sock_path = g_strdup (serv->local_serv_info);
487
502
 
488
 
                if (ipv6 && !ssl)
489
 
                        osi->ipv6_port = atoi (serv->local_serv_info);
490
 
 
491
503
                if (ipv4) {
492
504
                        if (!iiop) {
493
505
                                iiop = g_new0 (IOP_TAG_INTERNET_IOP_info, 1);
519
531
 
520
532
                                giopt = l2->data;
521
533
                                if (giopt->parent.profile_type == IOP_TAG_GENERIC_IOP &&
522
 
                                    strcmp (giopt->proto, serv->proto->name)) {
 
534
                                   !strcmp (giopt->proto, serv->proto->name)) {
523
535
                                        giop = giopt;
524
536
                                        break;
525
537
                                }
569
581
 
570
582
                csets = g_new0 (IOP_TAG_CODE_SETS_info, 1);
571
583
                csets->parent.component_type = IOP_TAG_CODE_SETS;
 
584
 
 
585
                csets->data.ForCharData.native_code_set  = IOP_PROFILES_CODE_SET_UTF8;
 
586
                csets->data.ForWcharData.native_code_set = IOP_PROFILES_CODE_SET_UTF16;
 
587
 
572
588
                mci->components = g_slist_append (mci->components, csets);
573
589
        }
574
590
 
585
601
void
586
602
IOP_generate_profiles (CORBA_Object obj)
587
603
{
588
 
        CORBA_ORB      orb;
 
604
        CORBA_ORB orb;
589
605
        ORBit_OAObject adaptor_obj;
590
606
 
591
607
        g_assert (obj && (obj->profile_list == NULL) && obj->orb);
605
621
                obj->object_key = ORBit_OAObject_object_to_objkey (adaptor_obj);
606
622
 
607
623
        obj->profile_list = orb->profiles;
608
 
 
609
 
        ORBit_register_objref (obj);
610
624
}
611
625
 
612
626
static void
628
642
                }
629
643
        case IOP_TAG_SSL_SEC_TRANS:
630
644
                break;
631
 
        case IOP_TAG_CODE_SETS:
632
 
                break;
 
645
        case IOP_TAG_CODE_SETS: {
 
646
                IOP_TAG_CODE_SETS_info  *csets = (IOP_TAG_CODE_SETS_info*)c;
 
647
                CORBA_sequence_CONV_FRAME_CodeSetId *conv_codesets;
 
648
                
 
649
                conv_codesets 
 
650
                        = &(csets->data.ForCharData.conversion_code_sets);
 
651
                if (conv_codesets->_buffer) 
 
652
                        ORBit_free_T (conv_codesets->_buffer);
 
653
 
 
654
                conv_codesets 
 
655
                        = &(csets->data.ForWcharData.conversion_code_sets);
 
656
                if (conv_codesets->_buffer) 
 
657
                        ORBit_free_T (conv_codesets->_buffer);
 
658
                break;
 
659
                }
 
660
 
633
661
        default:
634
662
                g_free (((IOP_UnknownProfile_info*)c)->data._buffer);
635
663
                break;
771
799
        /* native_code_set */
772
800
        giop_send_buffer_append_aligned (buf, &native_code_set, 4);
773
801
 
774
 
        if (opt_conversion_code_sets)
775
 
                g_error ("Unimplemented as yet");
776
 
        else {
 
802
        if (opt_conversion_code_sets && opt_conversion_code_sets->_buffer) {
 
803
                CORBA_unsigned_long length = opt_conversion_code_sets->_length;
 
804
                giop_send_buffer_append_aligned (buf, &length, 4);
 
805
                giop_send_buffer_append (buf,
 
806
                                         opt_conversion_code_sets->_buffer,
 
807
                                         length * sizeof(CORBA_unsigned_long));
 
808
        } else {
777
809
                CORBA_unsigned_long length = 0;
778
810
                giop_send_buffer_append_aligned (buf, &length, 4);
779
811
        }       
786
818
{
787
819
        /* To get these magic numbers see the 'OSF Character
788
820
           and Codeset Registry'; ftp.opengroup.org/pub/code_set_registry */
789
 
        CORBA_unsigned_long utf8_key  = 0x05010001;
790
 
        CORBA_unsigned_long utf16_key = 0x00010109;
 
821
        /* CORBA_unsigned_long utf8_key  = 0x05010001; */
 
822
        /* CORBA_unsigned_long utf16_key = 0x00010109; */
 
823
        IOP_TAG_CODE_SETS_info *csets = (IOP_TAG_CODE_SETS_info*) ci;
791
824
 
792
825
        /* Marshal a CodeSetComponentInfo structure */
793
 
        CodeSetComponent_marshal (buf, utf8_key, NULL);
794
 
        CodeSetComponent_marshal (buf, utf16_key, NULL);
 
826
        CodeSetComponent_marshal (buf,
 
827
                                  csets->data.ForCharData.native_code_set,
 
828
                                  &(csets->data.ForCharData.conversion_code_sets));
 
829
        CodeSetComponent_marshal (buf,
 
830
                                  csets->data.ForWcharData.native_code_set,
 
831
                                  &(csets->data.ForWcharData.conversion_code_sets));
795
832
}
796
833
 
797
834
static void
801
838
{
802
839
        IOP_UnknownComponent_info *uci = (IOP_UnknownComponent_info *) ci;
803
840
 
 
841
        giop_send_buffer_append (buf, &uci->data._length, 4);
804
842
        giop_send_buffer_append (buf, uci->data._buffer, uci->data._length);
805
843
}
806
844
 
1125
1163
 
1126
1164
static gboolean
1127
1165
CodeSetComponent_demarshal (GIOPRecvBuffer *buf,
1128
 
                            CORBA_unsigned_long *native_code_set,
1129
 
                            CORBA_sequence_CORBA_unsigned_long **opt_conversion_code_sets)
 
1166
                            CONV_FRAME_CodeSetComponent *component)
1130
1167
{
1131
1168
        CORBA_unsigned_long sequence_length;
1132
1169
 
1135
1172
        if (buf->cur + 8 > buf->end)
1136
1173
                return FALSE;
1137
1174
 
1138
 
        *native_code_set = *(CORBA_unsigned_long *)buf->cur;
 
1175
        component->native_code_set = *(CORBA_unsigned_long *)buf->cur;
1139
1176
        if (giop_msg_conversion_needed (buf))
1140
 
                *native_code_set = GUINT32_SWAP_LE_BE (*native_code_set);
 
1177
                component->native_code_set 
 
1178
                        = GUINT32_SWAP_LE_BE (component->native_code_set);
1141
1179
        buf->cur += 4;
1142
1180
 
1143
1181
        sequence_length = *(CORBA_unsigned_long *)buf->cur;
1145
1183
                sequence_length = GUINT32_SWAP_LE_BE (sequence_length);
1146
1184
        buf->cur += 4;
1147
1185
 
 
1186
       if (buf->cur + sequence_length * 4 > buf->end)
 
1187
               return FALSE;
 
1188
 
1148
1189
        if (sequence_length > 0) {
1149
 
                static int warned = 0;
1150
 
                if (!(warned++))
1151
 
                        g_warning ("Ignoring incoming code_sets component");
1152
 
 
1153
 
                if (buf->cur + sequence_length * 4 < buf->end)
1154
 
                        buf->cur += sequence_length * 4;
1155
 
                else
1156
 
                        return FALSE;
 
1190
                int i;
 
1191
                dprintf (OBJECTS, "Ignoring incoming code_sets component");
 
1192
                component->conversion_code_sets._maximum = sequence_length;
 
1193
                component->conversion_code_sets._length  = sequence_length;
 
1194
                component->conversion_code_sets._release = TRUE;
 
1195
                component->conversion_code_sets._buffer  =
 
1196
                        CORBA_sequence_CORBA_unsigned_long_allocbuf (sequence_length);
 
1197
                for (i=0; i<sequence_length; ++i) {
 
1198
                        component->conversion_code_sets._buffer [i] = 
 
1199
                                *(CORBA_unsigned_long *)buf->cur;
 
1200
                        if (giop_msg_conversion_needed (buf))
 
1201
                                component->conversion_code_sets._buffer [i] 
 
1202
                                        = GUINT32_SWAP_LE_BE (component->conversion_code_sets._buffer [i]);
 
1203
                        buf->cur += 4;
 
1204
                }
1157
1205
        }
1158
1206
        
1159
1207
        return TRUE;
1164
1212
                             GIOPRecvBuffer  *buf)
1165
1213
{
1166
1214
        IOP_TAG_CODE_SETS_info *retval;
1167
 
        CORBA_unsigned_long     dummy;
1168
1215
        GIOPRecvBuffer         *encaps;
1169
1216
 
1170
 
        encaps = giop_recv_buffer_use_encaps_buf (buf);
1171
 
        if (!encaps)
 
1217
        if (!(encaps = giop_recv_buffer_use_encaps_buf (buf)))
1172
1218
                return NULL;
1173
1219
  
1174
 
        retval = g_new (IOP_TAG_CODE_SETS_info, 1);
 
1220
        retval = g_new0 (IOP_TAG_CODE_SETS_info, 1);
1175
1221
        retval->parent.component_type = id;
1176
1222
 
1177
1223
        /* We don't care about the data much */
1178
 
        if (!CodeSetComponent_demarshal (encaps, &dummy, NULL) ||
1179
 
            !CodeSetComponent_demarshal (encaps, &dummy, NULL)) {
 
1224
        if (!CodeSetComponent_demarshal (encaps, &(retval->data.ForCharData)) ||
 
1225
            !CodeSetComponent_demarshal (encaps, &(retval->data.ForWcharData))) {
1180
1226
                giop_recv_buffer_unuse (encaps);
 
1227
                if (retval->data.ForCharData.conversion_code_sets._buffer) 
 
1228
                        ORBit_free_T (retval->data.ForCharData.conversion_code_sets._buffer);
 
1229
                if (retval->data.ForWcharData.conversion_code_sets._buffer) 
 
1230
                        ORBit_free_T (retval->data.ForWcharData.conversion_code_sets._buffer);
1181
1231
                g_free (retval);
1182
1232
                return NULL;
1183
1233
        }
1644
1694
                len = GUINT32_SWAP_LE_BE (len);
1645
1695
        buf->cur += 4;
1646
1696
 
1647
 
        if (len < 0 || (buf->cur + len) > buf->end)
 
1697
        if ((buf->cur + len) > buf->end)
1648
1698
                return TRUE;
1649
1699
 
1650
1700
        type_id = buf->cur;