/* internal types and variables */
+/* Function to get the GQuark for errors,
+ * with error codes specified by AmUtilError
+ *
+ * @return The GQuark that's used for errors
+ */
+GQuark am_util_error_quark(void);
+
+/* Error codes that may be returned by these functions */
+typedef enum {
+ AM_UTIL_ERROR_HEXDECODEINVAL,
+} AmUtilError;
+
int connect_portrange(sockaddr_union *, in_port_t, in_port_t, char *,
sockaddr_union *, int);
int bind_portrange(int, sockaddr_union *, in_port_t, in_port_t,
char *);
+/* just like an accept() call, but periodically calling PROLONG(PROLONG_DATA) and
+ * returning -1 with errno set to 0 if PROLONG returns false. Note that the socket
+ * need not be configured as non-blocking.
+ *
+ * Other arguments are just like for accept(2).
+ */
+int interruptible_accept(int sock, struct sockaddr *addr, socklen_t *addrlen,
+ gboolean (*prolong)(gpointer data), gpointer prolong_data);
+
ssize_t full_writev(int, struct iovec *, int);
char * construct_datestamp(time_t *t);
char * construct_timestamp(time_t *t);
-/*@only@*//*@null@*/char *quote_string(const char *str);
+/* quote_string only adds "" if they're required; quote_string_always
+ * always adds "" around the string */
+#define quote_string(str) quote_string_maybe((str), 0)
+#define quote_string_always(str) quote_string_maybe((str), 1)
+#define len_quote_string(str) len_quote_string_maybe((str), 0);
+
+/*@only@*//*@null@*/char *quote_string_maybe(const char *str, gboolean always);
/*@only@*//*@null@*/char *unquote_string(const char *str);
-int needs_quotes(const char * str);
+/*@only@*//*@null@*/int len_quote_string_maybe(const char *str, gboolean always);
/* Split a string into space-delimited words, obeying quoting as created by
* quote_string. To keep compatibility with the old split(), this has the
char * strquotedstr(char **saveptr);
char * sanitize_string(const char *str);
+
+/* Encode a string using URI-style hexadecimal encoding.
+ * Non-alphanumeric characters will be replaced with "%xx"
+ * where "xx" is the two-digit hexadecimal representation of the character.
+ *
+ * @param str The string to encode
+ *
+ * @return The encoded string. An empty string will be returned for NULL.
+ */
+char * hexencode_string(const char *str);
+
+/* Decode a string using URI-style hexadecimal encoding.
+ *
+ * @param str The string to decode
+ * @param err return location for a GError
+ *
+ * @return The decoded string. An empty string will be returned for NULL
+ * or if an error occurs.
+ */
+char * hexdecode_string(const char *str, GError **err);
+
int copy_file(char *dst, char *src, char **errmsg);
+/* These two functions handle "braced alternates", which is a syntax borrowed,
+ * partially, from shells. See perl/Amanda/Util.pod for a full description of
+ * the syntax they support.
+ */
+GPtrArray * expand_braced_alternates(char * source);
+char * collapse_braced_alternates(GPtrArray *source);
+
/*
* validate_email return 0 if the following characters are present
* * ( ) < > [ ] , ; : ! $ \ / "
* not NULL.
*
* @param hostname: the hostname to start with
+ * @param socktype: the socket type (SOCK_DGRAM or SOCK_STREAM)
* @param res: (result) if not NULL, the results from getaddrinfo()
- * @param canonname: (result) if not NULL, the canonical name of the host
- * @returns: newly allocated canonical hostname, or NULL if no
- * canonical hostname was available.
+ * @param canonname: (result) if not NULL, the newly-allocated canonical name of the host
+ * @returns: 0 on success, otherwise a getaddrinfo result (for use with gai_strerror)
*/
int resolve_hostname(const char *hostname, int socktype,
struct addrinfo **res, char **canonname);
RUNNING_AS_CLIENT_LOGIN,
RUNNING_AS_USER_MASK = (1 << 8) - 1,
- /* '&' this on to only check the uid, not the euid; use this for programs
+ /* '|' this on to only check the uid, not the euid; use this for programs
* that will call become_root() */
RUNNING_AS_UID_ONLY = 1 << 8
} running_as_flags;
* need to be root for certain operations. Does nothing if SINGLE_USERID is
* defined.
*
- * @param need_root: if true, try to assume root priviledges; otherwise, drop
- * priviledges.
+ * @param need_root: if 1, try to assume root priviledges; otherwise, drop
+ * priviledges. If -1, drop them irreversibly.
* @returns: true if the priviledge change succeeded
*/
int set_root_privs(int need_root);
* or prototypes some simple stub functions that are used instead.
*/
-#ifdef HAVE_READLINE
-# ifdef HAVE_READLINE_READLINE_H
+#ifdef HAVE_LIBREADLINE
+# if defined(HAVE_READLINE_READLINE_H)
# include <readline/readline.h>
-# ifdef HAVE_READLINE_HISTORY_H
-# include <readline/history.h>
-# endif
-# else
-# ifdef HAVE_READLINE_H
-# include <readline.h>
-# ifdef HAVE_HISTORY_H
-# include <history.h>
-# endif
-# endif
-# endif
-#else
+# elif defined(HAVE_READLINE_H)
+# include <readline.h>
+# else /* !defined(HAVE_READLINE_H) */
+extern char *readline ();
+# endif /* !defined(HAVE_READLINE_H) */
+ /* char *cmdline = NULL; */
+#else /* !defined(HAVE_LIBREADLINE) */
+ /* use our own readline */
+char * readline(const char *prompt);
+#endif /* HAVE_LIBREADLINE */
+
+#ifdef HAVE_READLINE_HISTORY
+# if defined(HAVE_READLINE_HISTORY_H)
+# include <readline/history.h>
+# elif defined(HAVE_HISTORY_H)
+# include <history.h>
+# else /* !defined(HAVE_HISTORY_H) */
+extern void add_history ();
+extern int write_history ();
+extern int read_history ();
+# endif /* defined(HAVE_READLINE_HISTORY_H) */
+#else /* !defined(HAVE_READLINE_HISTORY) */
+ /* use our own add_history */
+void add_history(const char *line);
+#endif /* HAVE_READLINE_HISTORY */
-char * readline(const char *prompt);
-void add_history(const char *line);
+char *base64_decode_alloc_string(char *);
+/* Inform the OpenBSD pthread library about the high-numbered file descriptors
+ * that an amandad service inherits. This won't be necessary once the new
+ * threading library is availble (OpenBSD 5.0?), but won't hurt anyway. See the
+ * thread "Backup issues with OpenBSD 4.5 machines" from September 2009. */
+#ifdef __OpenBSD__
+void openbsd_fd_inform(void);
+#else
+#define openbsd_fd_inform()
#endif
-char *base64_decode_alloc_string(char *);
-
-/* A GHFunc (callback for g_hash_table_foreach),
- * Count the number of properties.
+/* Add all properties to an ARGV
*
- * @param key_p: (char *) property name.
- * @param value_p: (GSList *) property values list.
- * @param user_data_p: (int *) count are added to that value.
+ * @param argvchild: Pointer to the ARGV.
+ * @param proplist: The property list
*/
-void count_proplist(gpointer key_p,
- gpointer value_p,
- gpointer user_data_p);
+void property_add_to_argv(GPtrArray *argv_ptr, GHashTable *proplist);
-/* A GHFunc (callback for g_hash_table_foreach),
- * Store a property and it's value in an ARGV.
+/* Print the argv_ptr with g_debug()
*
- * @param key_p: (char *) property name.
- * @param value_p: (GSList *) property values list.
- * @param user_data_p: (char ***) pointer to ARGV.
+ * @param argv_ptr: GPtrArray of an array to print.
*/
-void proplist_add_to_argv(gpointer key_p,
- gpointer value_p,
- gpointer user_data_p);
+void debug_executing(GPtrArray *argv_ptr);
#endif /* UTIL_H */