summaryrefslogtreecommitdiff
path: root/src/poolvendor.c
blob: f621f50e37fb16daa61e872ff6af8941d5119b3f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
/*
 * Copyright (c) 2007, Novell Inc.
 *
 * This program is licensed under the BSD license, read LICENSE.BSD
 * for further information
 */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

/* we need FNM_CASEFOLD */
#ifndef _GNU_SOURCE
#define _GNU_SOURCE
#endif

#include <fnmatch.h>

#include "pool.h"
#include "poolid.h"
#include "poolvendor.h"
#include "util.h"

/*
 *  const char *vendorsclasses[] = {
 *    "!openSUSE Build Service*",
 *    "SUSE*",
 *    "openSUSE*",
 *    "SGI*",
 *    "Novell*",
 *    "Silicon Graphics*",
 *    "Jpackage Project*",
 *    "ATI Technologies Inc.*",
 *    "Nvidia*",
 *    0,
 *    0,
 *  };
 */

/* allows for 32 different vendor classes */

Id pool_vendor2mask(Pool *pool, Id vendor)
{
  const char *vstr;
  int i;
  Id mask, m;
  const char **v, *vs;

  if (vendor == 0 || !pool->vendorclasses)
    return 0;
  for (i = 0; i < pool->vendormap.count; i += 2)
    if (pool->vendormap.elements[i] == vendor)
      return pool->vendormap.elements[i + 1];
  vstr = pool_id2str(pool, vendor);
  m = 1;
  mask = 0;
  for (v = pool->vendorclasses; ; v++)
    {
      vs = *v;
      if (vs == 0)	/* end of block? */
	{
	  v++;
	  if (*v == 0)
	    break;
	  if (m == (1 << 31))
	    break;	/* sorry, out of bits */
	  m <<= 1;	/* next vendor equivalence class */
	}
      if (fnmatch(*vs == '!' ? vs + 1 : vs, vstr, FNM_CASEFOLD) == 0)
	{
	  if (*vs != '!')
	    mask |= m;
	  while (v[1])	/* forward to next block */
	    v++;
	}
    }
  queue_push(&pool->vendormap, vendor);
  queue_push(&pool->vendormap, mask);
  return mask;
}

void
pool_setvendorclasses(Pool *pool, const char **vendorclasses)
{
  int i;
  const char **v;

  if (pool->vendorclasses)
    {
      for (v = pool->vendorclasses; v[0] || v[1]; v++)
	solv_free((void *)*v);
      pool->vendorclasses = solv_free(pool->vendorclasses);
    }
  if (!vendorclasses || !vendorclasses[0])
    return;
  for (v = vendorclasses; v[0] || v[1]; v++)
    ;
  pool->vendorclasses = solv_calloc(v - vendorclasses + 2, sizeof(const char *));
  for (v = vendorclasses, i = 0; v[0] || v[1]; v++, i++)
    pool->vendorclasses[i] = *v ? strdup(*v) : 0;
  pool->vendorclasses[i++] = 0;
  pool->vendorclasses[i] = 0;
  queue_empty(&pool->vendormap);
}