summaryrefslogtreecommitdiff
path: root/libsn/sn-xmessages.c
blob: ef18027d57546e5f0754799da6eaae4a62699a48 (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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
/* 
 * Copyright (C) 2002 Red Hat, Inc.
 * Copyright (C) 2009 Julien Danjou <julien@danjou.info>
 * 
 * Permission is hereby granted, free of charge, to any person
 * obtaining a copy of this software and associated documentation
 * files (the "Software"), to deal in the Software without
 * restriction, including without limitation the rights to use, copy,
 * modify, merge, publish, distribute, sublicense, and/or sell copies
 * of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 * 
 * The above copyright notice and this permission notice shall be
 * included in all copies or substantial portions of the Software.
 * 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */

#include <config.h>

#include <xcb/xcb_event.h>

#include "sn-xmessages.h"
#include "sn-list.h"
#include "sn-internals.h"

typedef struct
{
  void          *xid;
  Window         root;
  Atom           type_atom;
  Atom           type_atom_begin;
  char          *message_type;
  SnXmessageFunc func;
  void          *func_data;
  SnFreeFunc     free_data_func;
} SnXmessageHandler;

typedef struct
{
  Atom type_atom_begin;
  Window xwindow;
  char *message;
  int allocated;
} SnXmessage;

void
sn_internal_add_xmessage_func (SnDisplay      *display,
                               int             screen,
                               const char     *message_type,
                               const char     *message_type_begin,
                               SnXmessageFunc  func,
                               void           *func_data,
                               SnFreeFunc      free_data_func)
{
  SnXmessageHandler *handler;
  SnList *xmessage_funcs;
  
  sn_internal_display_get_xmessage_data (display, &xmessage_funcs,
                                         NULL);
  
  handler = sn_new0 (SnXmessageHandler, 1);

  handler->xid = sn_internal_display_get_id (display);
  handler->root = sn_internal_display_get_root_window (display, screen);
  handler->type_atom = sn_internal_atom_get (display, message_type);
  handler->type_atom_begin = sn_internal_atom_get (display, message_type_begin);
  handler->message_type = sn_internal_strdup (message_type);
  handler->func = func;
  handler->func_data = func_data;
  handler->free_data_func = free_data_func;
  
  sn_list_prepend (xmessage_funcs, handler);
}

typedef struct
{
  const char *message_type;
  SnXmessageFunc func;
  void *func_data;
  Window root;
  SnXmessageHandler *handler;
} FindHandlerData;

static sn_bool_t
find_handler_foreach (void *value,
                      void *data)
{
  FindHandlerData *fhd = data;
  SnXmessageHandler *handler = value;

  if (handler->func == fhd->func &&
      handler->func_data == fhd->func_data &&
      handler->root == fhd->root &&
      strcmp (fhd->message_type, handler->message_type) == 0)
    {
      fhd->handler = handler;
      return FALSE;
    }

  return TRUE;
}

void
sn_internal_remove_xmessage_func (SnDisplay      *display,
                                  int             screen,
                                  const char     *message_type,
                                  SnXmessageFunc  func,
                                  void           *func_data)
{
  FindHandlerData fhd;
  SnList *xmessage_funcs;

  sn_internal_display_get_xmessage_data (display, &xmessage_funcs,
                                         NULL);

  fhd.message_type = message_type;
  fhd.func = func;
  fhd.func_data = func_data;
  fhd.handler = NULL;
  fhd.root = sn_internal_display_get_root_window (display, screen);
  
  if (xmessage_funcs != NULL)
    sn_list_foreach (xmessage_funcs, find_handler_foreach, &fhd);

  if (fhd.handler != NULL)
    {
      sn_list_remove (xmessage_funcs, fhd.handler);

      sn_free (fhd.handler->message_type);
      
      if (fhd.handler->free_data_func)
        (* fhd.handler->free_data_func) (fhd.handler->func_data);
      
      sn_free (fhd.handler);
    }
}

void
sn_internal_broadcast_xmessage   (SnDisplay      *display,
                                  int             screen,
                                  const char     *message_type,
                                  const char     *message_type_begin,
                                  const char     *message)
{
  if (!sn_internal_utf8_validate (message, -1))
    {
      fprintf (stderr,
               "Attempted to send non-UTF-8 X message: %s\n",
               message);
      return;
    }

  switch (sn_internal_display_get_type (display))
  {
   case SN_DISPLAY_TYPE_XLIB:
    {
      Atom type_atom;
      Atom type_atom_begin;
      Window xwindow;
      XSetWindowAttributes attrs;
      Display *xdisplay = sn_display_get_x_display (display);
  
      attrs.override_redirect = True;
      attrs.event_mask = PropertyChangeMask | StructureNotifyMask;

      xwindow =
        XCreateWindow (xdisplay,
                       RootWindow (xdisplay, 0),
                       -100, -100, 1, 1,
                       0,
                       CopyFromParent,
                       CopyFromParent,
                       CopyFromParent,
                       CWOverrideRedirect | CWEventMask,
                       &attrs);
      type_atom = sn_internal_atom_get (display, message_type);
      type_atom_begin = sn_internal_atom_get (display, message_type_begin);
    
      {
        XEvent xevent;
        const char *src;
        const char *src_end;
        char *dest;
        char *dest_end;

        xevent.xclient.type = ClientMessage;
        xevent.xclient.message_type = type_atom_begin;
        xevent.xclient.display = xdisplay;
        xevent.xclient.window = xwindow;
        xevent.xclient.format = 8;

        src = message;
        src_end = message + strlen (message) + 1; /* +1 to include nul byte */
        
        while (src != src_end)
          {
            dest = &xevent.xclient.data.b[0];
            dest_end = dest + 20;

            while (dest != dest_end &&
                   src != src_end)
              {
                *dest = *src;
                ++dest;
                ++src;
              }

            XSendEvent (xdisplay,
                        RootWindow (xdisplay, screen),
                        False,
                        PropertyChangeMask,
                        &xevent);

            xevent.xclient.message_type = type_atom;
          }
      }

      XDestroyWindow (xdisplay, xwindow);
      XFlush (xdisplay);
    }
    break;
   case SN_DISPLAY_TYPE_XCB:
    {
      xcb_atom_t type_atom;
      xcb_atom_t type_atom_begin;
      xcb_window_t xwindow;
      uint32_t attrs[] = { 1, XCB_EVENT_MASK_PROPERTY_CHANGE | XCB_EVENT_MASK_STRUCTURE_NOTIFY };
      xcb_connection_t *xconnection = sn_display_get_x_connection (display);
      xcb_screen_t *s = sn_internal_display_get_xcb_screen (display, screen);

      xwindow = xcb_generate_id(xconnection);
      xcb_create_window(xconnection, s->root_depth, xwindow, s->root,
                        -100, -100, 1, 1, 0, XCB_COPY_FROM_PARENT, s->root_visual,
                        XCB_CW_OVERRIDE_REDIRECT | XCB_CW_EVENT_MASK,
                        attrs);

      type_atom = sn_internal_atom_get (display, message_type);
      type_atom_begin = sn_internal_atom_get (display, message_type_begin);

      {
        xcb_client_message_event_t xevent;
        const char *src;
        const char *src_end;
        unsigned char *dest;
        unsigned char *dest_end;

        xevent.response_type = XCB_CLIENT_MESSAGE;
        xevent.type = type_atom_begin;
        xevent.window = xwindow;
        xevent.format = 8;

        src = message;
        src_end = message + strlen (message) + 1; /* +1 to include nul byte */

        while (src != src_end)
          {
            dest = &xevent.data.data8[0];
            dest_end = dest + 20;

            while (dest != dest_end &&
                   src != src_end)
              {
                *dest = *src;
                ++dest;
                ++src;
              }

            xcb_send_event (xconnection, 0, s->root, XCB_EVENT_MASK_PROPERTY_CHANGE,
                            (char *) &xevent);

            xevent.type = type_atom;
          }
      }

      xcb_destroy_window (xconnection, xwindow);
      xcb_flush(xconnection);
    }
    break;
  }
}

typedef struct
{
  void *xid;
  Atom atom;
  Window xwindow;
  sn_bool_t found_handler;
} HandlerForAtomData;

static sn_bool_t
handler_for_atom_foreach (void *value,
                          void *data)
{
  SnXmessageHandler *handler = value;
  HandlerForAtomData *hfad = data;
  
  if (handler->xid == hfad->xid &&
      (handler->type_atom == hfad->atom ||
       handler->type_atom_begin == hfad->atom))
    {
      hfad->found_handler = TRUE;
      return FALSE;
    }
  else
    return TRUE;
}

static sn_bool_t
some_handler_handles_event (SnDisplay *display,
                            Atom atom,
                            Window win)
{
  HandlerForAtomData hfad;
  SnList *xmessage_funcs;

  sn_internal_display_get_xmessage_data (display, &xmessage_funcs,
                                         NULL);
  
  hfad.atom = atom;
  hfad.xid = sn_internal_display_get_id (display);
  hfad.xwindow = win;
  hfad.found_handler = FALSE;

  if (xmessage_funcs)
    sn_list_foreach (xmessage_funcs,
                     handler_for_atom_foreach,
                     &hfad);

  return hfad.found_handler;
}

typedef struct
{
  Window window;
  SnXmessage *message;
} FindMessageData;

static sn_bool_t
find_message_foreach (void *value,
                      void *data)
{
  SnXmessage *message = value;
  FindMessageData *fmd = data;
  
  if (fmd->window == message->xwindow)
    {
      fmd->message = message;
      return FALSE;
    }

  return TRUE;
}

static SnXmessage*
message_new(Atom type_atom_begin, Window win)
{
  SnXmessage *message = sn_new0 (SnXmessage, 1);
  message->type_atom_begin = type_atom_begin;
  message->xwindow = win;
  message->message = NULL;
  message->allocated = 0;
  return message;
}

static sn_bool_t
message_set_message(SnXmessage *message, const char *src)
{
  const char *src_end;
  char *dest;
  sn_bool_t completed = FALSE;

  src_end = src + 20;

  message->message = sn_realloc (message->message,
                                 message->allocated + (src_end - src));
  dest = message->message + message->allocated;
  message->allocated += (src_end - src);

  /* Copy bytes, be sure we get nul byte also */
  while (src != src_end)
    {
      *dest = *src;

      if (*src == '\0')
        {
          completed = TRUE;
          break;
        }

      ++dest;
      ++src;
    }

  return completed;
}

static SnXmessage*
get_or_add_message(SnList *pending_messages,
                   Window win,
                   Atom type_atom_begin)
{
  FindMessageData fmd;
  SnXmessage *message;

  fmd.window = win;
  fmd.message = NULL;

  
  if (pending_messages)
    sn_list_foreach (pending_messages, find_message_foreach, &fmd);

  message = fmd.message;

  if (message == NULL)
    {
      message = message_new(type_atom_begin, win);

      sn_list_prepend (pending_messages, message);
    }
  
  return message;
}

static SnXmessage*
add_event_to_messages (SnDisplay *display,
                       Window win,
                       Atom message_type,
                       const char *data)
{
  SnXmessage *message;
  SnList *pending_messages;

  sn_internal_display_get_xmessage_data (display, NULL,
                                         &pending_messages);

  message = get_or_add_message(pending_messages,
                               win, message_type);

  /* We don't want screwy situations to end up causing us to allocate
   * infinite memory. Cap the length of a message.
   */
#define MAX_MESSAGE_LENGTH 4096

  if (message->allocated > MAX_MESSAGE_LENGTH)
    {
      /* This message is some kind of crap - just dump it. */
      sn_free (message->message);
      sn_list_remove (pending_messages, message);
      sn_free (message);
      return NULL;
    }
  
  if (message_set_message (message, data))
    {
      /* Pull message out of the pending queue and return it */
      sn_list_remove (pending_messages, message);
      return message;
    }
  else
    return NULL;
}

typedef struct
{
  SnDisplay *display;
  SnXmessage *message;
} MessageDispatchData;

static sn_bool_t
dispatch_message_foreach (void *value,
                          void *data)
{
  SnXmessageHandler *handler = value;
  MessageDispatchData *mdd = data;  
  
  if (handler->type_atom_begin == mdd->message->type_atom_begin &&
      sn_internal_display_get_id (mdd->display) == handler->xid)
    (* handler->func) (mdd->display,
                       handler->message_type,
                       mdd->message->message,
                       handler->func_data);
  
  return TRUE;
}

static void
xmessage_process_message (SnDisplay *display, SnXmessage *message)
{
  if (message)
    {
      /* We need to dispatch and free this message; ignore
       * messages containing invalid UTF-8
       */

      if (sn_internal_utf8_validate (message->message, -1))
        {
          MessageDispatchData mdd;
          SnList *xmessage_funcs;
          
          sn_internal_display_get_xmessage_data (display, &xmessage_funcs,
                                                 NULL);
          
          mdd.display = display;
          mdd.message = message;
          
          /* We could stand to be more reentrant here; it will
           * barf if you add/remove a handler from inside the
           * dispatch
           */
          if (xmessage_funcs != NULL)
            sn_list_foreach (xmessage_funcs,
                             dispatch_message_foreach,
                             &mdd);
        }
      else
        {
          /* FIXME don't use fprintf, use something pluggable */
          fprintf (stderr, "Bad UTF-8 in startup notification message\n");
        }

      sn_free (message->message);
      sn_free (message);
    }
}

sn_bool_t
sn_internal_xmessage_process_event (SnDisplay *display,
                                    XEvent    *xevent)
{
  sn_bool_t retval = FALSE;
  SnXmessage *message = NULL;

  switch (xevent->xany.type)
    {
    case ClientMessage:
      if (some_handler_handles_event (display,
                                      xevent->xclient.message_type,
                                      xevent->xclient.window))
        {
          retval = TRUE;

          message = add_event_to_messages (display,
                                           xevent->xclient.window,
                                           xevent->xclient.message_type,
                                           xevent->xclient.data.b);
        }
      break;
    }

  xmessage_process_message (display, message);

  return retval;
}

sn_bool_t
sn_xcb_internal_xmessage_process_event (SnDisplay           *display,
                                        xcb_generic_event_t *xevent)
{
  sn_bool_t retval = FALSE;
  SnXmessage *message = NULL;
  xcb_client_message_event_t *ev = (xcb_client_message_event_t *) xevent;

  switch (XCB_EVENT_RESPONSE_TYPE(xevent))
    {
    case XCB_CLIENT_MESSAGE:
      if (some_handler_handles_event (display,
                                      ev->type,
                                      ev->window))
        {
          retval = TRUE;

          message = add_event_to_messages (display,
                                           ev->window,
                                           ev->type,
                                           (const char *) ev->data.data8);
        }
      break;
    }

  xmessage_process_message (display, message);

  return retval;
}

static void
sn_internal_append_to_string_escaped (char      **append_to,
                                      int        *current_len,
                                      const char *append)
{
  char *escaped;
  int len;
  char buf[2];
  const char *p;
  
  buf[1] = '\0';
  len = 0;
  escaped = NULL;

  /* We are the most inefficient algorithm ever! woot! */
  /* really need GString here */
  p = append;
  while (*p)
    {
      if (*p == '\\' || *p == '"' || *p == ' ')
        {
          buf[0] = '\\';
          sn_internal_append_to_string (&escaped, &len, buf);
        }
      buf[0] = *p;
      sn_internal_append_to_string (&escaped, &len, buf);
      
      ++p;
    }

  if (escaped != NULL)
    {
      sn_internal_append_to_string (append_to, current_len, escaped);
      
      sn_free (escaped);
    }
}

char*
sn_internal_serialize_message (const char   *prefix,
                               const char  **property_names,
                               const char  **property_values)
{
  int len;
  char *retval;
  int i;
  
  /* GLib would simplify this a lot... */  
  len = 0;
  retval = NULL;

  sn_internal_append_to_string (&retval, &len, prefix);
  sn_internal_append_to_string (&retval, &len, ":");

  i = 0;
  while (property_names[i])
    {
      sn_internal_append_to_string (&retval, &len, " ");
      sn_internal_append_to_string (&retval, &len, property_names[i]);
      sn_internal_append_to_string (&retval, &len, "=");
      sn_internal_append_to_string_escaped (&retval, &len, property_values[i]);
      
      ++i;
    }

  return retval;
}

/* Takes ownership of @append
 */
static void
append_string_to_list (char ***list,
                       char   *append)
{
  if (*list == NULL)
    {
      *list = sn_new0 (char*, 2);
      (*list)[0] = append;
    }
  else
    {
      int i;

      i = 0;
      while ((*list)[i] != NULL)
        ++i;

      *list = sn_renew (char*, *list, i + 2);
      (*list)[i] = append;
      (*list)[i+1] = NULL;
    }
}

static char*
parse_prefix_up_to (const char *str,
                    int         up_to,
                    const char **end)
{
  char *prefix;
  const char *p;
  int len;
  
  prefix = NULL;
  *end = NULL;
  
  p = str;
  while (*p && *p != up_to)
    ++p;

  if (*p == '\0')
    return NULL;

  len = p - str;
  prefix = sn_internal_strndup (str, len);

  *end = str + len;

  return prefix;
}                    


/* Single quotes preserve the literal string exactly. escape
 * sequences are not allowed; not even \' - if you want a '
 * in the quoted text, you have to do something like 'foo'\''bar'
 *
 * Double quotes allow $ ` " \ and newline to be escaped with backslash.
 * Otherwise double quotes preserve things literally.
 *
 * (This is overkill for X messages, copied from GLib shell code,
 *  copyright Red Hat Inc. also)
 */

static sn_bool_t
unescape_string_inplace (char  *str,
                         char **end)
{
  char* dest;
  char* s;
  sn_bool_t escaped;
  sn_bool_t quoted;  
  
  dest = s = str;
  escaped = FALSE;
  quoted = FALSE;
  
  while (*s)
    {      
      if (escaped)
        {
          escaped = FALSE;
          
          *dest = *s;
          ++dest;
        }
      else if (quoted)
        {
          if (*s == '"')
            quoted = FALSE;
          else if (*s == '\\')
            escaped = TRUE;
          else
            {
              *dest = *s;
              ++dest;
            }
        }
      else
        {
          if (*s == ' ')
            break;
          else if (*s == '\\')
            escaped = TRUE;
          else if (*s == '"')
            quoted = TRUE;
          else
            {
              *dest = *s;
              ++dest;
            }
        }

      ++s;
    }

  *dest = '\0';
  *end = s;
  
  return TRUE;
}

static sn_bool_t
parse_property (const char  *str,
                char       **name_p,
                char       **val_p,
                const char **end_p)
{
  char *val;
  char *name;
  char *copy;  
  char *p;
  
  *end_p = NULL;

  copy = sn_internal_strdup (str);
  p = copy;
  
  while (*p == ' ')
    ++p;

  name = parse_prefix_up_to (p, '=', (const char**) &p);
  if (name == NULL)
    {
      sn_free (copy);
      return FALSE;
    }
  ++p; /* skip '=' */

  while (*p == ' ')
    ++p;

  {
    char *end;
    
    end = NULL;
    if (!unescape_string_inplace (p, &end))
      {
        sn_free (copy);
        sn_free (name);
        return FALSE;
      }

    val = sn_internal_strndup (p, end - p);
    
    p = end;
  }

  while (*p == ' ')
    ++p;
  
  *end_p = str + (p - copy);
  
  sn_free (copy);
  
  *name_p = name;
  *val_p = val;

  return TRUE;
}

sn_bool_t
sn_internal_unserialize_message (const char *message,
                                 char      **prefix_p,
                                 char     ***property_names,
                                 char     ***property_values)
{
  /* GLib would simplify this a lot... */
  char *prefix;
  char **names;
  char **values;
  const char *p;
  char *name;
  char *value;
  
  *prefix_p = NULL;
  *property_names = NULL;
  *property_values = NULL;
  
  prefix = NULL;
  names = NULL;
  values = NULL;

  prefix = parse_prefix_up_to (message, ':', &p);
  if (prefix == NULL)
    return FALSE;

  ++p; /* skip ':' */

  name = NULL;
  value = NULL;
  while (parse_property (p, &name, &value, &p))
    {
      append_string_to_list (&names, name);
      append_string_to_list (&values, value);
    }
  
  *prefix_p = prefix;
  *property_names = names;
  *property_values = values;

  return TRUE;
}