#include "config.h"
+#include "buffer.h"
#include "debug.h"
#include "message.h"
#include "path.h"
+#include "url.h"
#include <assert.h>
#include <errno.h>
name[i] = '_';
}
}
+
+char *
+p11_path_encode (const char *path)
+{
+ static const char *VALID =
+ "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789.-_/\\";
+ p11_buffer buf;
+ char *result;
+
+ return_val_if_fail (path != NULL, NULL);
+
+ if (!p11_buffer_init_null (&buf, strlen (path)))
+ return_val_if_reached (NULL);
+
+ p11_url_encode ((unsigned char *)path,
+ (unsigned char *)path + strlen (path),
+ VALID,
+ &buf);
+ return_val_if_fail (p11_buffer_ok (&buf), NULL);
+
+ result = p11_buffer_steal (&buf, NULL);
+ p11_buffer_uninit (&buf);
+
+ return result;
+}
+
+char *
+p11_path_decode (const char *path)
+{
+ return (char *) p11_url_decode (path, path + strlen (path), "", NULL);
+}
void p11_path_canon (char *name);
+char * p11_path_encode (const char *path);
+
+char * p11_path_decode (const char *path);
+
#endif /* P11_PATH_H__ */
free (test);
}
+static void
+test_encode (void)
+{
+ char *test;
+
+ test = p11_path_encode ("2309haonutb;/AOE@#$O ");
+ assert_str_eq (test, "2309haonutb%3b/AOE%40%23%24O%20");
+ free (test);
+}
+
+static void
+test_decode (void)
+{
+ char *test;
+
+ test = p11_path_decode ("2309haonutb%3b/AOE%40%23%24O%20");
+ assert_str_eq (test, "2309haonutb;/AOE@#$O ");
+ free (test);
+}
+
int
main (int argc,
char *argv[])
p11_test (test_parent, "/path/parent");
p11_test (test_prefix, "/path/prefix");
p11_test (test_canon, "/path/canon");
+ p11_test (test_encode, "/path/encode");
+ p11_test (test_decode, "/path/decode");
return p11_test_run (argc, argv);
}