/*
- * "$Id: usersys.c 5138 2006-02-21 10:49:06Z mike $"
+ * "$Id$"
*
* User, system, and password routines for the Common UNIX Printing
* System (CUPS).
*
* Contents:
*
- * cupsEncryption() - Get the default encryption settings.
- * cupsGetPassword() - Get a password from the user.
- * cupsServer() - Return the hostname of the default server.
- * cupsSetEncryption() - Set the encryption preference.
- * cupsSetPasswordCB() - Set the password callback for CUPS.
- * cupsSetServer() - Set the default server name.
- * cupsSetUser() - Set the default user name.
- * cupsUser() - Return the current users name.
- * _cupsGetPassword() - Get a password from the user.
+ * cupsEncryption() - Get the default encryption settings.
+ * cupsGetPassword() - Get a password from the user.
+ * cupsServer() - Return the hostname of the default server.
+ * cupsSetEncryption() - Set the encryption preference.
+ * cupsSetPasswordCB() - Set the password callback for CUPS.
+ * cupsSetServer() - Set the default server name.
+ * cupsSetUser() - Set the default user name.
+ * cupsUser() - Return the current users name.
+ * _cupsGetPassword() - Get a password from the user.
+ * cups_open_client_conf() - Open the client.conf file.
*/
/*
#endif /* WIN32 */
+/*
+ * Local functions...
+ */
+
+static cups_file_t *cups_open_client_conf(void);
+
+
/*
* 'cupsEncryption()' - Get the default encryption settings.
*
{
cups_file_t *fp; /* client.conf file */
char *encryption; /* CUPS_ENCRYPTION variable */
- const char *home; /* Home directory of user */
char line[1024], /* Line from file */
*value; /* Value on line */
int linenum; /* Line number */
if ((encryption = getenv("CUPS_ENCRYPTION")) == NULL)
{
/*
- * Next check to see if we have a $HOME/.cupsrc or client.conf file...
+ * No, open the client.conf file...
*/
- if ((home = getenv("HOME")) != NULL)
- {
- snprintf(line, sizeof(line), "%s/.cupsrc", home);
- fp = cupsFileOpen(line, "r");
- }
- else
- fp = NULL;
-
- if (fp == NULL)
- {
- snprintf(line, sizeof(line), "%s/client.conf", cg->cups_serverroot);
- fp = cupsFileOpen(line, "r");
- }
-
+ fp = cups_open_client_conf();
encryption = "IfRequested";
- if (fp != NULL)
+ if (fp)
{
/*
* Read the config file and look for an Encryption line...
{
cups_file_t *fp; /* client.conf file */
char *server; /* Pointer to server name */
- const char *home; /* Home directory of user */
char *port; /* Port number */
char line[1024], /* Line from file */
*value; /* Value on line */
if ((server = getenv("CUPS_SERVER")) == NULL)
{
/*
- * Next check to see if we have a $HOME/.cupsrc or client.conf file...
+ * No environment variable, try the client.conf file...
*/
- if ((home = getenv("HOME")) != NULL)
- {
- snprintf(line, sizeof(line), "%s/.cupsrc", home);
- fp = cupsFileOpen(line, "r");
- }
- else
- fp = NULL;
-
- if (fp == NULL)
- {
- snprintf(line, sizeof(line), "%s/client.conf", cg->cups_serverroot);
- fp = cupsFileOpen(line, "r");
- }
+ fp = cups_open_client_conf();
#ifdef CUPS_DEFAULT_DOMAINSOCKET
/*
#endif /* CUPS_DEFAULT_DOMAINSOCKET */
server = "localhost";
- if (fp != NULL)
+ if (fp)
{
/*
* Read the config file and look for a ServerName line...
/*
- * End of "$Id: usersys.c 5138 2006-02-21 10:49:06Z mike $".
+ * 'cups_open_client_conf()' - Open the client.conf file.
+ */
+
+static cups_file_t * /* O - File or NULL */
+cups_open_client_conf(void)
+{
+ cups_file_t *fp; /* File */
+ const char *home; /* Home directory of user */
+ char filename[1024]; /* Filename */
+ _cups_globals_t *cg = _cupsGlobals(); /* Pointer to library globals */
+
+
+ if ((home = getenv("HOME")) != NULL)
+ {
+ /*
+ * Look for ~/.cups/client.conf or ~/.cupsrc...
+ */
+
+ snprintf(filename, sizeof(filename), "%s/.cups/client.conf", home);
+ if ((fp = cupsFileOpen(filename, "r")) != NULL)
+ return (fp);
+
+ snprintf(filename, sizeof(filename), "%s/.cupsrc", home);
+ if ((fp = cupsFileOpen(filename, "r")) != NULL)
+ return (fp);
+ }
+
+ snprintf(filename, sizeof(filename), "%s/client.conf", cg->cups_serverroot);
+ return (cupsFileOpen(filename, "r"));
+}
+
+
+/*
+ * End of "$Id$".
*/