]> err.no Git - systemd/commitdiff
libudev: export udev_util_encode_string()
authorKay Sievers <kay.sievers@vrfy.org>
Wed, 5 Oct 2011 23:10:59 +0000 (01:10 +0200)
committerKay Sievers <kay.sievers@vrfy.org>
Wed, 5 Oct 2011 23:10:59 +0000 (01:10 +0200)
Makefile.am
extras/ata_id/ata_id.c
extras/scsi_id/scsi_id.c
libudev/docs/libudev-docs.xml
libudev/docs/libudev-sections.txt
libudev/libudev-private.h
libudev/libudev-util.c
libudev/libudev.h
udev/udev-builtin-usb_id.c
udev/udev-event.c
udev/udev-rules.c

index d15c6d01b26857624c9bc8dcc3e22efce0f16860..d8b1889c222383197f96baeba279c5aaef5919bd 100644 (file)
@@ -41,9 +41,9 @@ dist_libexec_SCRIPTS =
 # ------------------------------------------------------------------------------
 # libudev
 # ------------------------------------------------------------------------------
-LIBUDEV_CURRENT=12
-LIBUDEV_REVISION=2
-LIBUDEV_AGE=12
+LIBUDEV_CURRENT=13
+LIBUDEV_REVISION=0
+LIBUDEV_AGE=13
 
 SUBDIRS += libudev/docs
 
index cadadfc27fa422d86c40f784778ba34192cc68d5..e38a7d1aa522b94492916009945d589ffa148675 100644 (file)
@@ -547,12 +547,12 @@ int main(int argc, char *argv[])
        memcpy (model, id.model, 40);
        model[40] = '\0';
        udev_util_encode_string(model, model_enc, sizeof(model_enc));
-       udev_util_replace_whitespace((char *) id.model, model, 40);
-       udev_util_replace_chars(model, NULL);
-       udev_util_replace_whitespace((char *) id.serial_no, serial, 20);
-       udev_util_replace_chars(serial, NULL);
-       udev_util_replace_whitespace((char *) id.fw_rev, revision, 8);
-       udev_util_replace_chars(revision, NULL);
+       util_replace_whitespace((char *) id.model, model, 40);
+       util_replace_chars(model, NULL);
+       util_replace_whitespace((char *) id.serial_no, serial, 20);
+       util_replace_chars(serial, NULL);
+       util_replace_whitespace((char *) id.fw_rev, revision, 8);
+       util_replace_chars(revision, NULL);
 
        if (export) {
                /* Set this to convey the disk speaks the ATA protocol */
index c14d411841ab6d85e3431721565817fb078aaa8c..26b92e3fcda70a6f6626da90dd4b93f551275f66 100644 (file)
@@ -510,13 +510,13 @@ static int set_inq_values(struct udev *udev, struct scsi_id_device *dev_scsi, co
        udev_util_encode_string(dev_scsi->vendor, vendor_enc_str, sizeof(vendor_enc_str));
        udev_util_encode_string(dev_scsi->model, model_enc_str, sizeof(model_enc_str));
 
-       udev_util_replace_whitespace(dev_scsi->vendor, vendor_str, sizeof(vendor_str));
-       udev_util_replace_chars(vendor_str, NULL);
-       udev_util_replace_whitespace(dev_scsi->model, model_str, sizeof(model_str));
-       udev_util_replace_chars(model_str, NULL);
+       util_replace_whitespace(dev_scsi->vendor, vendor_str, sizeof(vendor_str));
+       util_replace_chars(vendor_str, NULL);
+       util_replace_whitespace(dev_scsi->model, model_str, sizeof(model_str));
+       util_replace_chars(model_str, NULL);
        set_type(dev_scsi->type, type_str, sizeof(type_str));
-       udev_util_replace_whitespace(dev_scsi->revision, revision_str, sizeof(revision_str));
-       udev_util_replace_chars(revision_str, NULL);
+       util_replace_whitespace(dev_scsi->revision, revision_str, sizeof(revision_str));
+       util_replace_chars(revision_str, NULL);
        return 0;
 }
 
@@ -560,11 +560,11 @@ static int scsi_id(struct udev *udev, char *maj_min_dev)
                printf("ID_REVISION=%s\n", revision_str);
                printf("ID_TYPE=%s\n", type_str);
                if (dev_scsi.serial[0] != '\0') {
-                       udev_util_replace_whitespace(dev_scsi.serial, serial_str, sizeof(serial_str));
-                       udev_util_replace_chars(serial_str, NULL);
+                       util_replace_whitespace(dev_scsi.serial, serial_str, sizeof(serial_str));
+                       util_replace_chars(serial_str, NULL);
                        printf("ID_SERIAL=%s\n", serial_str);
-                       udev_util_replace_whitespace(dev_scsi.serial_short, serial_str, sizeof(serial_str));
-                       udev_util_replace_chars(serial_str, NULL);
+                       util_replace_whitespace(dev_scsi.serial_short, serial_str, sizeof(serial_str));
+                       util_replace_chars(serial_str, NULL);
                        printf("ID_SERIAL_SHORT=%s\n", serial_str);
                }
                if (dev_scsi.wwn[0] != '\0') {
@@ -593,8 +593,8 @@ static int scsi_id(struct udev *udev, char *maj_min_dev)
        if (reformat_serial) {
                char serial_str[MAX_SERIAL_LEN];
 
-               udev_util_replace_whitespace(dev_scsi.serial, serial_str, sizeof(serial_str));
-               udev_util_replace_chars(serial_str, NULL);
+               util_replace_whitespace(dev_scsi.serial, serial_str, sizeof(serial_str));
+               util_replace_chars(serial_str, NULL);
                printf("%s\n", serial_str);
                goto out;
        }
index f47091670067d3cc47ef0def2b8aef330a43c051..b7feb45529edd2b9d9fcaa8f52ea74a60bf6f2cb 100644 (file)
@@ -9,7 +9,7 @@
     <title>libudev Reference Manual</title>
     <releaseinfo>for libudev version &version;</releaseinfo>
     <copyright>
-      <year>2009-2010</year>
+      <year>2009-2011</year>
       <holder>Kay Sievers &lt;kay.sievers@vrfy.org&gt;</holder>
     </copyright>
   </bookinfo>
@@ -22,6 +22,7 @@
     <xi:include href="xml/libudev-monitor.xml"/>
     <xi:include href="xml/libudev-enumerate.xml"/>
     <xi:include href="xml/libudev-queue.xml"/>
+    <xi:include href="xml/libudev-util.xml"/>
   </chapter>
 
   <index id="api-index-full">
index a686c4558ef1e462081393f368a71cc095bda606..15c3e934b58b42b3fcdaa2978b3875350ac3e836 100644 (file)
@@ -120,3 +120,8 @@ udev_queue_get_kernel_seqnum
 udev_queue_get_udev_seqnum
 </SECTION>
 
+<SECTION>
+<FILE>libudev-util</FILE>
+<TITLE>udev_util</TITLE>
+udev_util_encode_string
+</SECTION>
index 1bcd2e323694d64b990ed048cf1a57e8845599d2..ffc82cbc6d7accfb80dfc757755c181fd50c68c6 100644 (file)
@@ -181,9 +181,8 @@ size_t util_strpcpy(char **dest, size_t size, const char *src);
 size_t util_strpcpyl(char **dest, size_t size, const char *src, ...) __attribute__((sentinel));
 size_t util_strscpy(char *dest, size_t size, const char *src);
 size_t util_strscpyl(char *dest, size_t size, const char *src, ...) __attribute__((sentinel));
-int udev_util_replace_whitespace(const char *str, char *to, size_t len);
-int udev_util_replace_chars(char *str, const char *white);
-int udev_util_encode_string(const char *str, char *str_enc, size_t len);
+int util_replace_whitespace(const char *str, char *to, size_t len);
+int util_replace_chars(char *str, const char *white);
 unsigned int util_string_hash32(const char *key);
 uint64_t util_string_bloom64(const char *str);
 
index a600b0a8812b88906ad9dcddebef3afe40ecceb5..e08349e0fa345d051a30d66d4d7a03f3b06592ea 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * libudev - interface to udev device information
  *
- * Copyright (C) 2008-2009 Kay Sievers <kay.sievers@vrfy.org>
+ * Copyright (C) 2008-2011 Kay Sievers <kay.sievers@vrfy.org>
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
 #include "libudev.h"
 #include "libudev-private.h"
 
+/**
+ * SECTION:libudev-util
+ * @short_description: utils
+ */
+
 ssize_t util_get_sys_core_link_value(struct udev *udev, const char *slink, const char *syspath, char *value, size_t size)
 {
        char path[UTIL_PATH_SIZE];
@@ -342,7 +347,7 @@ static int utf8_encoded_valid_unichar(const char *str)
        return len;
 }
 
-int udev_util_replace_whitespace(const char *str, char *to, size_t len)
+int util_replace_whitespace(const char *str, char *to, size_t len)
 {
        size_t i, j;
 
@@ -382,7 +387,7 @@ static int is_whitelisted(char c, const char *white)
 }
 
 /* allow chars in whitelist, plain ascii, hex-escaping and valid utf8 */
-int udev_util_replace_chars(char *str, const char *white)
+int util_replace_chars(char *str, const char *white)
 {
        size_t i = 0;
        int replaced = 0;
@@ -425,18 +430,18 @@ int udev_util_replace_chars(char *str, const char *white)
 }
 
 /**
- * util_encode_string:
+ * udev_util_encode_string:
  * @str: input string to be encoded
  * @str_enc: output string to store the encoded input string
  * @len: maximum size of the output string, which may be
  *       four times as long as the input string
  *
  * Encode all potentially unsafe characters of a string to the
- * corresponding hex value prefixed by '\x'.
+ * corresponding 2 char hex value prefixed by '\x'.
  *
  * Returns: 0 if the entire string was copied, non-zero otherwise.
  **/
-int udev_util_encode_string(const char *str, char *str_enc, size_t len)
+UDEV_EXPORT int udev_util_encode_string(const char *str, char *str_enc, size_t len)
 {
        size_t i, j;
 
index 47b56bb17ac417e36c6a16647466d08965de87f5..497f752fca5872d2f0c4fdc136e7869afcf7f490 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * libudev - interface to udev device information
  *
- * Copyright (C) 2008-2010 Kay Sievers <kay.sievers@vrfy.org>
+ * Copyright (C) 2008-2011 Kay Sievers <kay.sievers@vrfy.org>
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -174,6 +174,14 @@ int udev_queue_get_seqnum_sequence_is_finished(struct udev_queue *udev_queue,
                                               unsigned long long int start, unsigned long long int end);
 struct udev_list_entry *udev_queue_get_queued_list_entry(struct udev_queue *udev_queue);
 
+/*
+ * udev_util
+ *
+ * udev specific utilities
+ */
+int udev_util_encode_string(const char *str, char *str_enc, size_t len);
+
+
 #ifdef __cplusplus
 } /* extern "C" */
 #endif
index 1585b107a07fdea017d2464c37fa247891f9e8cb..587c21667bea1f19250992bed64bc75e2cd85f83 100644 (file)
@@ -350,8 +350,8 @@ static int builtin_usb_id(struct udev_device *dev, bool test)
                        goto fallback;
                }
                udev_util_encode_string(scsi_vendor, vendor_str_enc, sizeof(vendor_str_enc));
-               udev_util_replace_whitespace(scsi_vendor, vendor_str, sizeof(vendor_str)-1);
-               udev_util_replace_chars(vendor_str, NULL);
+               util_replace_whitespace(scsi_vendor, vendor_str, sizeof(vendor_str)-1);
+               util_replace_chars(vendor_str, NULL);
 
                scsi_model = udev_device_get_sysattr_value(dev_scsi, "model");
                if (!scsi_model) {
@@ -360,8 +360,8 @@ static int builtin_usb_id(struct udev_device *dev, bool test)
                        goto fallback;
                }
                udev_util_encode_string(scsi_model, model_str_enc, sizeof(model_str_enc));
-               udev_util_replace_whitespace(scsi_model, model_str, sizeof(model_str)-1);
-               udev_util_replace_chars(model_str, NULL);
+               util_replace_whitespace(scsi_model, model_str, sizeof(model_str)-1);
+               util_replace_chars(model_str, NULL);
 
                scsi_type = udev_device_get_sysattr_value(dev_scsi, "type");
                if (!scsi_type) {
@@ -377,8 +377,8 @@ static int builtin_usb_id(struct udev_device *dev, bool test)
                             udev_device_get_sysname(dev_scsi));
                        goto fallback;
                }
-               udev_util_replace_whitespace(scsi_rev, revision_str, sizeof(revision_str)-1);
-               udev_util_replace_chars(revision_str, NULL);
+               util_replace_whitespace(scsi_rev, revision_str, sizeof(revision_str)-1);
+               util_replace_chars(revision_str, NULL);
 
                /*
                 * some broken devices have the same identifiers
@@ -403,8 +403,8 @@ fallback:
                        return EXIT_FAILURE;
                }
                udev_util_encode_string(usb_vendor, vendor_str_enc, sizeof(vendor_str_enc));
-               udev_util_replace_whitespace(usb_vendor, vendor_str, sizeof(vendor_str)-1);
-               udev_util_replace_chars(vendor_str, NULL);
+               util_replace_whitespace(usb_vendor, vendor_str, sizeof(vendor_str)-1);
+               util_replace_chars(vendor_str, NULL);
        }
 
        if (model_str[0] == '\0') {
@@ -418,8 +418,8 @@ fallback:
                        return EXIT_FAILURE;
                }
                udev_util_encode_string(usb_model, model_str_enc, sizeof(model_str_enc));
-               udev_util_replace_whitespace(usb_model, model_str, sizeof(model_str)-1);
-               udev_util_replace_chars(model_str, NULL);
+               util_replace_whitespace(usb_model, model_str, sizeof(model_str)-1);
+               util_replace_chars(model_str, NULL);
        }
 
        if (revision_str[0] == '\0') {
@@ -427,8 +427,8 @@ fallback:
 
                usb_rev = udev_device_get_sysattr_value(dev_usb, "bcdDevice");
                if (usb_rev) {
-                       udev_util_replace_whitespace(usb_rev, revision_str, sizeof(revision_str)-1);
-                       udev_util_replace_chars(revision_str, NULL);
+                       util_replace_whitespace(usb_rev, revision_str, sizeof(revision_str)-1);
+                       util_replace_chars(revision_str, NULL);
                }
        }
 
@@ -437,8 +437,8 @@ fallback:
 
                usb_serial = udev_device_get_sysattr_value(dev_usb, "serial");
                if (usb_serial) {
-                       udev_util_replace_whitespace(usb_serial, serial_str, sizeof(serial_str)-1);
-                       udev_util_replace_chars(serial_str, NULL);
+                       util_replace_whitespace(usb_serial, serial_str, sizeof(serial_str)-1);
+                       util_replace_chars(serial_str, NULL);
                }
        }
 
index 3c1a3e7aa77a184734a2a7d7901612aab1590afd..7db75132476124b0bc940ba973565dcaf0ee46f0 100644 (file)
@@ -318,7 +318,7 @@ subst:
                        len = strlen(vbuf);
                        while (len > 0 && isspace(vbuf[--len]))
                                vbuf[len] = '\0';
-                       count = udev_util_replace_chars(vbuf, UDEV_ALLOWED_CHARS_INPUT);
+                       count = util_replace_chars(vbuf, UDEV_ALLOWED_CHARS_INPUT);
                        if (count > 0)
                                info(event->udev, "%i character(s) replaced\n" , count);
                        l = util_strpcpy(&s, l, vbuf);
index 84033243c2e48d5b2f806d5fd24c6c17a71578c7..75636d9bd6ee52685541356a1f5100d8078c6dee 100644 (file)
@@ -2271,7 +2271,7 @@ int udev_rules_apply_to_event(struct udev_rules *rules, struct udev_event *event
 
                                util_remove_trailing_chars(result, '\n');
                                if (esc == ESCAPE_UNSET || esc == ESCAPE_REPLACE) {
-                                       count = udev_util_replace_chars(result, UDEV_ALLOWED_CHARS_INPUT);
+                                       count = util_replace_chars(result, UDEV_ALLOWED_CHARS_INPUT);
                                        if (count > 0)
                                                info(event->udev, "%i character(s) replaced\n" , count);
                                }
@@ -2562,7 +2562,7 @@ int udev_rules_apply_to_event(struct udev_rules *rules, struct udev_event *event
                                event->name_final = true;
                        udev_event_apply_format(event, name, name_str, sizeof(name_str));
                        if (esc == ESCAPE_UNSET || esc == ESCAPE_REPLACE) {
-                               count = udev_util_replace_chars(name_str, "/");
+                               count = util_replace_chars(name_str, "/");
                                if (count > 0)
                                        info(event->udev, "%i character(s) replaced\n", count);
                        }
@@ -2592,9 +2592,9 @@ int udev_rules_apply_to_event(struct udev_rules *rules, struct udev_event *event
                        /* allow  multiple symlinks separated by spaces */
                        udev_event_apply_format(event, &rules->buf[cur->key.value_off], temp, sizeof(temp));
                        if (esc == ESCAPE_UNSET)
-                               count = udev_util_replace_chars(temp, "/ ");
+                               count = util_replace_chars(temp, "/ ");
                        else if (esc == ESCAPE_REPLACE)
-                               count = udev_util_replace_chars(temp, "/");
+                               count = util_replace_chars(temp, "/");
                        if (count > 0)
                                info(event->udev, "%i character(s) replaced\n" , count);
                        dbg(event->udev, "rule applied, added symlink(s) '%s'\n", temp);