summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVincent Untz <vuntz@novell.com>2008-11-20 16:13:21 +0100
committerVincent Untz <vuntz@novell.com>2008-11-20 16:13:21 +0100
commit8f8853d8bc0a4283786a16d214e1ab6183731c3c (patch)
tree03cf0684eb3fb1d024db94ccaecc85ba1a917d48
parente99cc52da775db022197655fdc7b5ddd936a1fc3 (diff)
Add cps_cups_is_printer_uri_local() function.
It will be used to implement different policies, depending on the local vs remote printer.
-rw-r--r--src/cups.c61
-rw-r--r--src/cups.h3
2 files changed, 64 insertions, 0 deletions
diff --git a/src/cups.c b/src/cups.c
index 82d58ce..f5856ec 100644
--- a/src/cups.c
+++ b/src/cups.c
@@ -1150,3 +1150,64 @@ cph_cups_server_set_settings (CphCups *cups,
return TRUE;
}
+
+/******************************************************
+ * Non-object functions
+ ******************************************************/
+
+gboolean
+cps_cups_is_printer_uri_local (const char *uri)
+{
+ char *lower_uri;
+
+ g_return_val_if_fail (uri != NULL, FALSE);
+
+ lower_uri = g_ascii_strdown (uri, -1);
+
+ /* clearly local stuff */
+ if (g_str_has_prefix (lower_uri, "parallel:") ||
+ g_str_has_prefix (lower_uri, "usb:") ||
+ g_str_has_prefix (lower_uri, "hal:") ||
+ /* beh is the backend error handler */
+ g_str_has_prefix (lower_uri, "beh:") ||
+ g_str_has_prefix (lower_uri, "scsi:") ||
+ g_str_has_prefix (lower_uri, "serial:") ||
+ g_str_has_prefix (lower_uri, "pipe:")) {
+ g_free (lower_uri);
+ return TRUE;
+ }
+
+ /* clearly remote stuff */
+ if (g_str_has_prefix (lower_uri, "socket:") ||
+ g_str_has_prefix (lower_uri, "ipp:") ||
+ g_str_has_prefix (lower_uri, "http:") ||
+ g_str_has_prefix (lower_uri, "lpd:") ||
+ g_str_has_prefix (lower_uri, "smb:") ||
+ g_str_has_prefix (lower_uri, "novell:")) {
+ g_free (lower_uri);
+ return FALSE;
+ }
+
+ /* hplip can be both, I think. Let's just check if we have an ip
+ * argument in the URI */
+ if (g_str_has_prefix (lower_uri, "hp:") ||
+ g_str_has_prefix (lower_uri, "hpfax:")) {
+ char *buf;
+
+ buf = strchr (lower_uri, '?');
+
+ while (buf) {
+ if (g_str_has_prefix (buf, "ip="))
+ break;
+ buf = strchr (buf, '&');
+ }
+
+ g_free (lower_uri);
+ return buf == NULL;
+ }
+
+ g_free (lower_uri);
+
+ /* we don't know, so we assume it's not local */
+ return FALSE;
+}
diff --git a/src/cups.h b/src/cups.h
index b235fa2..e1f9a92 100644
--- a/src/cups.h
+++ b/src/cups.h
@@ -130,6 +130,9 @@ GHashTable *cph_cups_server_get_settings (CphCups *cups);
gboolean cph_cups_server_set_settings (CphCups *cups,
GHashTable *settings);
+
+gboolean cps_cups_is_printer_uri_local (const char *uri);
+
G_END_DECLS
#endif /* CPH_CUPS_H */