Ignore:
Timestamp:
May 26, 2009, 9:44:50 AM (16 years ago)
Author:
Herwig Bauernfeind
Message:

Update 3.2 branch to 3.2.6

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/samba-3.2.x/source/printing/pcap.c

    r133 r228  
    6464
    6565
    66 typedef struct pcap_cache {
     66struct pcap_cache {
    6767        char *name;
    6868        char *comment;
    6969        struct pcap_cache *next;
    70 } pcap_cache_t;
    71 
    72 static pcap_cache_t *pcap_cache = NULL;
    73 
    74 bool pcap_cache_add(const char *name, const char *comment)
    75 {
    76         pcap_cache_t *p;
    77 
    78         if (name == NULL || ((p = SMB_MALLOC_P(pcap_cache_t)) == NULL))
    79                 return False;
     70};
     71
     72/* The systemwide printcap cache. */
     73static struct pcap_cache *pcap_cache = NULL;
     74
     75bool pcap_cache_add_specific(struct pcap_cache **ppcache, const char *name, const char *comment)
     76{
     77        struct pcap_cache *p;
     78
     79        if (name == NULL || ((p = SMB_MALLOC_P(struct pcap_cache)) == NULL))
     80                return false;
    8081
    8182        p->name = SMB_STRDUP(name);
    8283        p->comment = (comment && *comment) ? SMB_STRDUP(comment) : NULL;
    8384
    84         p->next = pcap_cache;
    85         pcap_cache = p;
    86 
    87         return True;
    88 }
    89 
    90 static void pcap_cache_destroy(pcap_cache_t *cache)
    91 {
    92         pcap_cache_t *p, *next;
    93 
    94         for (p = cache; p != NULL; p = next) {
     85        DEBUG(11,("pcap_cache_add_specific: Adding name %s info %s\n",
     86                p->name, p->comment ? p->comment : ""));
     87
     88        p->next = *ppcache;
     89        *ppcache = p;
     90
     91        return true;
     92}
     93
     94void pcap_cache_destroy_specific(struct pcap_cache **pp_cache)
     95{
     96        struct pcap_cache *p, *next;
     97
     98        for (p = *pp_cache; p != NULL; p = next) {
    9599                next = p->next;
    96100
     
    99103                SAFE_FREE(p);
    100104        }
     105        *pp_cache = NULL;
     106}
     107
     108bool pcap_cache_add(const char *name, const char *comment)
     109{
     110        return pcap_cache_add_specific(&pcap_cache, name, comment);
    101111}
    102112
     
    104114{
    105115        return (pcap_cache != NULL);
     116}
     117
     118void pcap_cache_replace(const struct pcap_cache *pcache)
     119{
     120        const struct pcap_cache *p;
     121
     122        pcap_cache_destroy_specific(&pcap_cache);
     123        for (p = pcache; p; p = p->next) {
     124                pcap_cache_add(p->name, p->comment);
     125        }
    106126}
    107127
     
    110130        const char *pcap_name = lp_printcapname();
    111131        bool pcap_reloaded = False;
    112         pcap_cache_t *tmp_cache = NULL;
     132        struct pcap_cache *tmp_cache = NULL;
    113133        XFILE *pcap_file;
    114134        char *pcap_line;
     
    224244
    225245        if (pcap_reloaded)
    226                 pcap_cache_destroy(tmp_cache);
     246                pcap_cache_destroy_specific(&tmp_cache);
    227247        else {
    228                 pcap_cache_destroy(pcap_cache);
     248                pcap_cache_destroy_specific(&pcap_cache);
    229249                pcap_cache = tmp_cache;
    230250        }
     
    236256bool pcap_printername_ok(const char *printername)
    237257{
    238         pcap_cache_t *p;
     258        struct pcap_cache *p;
    239259
    240260        for (p = pcap_cache; p != NULL; p = p->next)
     
    246266
    247267/***************************************************************************
    248 run a function on each printer name in the printcap file. The function is
    249 passed the primary name and the comment (if possible). Note the fn() takes
    250 strings in DOS codepage. This means the xxx_printer_fn() calls must be fixed
    251 to return DOS codepage. FIXME !! JRA.
    252 
    253 XXX: I'm not sure if this comment still applies.. Anyone?  -Rob
     268run a function on each printer name in the printcap file.
    254269***************************************************************************/
    255 void pcap_printer_fn(void (*fn)(char *, char *))
    256 {
    257         pcap_cache_t *p;
    258 
    259         for (p = pcap_cache; p != NULL; p = p->next)
    260                 fn(p->name, p->comment);
     270
     271void pcap_printer_fn_specific(const struct pcap_cache *pc,
     272                        void (*fn)(const char *, const char *, void *),
     273                        void *pdata)
     274{
     275        const struct pcap_cache *p;
     276
     277        for (p = pc; p != NULL; p = p->next)
     278                fn(p->name, p->comment, pdata);
    261279
    262280        return;
    263281}
     282
     283void pcap_printer_fn(void (*fn)(const char *, const char *, void *), void *pdata)
     284{
     285        pcap_printer_fn_specific(pcap_cache, fn, pdata);
     286}
Note: See TracChangeset for help on using the changeset viewer.