s3-printing: avoid mixing cups backend code with nt_printing code in cups_pull_commen...
authorGünther Deschner <gd@samba.org>
Fri, 26 Mar 2010 12:17:49 +0000 (13:17 +0100)
committerGünther Deschner <gd@samba.org>
Fri, 26 Mar 2010 13:36:46 +0000 (14:36 +0100)
Guenther

source3/include/proto.h
source3/printing/nt_printing.c
source3/printing/print_cups.c

index c211501ac544476b460ff7eecdb35f11e105d9e6..ecb29618aee3be17d107833c3e2581c2cc451c83 100644 (file)
@@ -4897,7 +4897,10 @@ bool aix_cache_reload(void);
 /* The following definitions come from printing/print_cups.c  */
 
 bool cups_cache_reload(void);
-bool cups_pull_comment_location(NT_PRINTER_INFO_LEVEL_2 *printer);
+bool cups_pull_comment_location(TALLOC_CTX *mem_ctx,
+                               const char *printername,
+                               char **comment,
+                               char **location);
 
 /* The following definitions come from printing/print_generic.c  */
 
index b29000a2d8116fe71053d6e5c459c567a3b92d7d..5096ca0599b8cbd2149567f6c83f2c8518ea0729 100644 (file)
@@ -3831,8 +3831,17 @@ static WERROR get_a_printer_2_default(NT_PRINTER_INFO_LEVEL_2 *info,
        if (get_loc_com && (enum printing_types)lp_printing(snum) == PRINT_CUPS ) {
                /* Pull the location and comment strings from cups if we don't
                   already have one */
-               if ( !strlen(info->location) || !strlen(info->comment) )
-                       cups_pull_comment_location( info );
+               if ( !strlen(info->location) || !strlen(info->comment) ) {
+                       char *comment = NULL;
+                       char *location = NULL;
+                       if (cups_pull_comment_location(info, info->sharename,
+                                                      &comment, &location)) {
+                               strlcpy(info->comment, comment, sizeof(info->comment));
+                               fstrcpy(info->location, location);
+                               TALLOC_FREE(comment);
+                               TALLOC_FREE(location);
+                       }
+               }
        }
 #endif
 
@@ -3953,8 +3962,17 @@ static WERROR get_a_printer_2(NT_PRINTER_INFO_LEVEL_2 *info,
        if (get_loc_com && (enum printing_types)lp_printing(snum) == PRINT_CUPS ) {
                /* Pull the location and comment strings from cups if we don't
                   already have one */
-               if ( !strlen(info->location) || !strlen(info->comment) )
-                       cups_pull_comment_location( info );
+               if ( !strlen(info->location) || !strlen(info->comment) ) {
+                       char *location = NULL;
+                       comment = NULL;
+                       if (cups_pull_comment_location(info, info->sharename,
+                                                      &comment, &location)) {
+                               strlcpy(info->comment, comment, sizeof(info->comment));
+                               fstrcpy(info->location, location);
+                               TALLOC_FREE(comment);
+                               TALLOC_FREE(location);
+                       }
+               }
        }
 #endif
 
index 5c023edf4927880feff83c0e92efea0eb36f7ef8..6735f14f703312a333129258ff5532757ff66a70 100644 (file)
@@ -1631,7 +1631,10 @@ struct printif   cups_printif =
        cups_job_submit,
 };
 
-bool cups_pull_comment_location(NT_PRINTER_INFO_LEVEL_2 *printer)
+bool cups_pull_comment_location(TALLOC_CTX *mem_ctx,
+                               const char *printername,
+                               char **comment,
+                               char **location)
 {
        TALLOC_CTX *frame = talloc_stackframe();
        http_t          *http = NULL;           /* HTTP connection to server */
@@ -1652,7 +1655,7 @@ bool cups_pull_comment_location(NT_PRINTER_INFO_LEVEL_2 *printer)
        bool ret = False;
        size_t size;
 
-       DEBUG(5, ("pulling %s location\n", printer->sharename));
+       DEBUG(5, ("pulling %s location\n", printername));
 
        /*
         * Make sure we don't ask for passwords...
@@ -1691,7 +1694,7 @@ bool cups_pull_comment_location(NT_PRINTER_INFO_LEVEL_2 *printer)
        if (server) {
                goto out;
        }
-       if (!push_utf8_talloc(frame, &sharename, printer->sharename, &size)) {
+       if (!push_utf8_talloc(frame, &sharename, printername, &size)) {
                goto out;
        }
        slprintf(uri, sizeof(uri) - 1, "ipp://%s/printers/%s",
@@ -1743,40 +1746,30 @@ bool cups_pull_comment_location(NT_PRINTER_INFO_LEVEL_2 *printer)
 
                        /* Grab the comment if we don't have one */
                        if ( (strcmp(attr->name, "printer-info") == 0)
-                            && (attr->value_tag == IPP_TAG_TEXT)
-                            && !strlen(printer->comment) )
+                            && (attr->value_tag == IPP_TAG_TEXT))
                        {
-                               char *comment = NULL;
-                               if (!pull_utf8_talloc(frame,
-                                               &comment,
+                               if (!pull_utf8_talloc(mem_ctx,
+                                               comment,
                                                attr->values[0].string.text,
                                                &size)) {
                                        goto out;
                                }
                                DEBUG(5,("cups_pull_comment_location: Using cups comment: %s\n",
-                                        comment));
-                               strlcpy(printer->comment,
-                                       comment,
-                                       sizeof(printer->comment));
+                                        *comment));
                        }
 
                        /* Grab the location if we don't have one */
                        if ( (strcmp(attr->name, "printer-location") == 0)
-                            && (attr->value_tag == IPP_TAG_TEXT)
-                            && !strlen(printer->location) )
+                            && (attr->value_tag == IPP_TAG_TEXT))
                        {
-                               char *location = NULL;
-                               if (!pull_utf8_talloc(frame,
-                                               &location,
+                               if (!pull_utf8_talloc(mem_ctx,
+                                               location,
                                                attr->values[0].string.text,
                                                &size)) {
                                        goto out;
                                }
                                DEBUG(5,("cups_pull_comment_location: Using cups location: %s\n",
-                                        location));
-                               strlcpy(printer->location,
-                                       location,
-                                       sizeof(printer->location));
+                                        *location));
                        }
 
                        attr = attr->next;