diff options
| author | Paul Eggert | 2012-05-25 12:24:54 -0700 |
|---|---|---|
| committer | Paul Eggert | 2012-05-25 12:24:54 -0700 |
| commit | 243e053005d21aa66c2fc0d5be299d677de02fa5 (patch) | |
| tree | 6786f1135454bfd87bff9d143bf9c0a761e86ce4 /src/dbusbind.c | |
| parent | 42b2a986d9d4b7040fb20c90ec0efeffb78e761a (diff) | |
| download | emacs-243e053005d21aa66c2fc0d5be299d677de02fa5.tar.gz emacs-243e053005d21aa66c2fc0d5be299d677de02fa5.zip | |
Merge recent dbus changes better.
Diffstat (limited to 'src/dbusbind.c')
| -rw-r--r-- | src/dbusbind.c | 75 |
1 files changed, 33 insertions, 42 deletions
diff --git a/src/dbusbind.c b/src/dbusbind.c index 2ed7369c9dc..e506380e607 100644 --- a/src/dbusbind.c +++ b/src/dbusbind.c | |||
| @@ -254,22 +254,6 @@ xd_symbol_to_dbus_type (Lisp_Object object) | |||
| 254 | #define XD_OBJECT_TO_STRING(object) \ | 254 | #define XD_OBJECT_TO_STRING(object) \ |
| 255 | SDATA (format2 ("%s", object, Qnil)) | 255 | SDATA (format2 ("%s", object, Qnil)) |
| 256 | 256 | ||
| 257 | /* Check whether X is a valid dbus serial number. If valid, set | ||
| 258 | SERIAL to its value. Otherwise, signal an error. */ | ||
| 259 | #define XD_CHECK_DBUS_SERIAL(x, serial) \ | ||
| 260 | do { \ | ||
| 261 | dbus_uint32_t DBUS_SERIAL_MAX = -1; \ | ||
| 262 | if (NATNUMP (x) && XINT (x) <= DBUS_SERIAL_MAX) \ | ||
| 263 | serial = XINT (x); \ | ||
| 264 | else if (MOST_POSITIVE_FIXNUM < DBUS_SERIAL_MAX \ | ||
| 265 | && FLOATP (x) \ | ||
| 266 | && 0 <= XFLOAT_DATA (x) \ | ||
| 267 | && XFLOAT_DATA (x) <= DBUS_SERIAL_MAX) \ | ||
| 268 | serial = XFLOAT_DATA (x); \ | ||
| 269 | else \ | ||
| 270 | XD_SIGNAL2 (build_string ("Invalid dbus serial"), x); \ | ||
| 271 | } while (0) | ||
| 272 | |||
| 273 | #define XD_DBUS_VALIDATE_BUS_ADDRESS(bus) \ | 257 | #define XD_DBUS_VALIDATE_BUS_ADDRESS(bus) \ |
| 274 | do { \ | 258 | do { \ |
| 275 | if (STRINGP (bus)) \ | 259 | if (STRINGP (bus)) \ |
| @@ -366,9 +350,9 @@ xd_signature_cat (char *signature, char const *x) | |||
| 366 | signature is embedded, or DBUS_TYPE_INVALID. It is needed for the | 350 | signature is embedded, or DBUS_TYPE_INVALID. It is needed for the |
| 367 | check that DBUS_TYPE_DICT_ENTRY occurs only as array element. */ | 351 | check that DBUS_TYPE_DICT_ENTRY occurs only as array element. */ |
| 368 | static void | 352 | static void |
| 369 | xd_signature (char *signature, unsigned int dtype, unsigned int parent_type, Lisp_Object object) | 353 | xd_signature (char *signature, int dtype, int parent_type, Lisp_Object object) |
| 370 | { | 354 | { |
| 371 | unsigned int subtype; | 355 | int subtype; |
| 372 | Lisp_Object elt; | 356 | Lisp_Object elt; |
| 373 | char const *subsig; | 357 | char const *subsig; |
| 374 | int subsiglen; | 358 | int subsiglen; |
| @@ -558,9 +542,12 @@ extract_signed (Lisp_Object x, intmax_t lo, intmax_t hi) | |||
| 558 | return n; | 542 | return n; |
| 559 | } | 543 | } |
| 560 | } | 544 | } |
| 561 | args_out_of_range_3 (x, | 545 | if (xd_in_read_queued_messages) |
| 562 | make_fixnum_or_float (lo), | 546 | Fthrow (Qdbus_error, Qnil); |
| 563 | make_fixnum_or_float (hi)); | 547 | else |
| 548 | args_out_of_range_3 (x, | ||
| 549 | make_fixnum_or_float (lo), | ||
| 550 | make_fixnum_or_float (hi)); | ||
| 564 | } | 551 | } |
| 565 | 552 | ||
| 566 | /* Convert X to an unsigned integer with bounds 0 and HI. */ | 553 | /* Convert X to an unsigned integer with bounds 0 and HI. */ |
| @@ -583,7 +570,10 @@ extract_unsigned (Lisp_Object x, uintmax_t hi) | |||
| 583 | return n; | 570 | return n; |
| 584 | } | 571 | } |
| 585 | } | 572 | } |
| 586 | args_out_of_range_2 (x, make_fixnum_or_float (hi)); | 573 | if (xd_in_read_queued_messages) |
| 574 | Fthrow (Qdbus_error, Qnil); | ||
| 575 | else | ||
| 576 | args_out_of_range_3 (x, make_number (0), make_fixnum_or_float (hi)); | ||
| 587 | } | 577 | } |
| 588 | 578 | ||
| 589 | /* Append C value, extracted from Lisp OBJECT, to iteration ITER. | 579 | /* Append C value, extracted from Lisp OBJECT, to iteration ITER. |
| @@ -592,7 +582,7 @@ extract_unsigned (Lisp_Object x, uintmax_t hi) | |||
| 592 | `dbus-send-signal', into corresponding C values appended as | 582 | `dbus-send-signal', into corresponding C values appended as |
| 593 | arguments to a D-Bus message. */ | 583 | arguments to a D-Bus message. */ |
| 594 | static void | 584 | static void |
| 595 | xd_append_arg (unsigned int dtype, Lisp_Object object, DBusMessageIter *iter) | 585 | xd_append_arg (int dtype, Lisp_Object object, DBusMessageIter *iter) |
| 596 | { | 586 | { |
| 597 | char signature[DBUS_MAXIMUM_SIGNATURE_LENGTH]; | 587 | char signature[DBUS_MAXIMUM_SIGNATURE_LENGTH]; |
| 598 | DBusMessageIter subiter; | 588 | DBusMessageIter subiter; |
| @@ -620,9 +610,10 @@ xd_append_arg (unsigned int dtype, Lisp_Object object, DBusMessageIter *iter) | |||
| 620 | } | 610 | } |
| 621 | 611 | ||
| 622 | case DBUS_TYPE_INT16: | 612 | case DBUS_TYPE_INT16: |
| 623 | CHECK_TYPE_RANGED_INTEGER (dbus_int16_t, object); | ||
| 624 | { | 613 | { |
| 625 | dbus_int16_t val = XINT (object); | 614 | dbus_int16_t val = extract_signed (object, |
| 615 | TYPE_MINIMUM (dbus_int16_t), | ||
| 616 | TYPE_MAXIMUM (dbus_int16_t)); | ||
| 626 | int pval = val; | 617 | int pval = val; |
| 627 | XD_DEBUG_MESSAGE ("%c %d", dtype, pval); | 618 | XD_DEBUG_MESSAGE ("%c %d", dtype, pval); |
| 628 | if (!dbus_message_iter_append_basic (iter, dtype, &val)) | 619 | if (!dbus_message_iter_append_basic (iter, dtype, &val)) |
| @@ -631,9 +622,9 @@ xd_append_arg (unsigned int dtype, Lisp_Object object, DBusMessageIter *iter) | |||
| 631 | } | 622 | } |
| 632 | 623 | ||
| 633 | case DBUS_TYPE_UINT16: | 624 | case DBUS_TYPE_UINT16: |
| 634 | CHECK_TYPE_RANGED_INTEGER (dbus_uint16_t, object); | ||
| 635 | { | 625 | { |
| 636 | dbus_uint16_t val = XFASTINT (object); | 626 | dbus_uint16_t val = extract_unsigned (object, |
| 627 | TYPE_MAXIMUM (dbus_uint16_t)); | ||
| 637 | unsigned int pval = val; | 628 | unsigned int pval = val; |
| 638 | XD_DEBUG_MESSAGE ("%c %u", dtype, pval); | 629 | XD_DEBUG_MESSAGE ("%c %u", dtype, pval); |
| 639 | if (!dbus_message_iter_append_basic (iter, dtype, &val)) | 630 | if (!dbus_message_iter_append_basic (iter, dtype, &val)) |
| @@ -668,7 +659,6 @@ xd_append_arg (unsigned int dtype, Lisp_Object object, DBusMessageIter *iter) | |||
| 668 | } | 659 | } |
| 669 | 660 | ||
| 670 | case DBUS_TYPE_INT64: | 661 | case DBUS_TYPE_INT64: |
| 671 | CHECK_TYPE_RANGED_INTEGER_OR_FLOAT (dbus_int64_t, object); | ||
| 672 | { | 662 | { |
| 673 | dbus_int64_t val = extract_signed (object, | 663 | dbus_int64_t val = extract_signed (object, |
| 674 | TYPE_MINIMUM (dbus_int64_t), | 664 | TYPE_MINIMUM (dbus_int64_t), |
| @@ -810,7 +800,7 @@ xd_append_arg (unsigned int dtype, Lisp_Object object, DBusMessageIter *iter) | |||
| 810 | D-Bus message must be a valid DBusType. Compound D-Bus types | 800 | D-Bus message must be a valid DBusType. Compound D-Bus types |
| 811 | result always in a Lisp list. */ | 801 | result always in a Lisp list. */ |
| 812 | static Lisp_Object | 802 | static Lisp_Object |
| 813 | xd_retrieve_arg (unsigned int dtype, DBusMessageIter *iter) | 803 | xd_retrieve_arg (int dtype, DBusMessageIter *iter) |
| 814 | { | 804 | { |
| 815 | 805 | ||
| 816 | switch (dtype) | 806 | switch (dtype) |
| @@ -942,7 +932,7 @@ xd_retrieve_arg (unsigned int dtype, DBusMessageIter *iter) | |||
| 942 | } | 932 | } |
| 943 | 933 | ||
| 944 | /* Return the number of references of the shared CONNECTION. */ | 934 | /* Return the number of references of the shared CONNECTION. */ |
| 945 | static int | 935 | static ptrdiff_t |
| 946 | xd_get_connection_references (DBusConnection *connection) | 936 | xd_get_connection_references (DBusConnection *connection) |
| 947 | { | 937 | { |
| 948 | ptrdiff_t *refcount; | 938 | ptrdiff_t *refcount; |
| @@ -1115,7 +1105,7 @@ this connection to those buses. */) | |||
| 1115 | DBusConnection *connection; | 1105 | DBusConnection *connection; |
| 1116 | DBusError derror; | 1106 | DBusError derror; |
| 1117 | Lisp_Object val; | 1107 | Lisp_Object val; |
| 1118 | int refcount; | 1108 | ptrdiff_t refcount; |
| 1119 | 1109 | ||
| 1120 | /* Check parameter. */ | 1110 | /* Check parameter. */ |
| 1121 | XD_DBUS_VALIDATE_BUS_ADDRESS (bus); | 1111 | XD_DBUS_VALIDATE_BUS_ADDRESS (bus); |
| @@ -1185,7 +1175,7 @@ this connection to those buses. */) | |||
| 1185 | 1175 | ||
| 1186 | /* Return reference counter. */ | 1176 | /* Return reference counter. */ |
| 1187 | refcount = xd_get_connection_references (connection); | 1177 | refcount = xd_get_connection_references (connection); |
| 1188 | XD_DEBUG_MESSAGE ("Bus %s, Reference counter %d", | 1178 | XD_DEBUG_MESSAGE ("Bus %s, Reference counter %"pD"d", |
| 1189 | XD_OBJECT_TO_STRING (bus), refcount); | 1179 | XD_OBJECT_TO_STRING (bus), refcount); |
| 1190 | return make_number (refcount); | 1180 | return make_number (refcount); |
| 1191 | } | 1181 | } |
| @@ -1249,8 +1239,8 @@ usage: (dbus-message-internal &rest REST) */) | |||
| 1249 | DBusConnection *connection; | 1239 | DBusConnection *connection; |
| 1250 | DBusMessage *dmessage; | 1240 | DBusMessage *dmessage; |
| 1251 | DBusMessageIter iter; | 1241 | DBusMessageIter iter; |
| 1252 | unsigned int dtype; | 1242 | int dtype; |
| 1253 | unsigned int mtype; | 1243 | int mtype; |
| 1254 | dbus_uint32_t serial = 0; | 1244 | dbus_uint32_t serial = 0; |
| 1255 | unsigned int ui_serial; | 1245 | unsigned int ui_serial; |
| 1256 | int timeout = -1; | 1246 | int timeout = -1; |
| @@ -1264,9 +1254,10 @@ usage: (dbus-message-internal &rest REST) */) | |||
| 1264 | handler = Qnil; | 1254 | handler = Qnil; |
| 1265 | 1255 | ||
| 1266 | CHECK_NATNUM (message_type); | 1256 | CHECK_NATNUM (message_type); |
| 1267 | mtype = XFASTINT (message_type); | 1257 | if (! (DBUS_MESSAGE_TYPE_INVALID < XFASTINT (message_type) |
| 1268 | if ((mtype <= DBUS_MESSAGE_TYPE_INVALID) || (mtype >= DBUS_NUM_MESSAGE_TYPES)) | 1258 | && XFASTINT (message_type) < DBUS_NUM_MESSAGE_TYPES)) |
| 1269 | XD_SIGNAL2 (build_string ("Invalid message type"), message_type); | 1259 | XD_SIGNAL2 (build_string ("Invalid message type"), message_type); |
| 1260 | mtype = XFASTINT (message_type); | ||
| 1270 | 1261 | ||
| 1271 | if ((mtype == DBUS_MESSAGE_TYPE_METHOD_CALL) | 1262 | if ((mtype == DBUS_MESSAGE_TYPE_METHOD_CALL) |
| 1272 | || (mtype == DBUS_MESSAGE_TYPE_SIGNAL)) | 1263 | || (mtype == DBUS_MESSAGE_TYPE_SIGNAL)) |
| @@ -1280,7 +1271,7 @@ usage: (dbus-message-internal &rest REST) */) | |||
| 1280 | } | 1271 | } |
| 1281 | else /* DBUS_MESSAGE_TYPE_METHOD_RETURN, DBUS_MESSAGE_TYPE_ERROR */ | 1272 | else /* DBUS_MESSAGE_TYPE_METHOD_RETURN, DBUS_MESSAGE_TYPE_ERROR */ |
| 1282 | { | 1273 | { |
| 1283 | XD_CHECK_DBUS_SERIAL (args[3], serial); | 1274 | serial = extract_unsigned (args[3], TYPE_MAXIMUM (dbus_uint32_t)); |
| 1284 | count = 4; | 1275 | count = 4; |
| 1285 | } | 1276 | } |
| 1286 | 1277 | ||
| @@ -1504,8 +1495,8 @@ xd_read_message_1 (DBusConnection *connection, Lisp_Object bus) | |||
| 1504 | struct input_event event; | 1495 | struct input_event event; |
| 1505 | DBusMessage *dmessage; | 1496 | DBusMessage *dmessage; |
| 1506 | DBusMessageIter iter; | 1497 | DBusMessageIter iter; |
| 1507 | unsigned int dtype; | 1498 | int dtype; |
| 1508 | unsigned int mtype; | 1499 | int mtype; |
| 1509 | dbus_uint32_t serial; | 1500 | dbus_uint32_t serial; |
| 1510 | unsigned int ui_serial; | 1501 | unsigned int ui_serial; |
| 1511 | const char *uname, *path, *interface, *member; | 1502 | const char *uname, *path, *interface, *member; |
| @@ -1753,10 +1744,10 @@ syms_of_dbusbind (void) | |||
| 1753 | { | 1744 | { |
| 1754 | #ifdef DBUS_VERSION | 1745 | #ifdef DBUS_VERSION |
| 1755 | int major, minor, micro; | 1746 | int major, minor, micro; |
| 1756 | char s[1024]; | 1747 | char s[sizeof ".." + 3 * INT_STRLEN_BOUND (int)]; |
| 1757 | dbus_get_version (&major, &minor, µ); | 1748 | dbus_get_version (&major, &minor, µ); |
| 1758 | snprintf (s, sizeof s, "%d.%d.%d", major, minor, micro); | 1749 | sprintf (s, "%d.%d.%d", major, minor, micro); |
| 1759 | Vdbus_runtime_version = make_string (s, strlen (s)); | 1750 | Vdbus_runtime_version = build_string (s); |
| 1760 | #else | 1751 | #else |
| 1761 | Vdbus_runtime_version = Qnil; | 1752 | Vdbus_runtime_version = Qnil; |
| 1762 | #endif | 1753 | #endif |