FOSSology  3.2.0rc1
Open Source License Compliance by Open Source Software
libfossrepo.c
Go to the documentation of this file.
1 /************************************************************
2 libfossrepo: A set of functions for accessing the file repository.
3 
4 Copyright (C) 2007-2012 Hewlett-Packard Development Company, L.P.
5 
6 This library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Lesser General Public
8 License version 2.1 as published by the Free Software Foundation.
9 
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14 
15 You should have received a copy of the GNU Lesser General Public License
16 along with this library; if not, write to the Free Software Foundation, Inc.0
17 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 
19 ************************************************************/
20 
26 #include "libfossrepo.h"
27 #include "libfossscheduler.h"
28 #include "fossconfig.h"
29 
30 #include <sys/stat.h>
31 #include <glib.h>
32 
33 #ifndef FOSSREPO_CONF
34 #define FOSSREPO_CONF "/srv/fossology/repository"
35 #endif
36 #ifndef FOSSGROUP
37 #define FOSSGROUP "fossology"
38 #endif
39 
40 
41 #ifdef COMMIT_HASH
42 char LibraryRepoBuildVersion[]="Library libfossrepo Build version: " COMMIT_HASH ".\n";
43 #endif
44 
45 #define MAXHOSTNAMELEN 64
46 #define MAXLINE 1024
47 #define REPONAME "REPOSITORY"
48 
49 #define GROUP 0
50 
51 /*** Globals to simplify usage ***/
52 int RepDepth = 2;
53 char RepPath[MAXLINE + 1] = "";
54 #if GROUP
55 int RepGroup;
56 #endif
57 
58 #define REPCONFCHECK() { if (!*RepPath) fo_RepOpen(); }
59 
60 
73 int _RepCheckType(const char* S)
74 {
75  int i;
76  if (S == NULL) return (0);
77  for (i = 0; S[i] != '\0'; i++)
78  {
79  if (!isalnum(S[i]) && !strchr("@%_=+-", S[i])) return (0);
80  }
81  return (1);
82 } /* _RepCheckType() */
83 
95 int _RepCheckString(char* S)
96 {
97  int i;
98  if (S == NULL) return (0);
99  if (S[0] == '.') return (0);
100  for (i = 0; S[i] != '\0'; i++)
101  {
102  if (!isalnum(S[i]) && !strchr("@%_.=+-", S[i])) return (0);
103  }
104  return (1);
105 } /* _RepCheckString() */
106 
115 {
116  char* MyRepPath = NULL;
117 
118  REPCONFCHECK();
119 
120  /* allocate the path */
121  MyRepPath = (char*) calloc(strlen(RepPath) + 1, 1);
122  strcpy(MyRepPath, RepPath);
123  return (MyRepPath);
124 } /* fo_RepGetRepPath() */
125 
132 int fo_RepHostExist(char* Type, char* Host)
133 {
134  char* entry;
135  int i, length;
136  GError* error;
137 
138  REPCONFCHECK();
139  if (!_RepCheckType(Type)) return (-1);
140 
141  length = fo_config_list_length(sysconfig, "REPOSITORY", Host, &error);
142  if (error)
143  {
144  fprintf(stderr, "ERROR: %s\n", error->message);
145  return 0;
146  }
147 
148  for (i = 0; i < length; i++)
149  {
150  entry = fo_config_get_list(sysconfig, "REPOSITORY", Host, i, &error);
151  if (entry[0] == '*' || strncmp(Type, entry, strlen(Type)) == 0)
152  return 1;
153  }
154 
155  return 0;
156 } /* fo_RepHostExist() */
157 
170 char* _RepGetHost(const char* Type, char* Filename, int MatchNum)
171 {
172  char** hosts;
173  char* entry;
174  char* start;
175  char* end;
176  char* ret = NULL;
177  int Match = 0;
178  int i, j, kl, hl;
179  GError* error = NULL;
180 
181  REPCONFCHECK();
182  if (!_RepCheckType(Type) || !_RepCheckString(Filename))
183  return (NULL);
184 
185  hosts = fo_config_key_set(sysconfig, REPONAME, &kl);
186  for (i = 0; i < kl; i++)
187  {
188  hl = fo_config_list_length(sysconfig, REPONAME, hosts[i], &error);
189  for (j = 0; j < hl; j++)
190  {
191  entry = fo_config_get_list(sysconfig, REPONAME, hosts[i], j, &error);
192  char* remainder = NULL;
193  strtok_r(entry, " ", &remainder);
194  start = strtok_r(NULL, " ", &remainder);
195  end = strtok_r(NULL, " ", &remainder);
196 
197  if (strcmp(entry, "*") == 0 || strcmp(entry, Type) == 0)
198  {
199  if ((strncasecmp(start, Filename, strlen(start)) <= 0) &&
200  (strncasecmp(end, Filename, strlen(end)) >= 0))
201  {
202  Match++;
203  if (Match == MatchNum)
204  {
205  ret = (char*) calloc(strlen(hosts[i]) + 1, sizeof(char));
206  strcpy(ret, hosts[i]);
207  g_free(entry);
208  return ret;
209  }
210  }
211  }
212 
213  g_free(entry);
214  }
215  }
216 
217  return NULL;
218 } /* _RepGetHost() */
219 
233 char* fo_RepGetHost(char* Type, char* Filename)
234 {
235  return (_RepGetHost(Type, Filename, 1));
236 } /* fo_RepGetHost() */
237 
256 char* fo_RepMkPathTmp(const char* Type, char* Filename, char* Ext, int Which)
257 {
258  char* Path;
259  char* Host;
260  int Len = 0;
261  int i;
262  int FilenameLen;
263 
264  if (!_RepCheckType(Type) || !_RepCheckString(Filename)) return (NULL);
265 
266  /* get the hostname */
267  Host = _RepGetHost(Type, Filename, Which);
268  if (Host)
269  {Len += strlen(Host) + 1;}
270  if (!Host && (Which > 1))
271  {
272  free(Host);
273  return (NULL);
274  }
275  /* get the depth */
276  if (Type) Len += strlen(Type) + 1;
277  /* save the path too */
278  Len += strlen(RepPath) + 1;
279 
280  /* add in depth */
281  Len = Len + 3 * RepDepth;
282 
283  /* add in filename size */
284  FilenameLen = strlen(Filename);
285  Len += FilenameLen;
286  if (Ext) Len += 1 + strlen(Ext);
287 
288  /* create the name */
289  Path = (char*) calloc(Len + 1, 1);
290  Len = 0; /* now Len is size of string */
291  {
292  strcat(Path, RepPath);
293  strcat(Path, "/");
294  Len += strlen(RepPath) + 1;
295  }
296  if (Host)
297  {
298  strcat(Path, Host);
299  strcat(Path, "/");
300  Len += strlen(Host) + 1;
301  }
302  if (Type)
303  {
304  strcat(Path, Type);
305  strcat(Path, "/");
306  Len += strlen(Type) + 1;
307  }
308 
309  /* free memory */
310  if (Host) free(Host);
311 
312  /* check if the filename is too small */
313  if (FilenameLen < RepDepth * 2)
314  {
315  for (i = 0; i < FilenameLen; i++)
316  {
317  Path[Len++] = tolower(Filename[i]);
318  if (i % 2 == 1) Path[Len++] = '/';
319  }
320  for (; i < RepDepth * 2; i++)
321  {
322  Path[Len++] = '_';
323  if (i % 2 == 1) Path[Len++] = '/';
324  }
325  }
326  else
327  {
328  /* add the filename */
329  for (i = 0; i < RepDepth; i++)
330  {
331  Path[Len] = tolower(Filename[i * 2]);
332  Path[Len + 1] = tolower(Filename[i * 2 + 1]);
333  Path[Len + 2] = '/';
334  Len += 3;
335  }
336  }
337 
338  for (i = 0; Filename[i] != '\0'; i++)
339  {
340  Path[Len] = tolower(Filename[i]);
341  Len++;
342  }
343 
344  if (Ext)
345  {
346  strcat(Path, ".");
347  strcat(Path, Ext);
348  Len += strlen(Type) + 1;
349  }
350  return (Path);
351 } /* fo_RepMkPathTmp() */
352 
364 char* fo_RepMkPath(const char* Type, char* Filename)
365 {
366  char* Path, * AltPath;
367  int i;
368  struct stat Stat;
369 
370  Path = fo_RepMkPathTmp(Type, Filename, NULL, 1);
371  if (!Path) return (NULL);
372  /* if something exists, then return it! */
373  if (!stat(Path, &Stat))
374  {return (Path);}
375 
376  /* Check if it exists in an alternate path */
377  i = 2;
378  while (1)
379  {
380  AltPath = fo_RepMkPathTmp(Type, Filename, NULL, i);
381  if (!AltPath) return (Path); /* No alternate */
382  /* If there is an alternate, return it. */
383  if (!stat(AltPath, &Stat))
384  {
385  free(Path);
386  return (AltPath);
387  }
388  i++;
389  }
390 
391  /* should never get here */
392  return (Path);
393 } /* fo_RepMkPath() */
394 
406 void _RepUpdateTime(char* File)
407 {
408  struct utimbuf Utime;
409  Utime.actime = Utime.modtime = time(NULL);
410  utime(File, &Utime);
411 } /* _RepUpdateTime() */
412 
420 int _RepMkDirs(char* Fname)
421 {
422  char Dir[FILENAME_MAX + 1];
423  int i;
424  int rc = 0;
425  mode_t Mask;
426 #if GROUP
427  gid_t Gid;
428 #endif
429 
430  memset(Dir, '\0', sizeof(Dir));
431  strcpy(Dir, Fname);
432  for (i = 1; Dir[i] != '\0'; i++)
433  {
434  if (Dir[i] == '/')
435  {
436  Dir[i] = '\0';
437  Mask = umask(0000); /* mode: 0777 */
438 #if GROUP
439  Gid = getegid();
440  setegid(RepGroup);
441 #endif
442  rc = mkdir(Dir, 0770); /* create this path segment */
443 #if GROUP
444  setegid(Gid);
445 #endif
446  umask(Mask);
447  if (rc && (errno == EEXIST)) rc = 0;
448  Dir[i] = '/';
449  if (rc)
450  {
451  fprintf(stderr, "FATAL: 'mkdir %s' failed with rc=%d\n", Dir, rc);
452  return (rc);
453  }
454  }
455  }
456  return (rc);
457 } /* _RepMkDirs() */
458 
466 int fo_RepRenameTmp(char* Type, char* Filename, char* Ext)
467 {
468  char* FnameOld, * Fname;
469  int rc;
470 
471  FnameOld = fo_RepMkPathTmp(Type, Filename, Ext, 1);
472  Fname = fo_RepMkPath(Type, Filename);
473  if (!FnameOld || !Fname)
474  {
475  fprintf(stderr, "ERROR: Bad repository name: type='%s' name='%s'\n",
476  Type, Filename);
477  return (-1);
478  }
479  rc = rename(FnameOld, Fname);
480  free(FnameOld);
481  free(Fname);
482  return (rc);
483 } /* fo_RepRenameTmp() */
484 
498 int fo_RepExist(char* Type, char* Filename)
499 {
500  char* Fname;
501  struct stat Stat;
502  int rc = 0;
503 
504  if (!_RepCheckType(Type))
505  {
506  fprintf(stderr, "ERROR: Invalid type '%s'\n", Type);
507  return (-1);
508  }
509  if (!_RepCheckString(Filename))
510  {
511  fprintf(stderr, "ERROR: Invalid filename '%s'\n", Filename);
512  return (-1);
513  }
514 
515  Fname = fo_RepMkPath(Type, Filename);
516  if (!Fname)
517  {
518  fprintf(stderr, "ERROR: Unable to allocate path for '%s/%s'\n", Type, Filename);
519  return (-1);
520  }
521  if (!stat(Fname, &Stat)) rc = 1;
522  free(Fname);
523  return (rc);
524 } /* fo_RepExist() */
525 
543 int fo_RepExist2(char* Type, char* Filename)
544 {
545  char* Fname;
546  struct stat Stat;
547  int rc = 0;
548 
549  if (!_RepCheckType(Type))
550  {
551  fprintf(stderr, "ERROR: Invalid type '%s'\n", Type);
552  return (-1);
553  }
554  if (!_RepCheckString(Filename))
555  {
556  fprintf(stderr, "ERROR: Invalid filename '%s'\n", Filename);
557  return (-1);
558  }
559 
560  Fname = fo_RepMkPath(Type, Filename);
561  if (!Fname)
562  {
563  fprintf(stderr, "ERROR: Unable to allocate path for '%s/%s'\n", Type, Filename);
564  return (-1);
565  }
566  if (stat(Fname, &Stat)) rc = errno;
567  free(Fname);
568  return (rc);
569 } /* fo_RepExist2() */
570 
580 int fo_RepRemove(char* Type, char* Filename)
581 {
582  char* Fname;
583  struct stat Stat;
584  int rc = 0;
585 
586  if (!_RepCheckType(Type))
587  {
588  fprintf(stderr, "ERROR: Invalid type '%s'\n", Type);
589  return (0);
590  }
591  if (!_RepCheckString(Filename))
592  {
593  fprintf(stderr, "ERROR: Invalid filename '%s'\n", Filename);
594  return (0);
595  }
596 
597  Fname = fo_RepMkPath(Type, Filename);
598  if (!Fname)
599  {
600  fprintf(stderr, "ERROR: Unable to allocate path for '%s/%s'\n", Type, Filename);
601  return (0);
602  }
603  if (!stat(Fname, &Stat)) rc = unlink(Fname);
604  free(Fname);
605  return (rc);
606 } /* fo_RepRemove() */
607 
613 int fo_RepFclose(FILE* F)
614 {
615  if (!F) return (0);
616  return (fclose(F));
617 } /* fo_RepFclose() */
618 
625 FILE* fo_RepFread(char* Type, char* Filename)
626 {
627  FILE* F = NULL;
628  char* Fname;
629 
630  if (!_RepCheckType(Type))
631  {
632  fprintf(stderr, "ERROR: Invalid type '%s'\n", Type);
633  return (NULL);
634  }
635  if (!_RepCheckString(Filename))
636  {
637  fprintf(stderr, "ERROR: Invalid filename '%s'\n", Filename);
638  return (NULL);
639  }
640 
641  Fname = fo_RepMkPath(Type, Filename);
642  if (!Fname)
643  {
644  fprintf(stderr, "ERROR: Unable to allocate path for '%s/%s'\n", Type, Filename);
645  return (NULL);
646  }
647  _RepUpdateTime(Fname);
648  F = fopen(Fname, "rb");
649  free(Fname);
650  return (F);
651 } /* fo_RepFread() */
652 
660 FILE* fo_RepFwriteTmp(char* Type, char* Filename, char* Ext)
661 {
662  FILE* F = NULL;
663  char* Fname;
664  mode_t Mask;
665 #if GROUP
666  gid_t Gid;
667 #endif
668 
669  if (!_RepCheckType(Type))
670  {
671  fprintf(stderr, "ERROR: Invalid type '%s'\n", Type);
672  return (NULL);
673  }
674  if (!_RepCheckString(Filename))
675  {
676  fprintf(stderr, "ERROR: Invalid filename '%s'\n", Filename);
677  return (NULL);
678  }
679 
680  Fname = fo_RepMkPathTmp(Type, Filename, Ext, 1);
681  if (!Fname)
682  {
683  fprintf(stderr, "ERROR: Unable to allocate path for '%s/%s'\n", Type, Filename);
684  return (NULL);
685  }
686  if (_RepMkDirs(Fname))
687  {
688  free(Fname);
689  return (NULL);
690  }
691  _RepUpdateTime(Fname);
692  Mask = umask(0117); /* mode: 0660 */
693 #if GROUP
694  Gid = getegid();
695  setegid(RepGroup);
696 #endif
697  F = fopen(Fname, "wb");
698  if (!F)
699  {
700  fprintf(stderr, "ERROR: %s, in %s:%d, failed to open [%s]\n",
701  strerror(errno), __FILE__, __LINE__, Fname);
702  free(Fname);
703  return (NULL);
704  }
705  chmod(Fname, S_ISGID | S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP); /* when umask fails */
706 #if GROUP
707  setegid(Gid);
708 #endif
709  umask(Mask);
710  free(Fname);
711  return (F);
712 } /* fo_RepFwriteTmp() */
713 
722 FILE* fo_RepFwrite(char* Type, char* Filename)
723 {
724  return (fo_RepFwriteTmp(Type, Filename, NULL));
725 } /* fo_RepFwrite() */
726 
734 {
735  if (!M) return;
736  if (M->_MmapSize > 0) munmap(M->Mmap, M->_MmapSize);
737  close(M->FileHandle);
738  free(M);
739 } /* fo_RepMunmap() */
740 
747 {
748  RepMmapStruct* M;
749  struct stat Stat;
750  int PageSize;
751 
752  M = (RepMmapStruct*) calloc(1, sizeof(RepMmapStruct));
753  if (!M)
754  {return (NULL);}
755 
756  /* open the file (memory map) */
757  M->FileHandle = open(Fname, O_RDONLY);
758  if (M->FileHandle == -1)
759  {
760  fprintf(stderr, "ERROR: Unable to open file for mmap (%s)\n", Fname);
761  free(M);
762  return (NULL);
763  }
764 
765  /* find how big the file is (to allocate it) */
766  if (fstat(M->FileHandle, &Stat) == -1)
767  {
768  fprintf(stderr, "ERROR: Unable to stat file (%s)\n", Fname);
769  close(M->FileHandle);
770  free(M);
771  return (NULL);
772  }
773  PageSize = getpagesize();
774 
775  /* only mmap the first 1G */
776  if (Stat.st_size > 0x7fffffff) Stat.st_size = 0x80000000;
777 
778  M->MmapSize = Stat.st_size;
779  M->_MmapSize = M->MmapSize + PageSize - (M->MmapSize % PageSize);
780  M->Mmap = mmap(0, M->_MmapSize, PROT_READ, MAP_PRIVATE, M->FileHandle, 0);
781  if (M->Mmap == MAP_FAILED)
782  {
783  fprintf(stderr, "ERROR: Unable to mmap file (%s)\n", Fname);
784  close(M->FileHandle);
785  free(M);
786  return (NULL);
787  }
788  return (M);
789 } /* fo_RepMmapFile() */
790 
798 RepMmapStruct* fo_RepMmap(char* Type, char* Filename)
799 {
800  RepMmapStruct* M;
801  char* Fname;
802 
803  if (!_RepCheckType(Type) || !_RepCheckString(Filename)) return (NULL);
804 
805  Fname = fo_RepMkPath(Type, Filename);
806  if (!Fname) return (NULL);
807  _RepUpdateTime(Fname);
808 
809  M = fo_RepMmapFile(Fname);
810  free(Fname);
811  return (M);
812 } /* fo_RepMmap() */
813 
824 int fo_RepImport(char* Source, char* Type, char* Filename, int Link)
825 {
826  if (0 == strcmp(Type, "files"))
827  {
828  chmod(Source, S_ISGID | S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH); /* change mode */
829  }
830  /*** code uses read/write ***/
831  /*** Could use mmap, but it isn't noticably faster and could have
832  problems with multi-gig files ***/
833  int LenIn, LenOut;
834  int i;
835  char Buf[0x80000]; /* 80K blocks */
836  char vBuf[0x80000]; /* 80K blocks */
837  FILE* Fin;
838  FILE* Fout;
839  char* FoutPath;
840 
841  /* easy route: make a hard link */
842  if (Link)
843  {
844  FoutPath = fo_RepMkPath(Type, Filename);
845  if (!FoutPath) return (0);
846  if (_RepMkDirs(FoutPath)) /* make the directory */
847  {
848  free(FoutPath);
849  return (1);
850  }
851  if (link(Source, FoutPath) == 0)
852  {
853  free(FoutPath);
854  return (0);
855  }
856  free(FoutPath);
857  } /* try a hard link */
858 
859  /* hard route: actually copy the file */
860  Fin = fopen(Source, "rb");
861  if (!Fin)
862  {
863  fprintf(stderr, "ERROR: Unable to open source file '%s'\n", Source);
864  return (1);
865  }
866  setvbuf(Fin, vBuf, _IOFBF, sizeof(vBuf));
867 
868  Fout = fo_RepFwriteTmp(Type, Filename, "I"); /* tmp = ".I" for importing... */
869  if (!Fout)
870  {
871  fprintf(stderr, "ERROR: Invalid -- type='%s' filename='%s'\n", Type, Filename);
872  fclose(Fin);
873  return (2);
874  }
875 
876  LenIn = fread(Buf,1,sizeof(Buf),Fin);
877  while(LenIn > 0)
878  {
879  LenOut=0;
880  while(LenOut < LenIn)
881  {
882  i = fwrite(Buf+LenOut,1,LenIn - LenOut,Fout);
883  LenOut += i;
884  if (i == 0)
885  {
886  /*** Oh no! Write failed! ***/
887  fclose(Fout);
888  fo_RepFclose(Fout);
889  fo_RepRemove(Type,Filename);
890  fprintf(stderr,"ERROR: Write failed -- type='%s' filename='%s'\n",Type,Filename);
891  fclose(Fin);
892  return(3);
893  }
894  }
895  LenIn = fread(Buf,1,sizeof(Buf),Fin);
896  }
897  fo_RepFclose(Fout);
898  fclose(Fin);
899  fo_RepRenameTmp(Type, Filename, "I"); /* mv .I to real name */
900  return (0);
901 } /* fo_RepImport() */
902 
907 {
908  RepDepth = 2; /* default depth */
909  memset(RepPath, '\0', sizeof(RepPath));
910  RepPath[0] = '.'; /* default to local directory */
911 } /* fo_RepClose() */
912 
921 {
922  return fo_RepOpenFull(sysconfig);
923 }
924 
933 {
934  GError* error = NULL;
935  char* path;
936 
937 #if GROUP
938  struct group *Group;
939  gid_t Gid;
940 #endif
941 
942  fo_RepClose(); /* reset everything */
943 
944 #if GROUP
945  /* Make sure we can use group */
946  Group = getgrnam(FOSSGROUP);
947  if (!Group) return(0); /* no such group */
948  RepGroup = Group->gr_gid;
949  Gid = getegid();
950  if ((Gid != RepGroup) && setegid(RepGroup))
951  {
952  perror("Huh?");
953  return(0);
954  }
955  setegid(Gid);
956 #endif
957 
958  /* Load the depth configuration */
959  char* repDepthStr = fo_config_get(config, "FOSSOLOGY", "depth", &error);
960  if (error)
961  {
962  fprintf(stderr, "ERROR %s.%d: %s\n", __FILE__, __LINE__, error->message);
963  return 0;
964  }
965  RepDepth = atoi(repDepthStr);
966 
967  /* Load the path configuration */
968  path = fo_config_get(config, "FOSSOLOGY", "path", &error);
969  if (error)
970  {
971  fprintf(stderr, "ERROR %s.%d: %s\n", __FILE__, __LINE__, error->message);
972  return 0;
973  }
974  strncpy(RepPath, path, sizeof(RepPath)-1);
975  RepPath[sizeof(RepPath)-1] = 0;
976 
977  return 1;
978 } /* fo_RepOpen() */
979 
989 char* fo_RepValidate(fo_conf* config)
990 {
991  char* retval = NULL;
992  int32_t nhosts, nlist, i, j;
993  char* gname = "REPOSITORY";
994  char** hosts;
995  char* curr;
996  GRegex* regex = NULL;
997  GMatchInfo* match = NULL;
998  uint32_t begin, end;
999  gchar* begin_str;
1000  gchar* end_str;
1001 
1002 
1003  if ((hosts = fo_config_key_set(config, gname, &nhosts)) == NULL)
1004  return g_strdup("The fossology.conf file does not contain a \"REPOSITORY\" group.");
1005 
1006  /* Regex to match repository lines in the configuration file.
1007  *
1008  * This will match a file type followed by two hexidecimal numbers. Possible
1009  * file types are gold, files, logs, license, test, and all type (denoted by
1010  * a *).
1011  *
1012  * example match:
1013  * * 00 ff
1014  */
1015  regex = g_regex_new(
1016  "(\\*|gold|files|logs|license|test)\\s+([[:xdigit:]]+)\\s+([[:xdigit:]]+)$",
1017  0, 0, NULL);
1018 
1019  for (i = 0; i < nhosts; i++)
1020  {
1021  nlist = fo_config_list_length(config, gname, hosts[i], NULL);
1022 
1023  for (j = 0; j < nlist; j++)
1024  {
1025  curr = fo_config_get_list(config, gname, hosts[i], j, NULL);
1026 
1027  if (!g_regex_match(regex, curr, 0, &match))
1028  {
1029  retval = g_strdup_printf("%s[] = %s", hosts[i], curr);
1030  break;
1031  }
1032 
1033  begin_str = g_match_info_fetch(match, 2);
1034  end_str = g_match_info_fetch(match, 3);
1035 
1036  begin = strtoul(begin_str, NULL, 16);
1037  end = strtoul(end_str, NULL, 16);
1038 
1039  if (begin >= end)
1040  {
1041  retval = g_strdup_printf("%s[] = %s", hosts[i], curr);
1042  break;
1043  }
1044 
1045  g_free(begin_str);
1046  g_free(end_str);
1047  g_match_info_free(match);
1048  }
1049  }
1050 
1051  g_regex_unref(regex);
1052  return retval;
1053 } /* fo_RepValidate() */
1054 
Definition: match.h:31
FOSSology library to read config file.
FILE * fo_RepFwrite(char *Type, char *Filename)
Perform an fwrite. Also creates directories.
Definition: libfossrepo.c:722
RepMmapStruct * fo_RepMmap(char *Type, char *Filename)
Perform a mmap.
Definition: libfossrepo.c:798
fo_conf * sysconfig
Store the results of a regex match.
Definition: scanners.hpp:39
void _RepUpdateTime(char *File)
Update the last modified time of a file.
Definition: libfossrepo.c:406
uint32_t MmapSize
Size of file mmap.
Definition: libfossrepo.h:104
Definition: monk.h:72
int fo_RepHostExist(char *Type, char *Host)
Determine if a host exists.
Definition: libfossrepo.c:132
#define MAXLINE
Max length of a line.
Definition: libfossrepo.c:46
char * fo_RepGetRepPath()
Determine the path for the repository&#39;s root.
Definition: libfossrepo.c:114
char * fo_RepMkPathTmp(const char *Type, char *Filename, char *Ext, int Which)
Given a filename, construct the full path to the file.
Definition: libfossrepo.c:256
char * fo_RepValidate(fo_conf *config)
validates the repository configuration information.
Definition: libfossrepo.c:989
char * fo_config_get(fo_conf *conf, const char *group, const char *key, GError **error)
Gets an element based on its group name and key name. If the group or key is not found, the error object is set and NULL is returned.
Definition: fossconfig.c:341
FILE * fo_RepFread(char *Type, char *Filename)
Perform an fopen for reading only.
Definition: libfossrepo.c:625
char * fo_RepGetHost(char *Type, char *Filename)
Determine the host for a filename.
Definition: libfossrepo.c:233
int fo_RepFclose(FILE *F)
Perform an fclose.
Definition: libfossrepo.c:613
int _RepCheckType(const char *S)
Simple check to see if the string S is valid filename.
Definition: libfossrepo.c:73
start($application)
start the application Assumes application is restartable via /etc/init.d/<script>. The application passed in should match the script name in /etc/init.d
Definition: pkgConfig.php:1225
RepPath($PfilePk, $Repo="files")
Given a pfile id, retrieve the pfile path.
Definition: common-repo.php:69
uint32_t _MmapSize
Real size of mmap (set to page boundary)
Definition: libfossrepo.h:105
RepMmapStruct * fo_RepMmapFile(char *Fname)
Perform a mmap on a regular file name.
Definition: libfossrepo.c:746
FILE * fo_RepFwriteTmp(char *Type, char *Filename, char *Ext)
Perform an fwrite. Also creates directories.
Definition: libfossrepo.c:660
int FileHandle
Handle from open()
Definition: libfossrepo.h:102
#define REPONAME
Default repo name.
Definition: libfossrepo.c:47
int _RepMkDirs(char *Fname)
Same as command-line "mkdir -p".
Definition: libfossrepo.c:420
char * fo_config_get_list(fo_conf *conf, char *group, char *key, int idx, GError **error)
Definition: fossconfig.c:387
int fo_config_list_length(fo_conf *conf, char *group, char *key, GError **error)
Gets the length of the list associated with a particular list key.
Definition: fossconfig.c:480
int fo_RepOpenFull(fo_conf *config)
Loads common information from configuration files into ram.
Definition: libfossrepo.c:932
unsigned char * Mmap
Memory pointer from mmap.
Definition: libfossrepo.h:103
char * fo_RepMkPath(const char *Type, char *Filename)
Given a filename, construct the full path to the file.
Definition: libfossrepo.c:364
void fo_RepMunmap(RepMmapStruct *M)
Perform a munmap.
Definition: libfossrepo.c:733
char ** fo_config_key_set(fo_conf *conf, char *group, int *length)
Gets the set of key names for a particular group.
Definition: fossconfig.c:619
int fo_RepExist2(char *Type, char *Filename)
Determine if a file exists.
Definition: libfossrepo.c:543
char * _RepGetHost(const char *Type, char *Filename, int MatchNum)
Determine the host for the tree.
Definition: libfossrepo.c:170
int fo_RepOpen()
wrapper function for agents. Simply call fo_RepOpenFull() passing in the default system configuration...
Definition: libfossrepo.c:920
void fo_RepClose()
Close and unmap the repository configuration file.
Definition: libfossrepo.c:906
int fo_RepImport(char *Source, char *Type, char *Filename, int Link)
Import a file into the repository.
Definition: libfossrepo.c:824
char * Filename
Filename.
Definition: run_tests.c:28
int fo_RepRenameTmp(char *Type, char *Filename, char *Ext)
Rename a temp file to a real file.
Definition: libfossrepo.c:466
int _RepCheckString(char *S)
Simple check to see if the string is valid.
Definition: libfossrepo.c:95
int fo_RepRemove(char *Type, char *Filename)
Delete a repository file.
Definition: libfossrepo.c:580
int fo_RepExist(char *Type, char *Filename)
Determine if a file exists.
Definition: libfossrepo.c:498