FOSSology  4.4.0
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  SPDX-FileCopyrightText: © 2007-2012 Hewlett-Packard Development Company, L.P.
5 
6  SPDX-License-Identifier: LGPL-2.1-only
7 */
8 
14 #include "libfossrepo.h"
15 #include "libfossscheduler.h"
16 #include "fossconfig.h"
17 
18 #include <sys/stat.h>
19 #include <glib.h>
20 
21 #ifndef FOSSREPO_CONF
22 #define FOSSREPO_CONF "/srv/fossology/repository"
23 #endif
24 #ifndef FOSSGROUP
25 #define FOSSGROUP "fossology"
26 #endif
27 
28 
29 #ifdef COMMIT_HASH
30 char LibraryRepoBuildVersion[]="Library libfossrepo Build version: " COMMIT_HASH ".\n";
31 #endif
32 
33 #define MAXHOSTNAMELEN 64
34 #define MAXLINE 1024
35 #define REPONAME "REPOSITORY"
36 
37 #define GROUP 0
38 
39 /*** Globals to simplify usage ***/
40 int RepDepth = 2;
41 char RepPath[MAXLINE + 1] = "";
42 #if GROUP
43 int RepGroup;
44 #endif
45 
46 #define REPCONFCHECK() { if (!*RepPath) fo_RepOpen(); }
47 
48 
61 int _RepCheckType(const char* S)
62 {
63  int i;
64  if (S == NULL) return (0);
65  for (i = 0; S[i] != '\0'; i++)
66  {
67  if (!isalnum(S[i]) && !strchr("@%_=+-", S[i])) return (0);
68  }
69  return (1);
70 } /* _RepCheckType() */
71 
83 int _RepCheckString(char* S)
84 {
85  int i;
86  if (S == NULL) return (0);
87  if (S[0] == '.') return (0);
88  for (i = 0; S[i] != '\0'; i++)
89  {
90  if (!isalnum(S[i]) && !strchr("@%_.=+-", S[i])) return (0);
91  }
92  return (1);
93 } /* _RepCheckString() */
94 
103 {
104  char* MyRepPath = NULL;
105 
106  REPCONFCHECK();
107 
108  /* allocate the path */
109  MyRepPath = (char*) calloc(strlen(RepPath) + 1, 1);
110  strcpy(MyRepPath, RepPath);
111  return (MyRepPath);
112 } /* fo_RepGetRepPath() */
113 
120 int fo_RepHostExist(char* Type, char* Host)
121 {
122  char* entry;
123  int i, length;
124  GError* error;
125 
126  REPCONFCHECK();
127  if (!_RepCheckType(Type)) return (-1);
128 
129  length = fo_config_list_length(sysconfig, "REPOSITORY", Host, &error);
130  if (error)
131  {
132  fprintf(stderr, "ERROR: %s\n", error->message);
133  return 0;
134  }
135 
136  for (i = 0; i < length; i++)
137  {
138  entry = fo_config_get_list(sysconfig, "REPOSITORY", Host, i, &error);
139  if (entry[0] == '*' || strncmp(Type, entry, strlen(Type)) == 0)
140  return 1;
141  }
142 
143  return 0;
144 } /* fo_RepHostExist() */
145 
158 char* _RepGetHost(const char* Type, char* Filename, int MatchNum)
159 {
160  char** hosts;
161  char* entry;
162  char* start;
163  char* end;
164  char* ret = NULL;
165  int Match = 0;
166  int i, j, kl, hl;
167  GError* error = NULL;
168 
169  REPCONFCHECK();
170  if (!_RepCheckType(Type) || !_RepCheckString(Filename))
171  return (NULL);
172 
173  hosts = fo_config_key_set(sysconfig, REPONAME, &kl);
174  for (i = 0; i < kl; i++)
175  {
176  hl = fo_config_list_length(sysconfig, REPONAME, hosts[i], &error);
177  for (j = 0; j < hl; j++)
178  {
179  entry = fo_config_get_list(sysconfig, REPONAME, hosts[i], j, &error);
180  char* remainder = NULL;
181  strtok_r(entry, " ", &remainder);
182  start = strtok_r(NULL, " ", &remainder);
183  end = strtok_r(NULL, " ", &remainder);
184 
185  if (strcmp(entry, "*") == 0 || strcmp(entry, Type) == 0)
186  {
187  if ((strncasecmp(start, Filename, strlen(start)) <= 0) &&
188  (strncasecmp(end, Filename, strlen(end)) >= 0))
189  {
190  Match++;
191  if (Match == MatchNum)
192  {
193  ret = (char*) calloc(strlen(hosts[i]) + 1, sizeof(char));
194  strcpy(ret, hosts[i]);
195  g_free(entry);
196  return ret;
197  }
198  }
199  }
200 
201  g_free(entry);
202  }
203  }
204 
205  return NULL;
206 } /* _RepGetHost() */
207 
221 char* fo_RepGetHost(char* Type, char* Filename)
222 {
223  return (_RepGetHost(Type, Filename, 1));
224 } /* fo_RepGetHost() */
225 
244 char* fo_RepMkPathTmp(const char* Type, char* Filename, char* Ext, int Which)
245 {
246  char* Path;
247  char* Host;
248  int Len = 0;
249  int i;
250  int FilenameLen;
251 
252  if (!_RepCheckType(Type) || !_RepCheckString(Filename)) return (NULL);
253 
254  /* get the hostname */
255  Host = _RepGetHost(Type, Filename, Which);
256  if (Host)
257  {Len += strlen(Host) + 1;}
258  if (!Host && (Which > 1))
259  {
260  free(Host);
261  return (NULL);
262  }
263  /* get the depth */
264  if (Type) Len += strlen(Type) + 1;
265  /* save the path too */
266  Len += strlen(RepPath) + 1;
267 
268  /* add in depth */
269  Len = Len + 3 * RepDepth;
270 
271  /* add in filename size */
272  FilenameLen = strlen(Filename);
273  Len += FilenameLen;
274  if (Ext) Len += 1 + strlen(Ext);
275 
276  /* create the name */
277  Path = (char*) calloc(Len + 1, 1);
278  Len = 0; /* now Len is size of string */
279  {
280  strcat(Path, RepPath);
281  strcat(Path, "/");
282  Len += strlen(RepPath) + 1;
283  }
284  if (Host)
285  {
286  strcat(Path, Host);
287  strcat(Path, "/");
288  Len += strlen(Host) + 1;
289  }
290  if (Type)
291  {
292  strcat(Path, Type);
293  strcat(Path, "/");
294  Len += strlen(Type) + 1;
295  }
296 
297  /* free memory */
298  if (Host) free(Host);
299 
300  /* check if the filename is too small */
301  if (FilenameLen < RepDepth * 2)
302  {
303  for (i = 0; i < FilenameLen; i++)
304  {
305  Path[Len++] = tolower(Filename[i]);
306  if (i % 2 == 1) Path[Len++] = '/';
307  }
308  for (; i < RepDepth * 2; i++)
309  {
310  Path[Len++] = '_';
311  if (i % 2 == 1) Path[Len++] = '/';
312  }
313  }
314  else
315  {
316  /* add the filename */
317  for (i = 0; i < RepDepth; i++)
318  {
319  Path[Len] = tolower(Filename[i * 2]);
320  Path[Len + 1] = tolower(Filename[i * 2 + 1]);
321  Path[Len + 2] = '/';
322  Len += 3;
323  }
324  }
325 
326  for (i = 0; Filename[i] != '\0'; i++)
327  {
328  Path[Len] = tolower(Filename[i]);
329  Len++;
330  }
331 
332  if (Ext)
333  {
334  strcat(Path, ".");
335  strcat(Path, Ext);
336  Len += strlen(Type) + 1;
337  }
338  return (Path);
339 } /* fo_RepMkPathTmp() */
340 
352 char* fo_RepMkPath(const char* Type, char* Filename)
353 {
354  char* Path, * AltPath;
355  int i;
356  struct stat Stat;
357 
358  Path = fo_RepMkPathTmp(Type, Filename, NULL, 1);
359  if (!Path) return (NULL);
360  /* if something exists, then return it! */
361  if (!stat(Path, &Stat))
362  {return (Path);}
363 
364  /* Check if it exists in an alternate path */
365  i = 2;
366  while (1)
367  {
368  AltPath = fo_RepMkPathTmp(Type, Filename, NULL, i);
369  if (!AltPath) return (Path); /* No alternate */
370  /* If there is an alternate, return it. */
371  if (!stat(AltPath, &Stat))
372  {
373  free(Path);
374  return (AltPath);
375  }
376  i++;
377  }
378 
379  /* should never get here */
380  return (Path);
381 } /* fo_RepMkPath() */
382 
394 void _RepUpdateTime(char* File)
395 {
396  struct utimbuf Utime;
397  Utime.actime = Utime.modtime = time(NULL);
398  utime(File, &Utime);
399 } /* _RepUpdateTime() */
400 
408 int _RepMkDirs(char* Fname)
409 {
410  char Dir[FILENAME_MAX + 1];
411  int i;
412  int rc = 0;
413  mode_t Mask;
414 #if GROUP
415  gid_t Gid;
416 #endif
417 
418  memset(Dir, '\0', sizeof(Dir));
419  strcpy(Dir, Fname);
420  for (i = 1; Dir[i] != '\0'; i++)
421  {
422  if (Dir[i] == '/')
423  {
424  Dir[i] = '\0';
425  Mask = umask(0000); /* mode: 0777 */
426 #if GROUP
427  Gid = getegid();
428  setegid(RepGroup);
429 #endif
430  rc = mkdir(Dir, 0770); /* create this path segment */
431 #if GROUP
432  setegid(Gid);
433 #endif
434  umask(Mask);
435  if (rc && (errno == EEXIST)) rc = 0;
436  Dir[i] = '/';
437  if (rc)
438  {
439  fprintf(stderr, "FATAL: 'mkdir %s' failed with rc=%d\n", Dir, rc);
440  return (rc);
441  }
442  }
443  }
444  return (rc);
445 } /* _RepMkDirs() */
446 
454 int fo_RepRenameTmp(char* Type, char* Filename, char* Ext)
455 {
456  char* FnameOld, * Fname;
457  int rc;
458 
459  FnameOld = fo_RepMkPathTmp(Type, Filename, Ext, 1);
460  Fname = fo_RepMkPath(Type, Filename);
461  if (!FnameOld || !Fname)
462  {
463  fprintf(stderr, "ERROR: Bad repository name: type='%s' name='%s'\n",
464  Type, Filename);
465  return (-1);
466  }
467  rc = rename(FnameOld, Fname);
468  free(FnameOld);
469  free(Fname);
470  return (rc);
471 } /* fo_RepRenameTmp() */
472 
486 int fo_RepExist(char* Type, char* Filename)
487 {
488  char* Fname;
489  struct stat Stat;
490  int rc = 0;
491 
492  if (!_RepCheckType(Type))
493  {
494  fprintf(stderr, "ERROR: Invalid type '%s'\n", Type);
495  return (-1);
496  }
498  {
499  fprintf(stderr, "ERROR: Invalid filename '%s'\n", Filename);
500  return (-1);
501  }
502 
503  Fname = fo_RepMkPath(Type, Filename);
504  if (!Fname)
505  {
506  fprintf(stderr, "ERROR: Unable to allocate path for '%s/%s'\n", Type, Filename);
507  return (-1);
508  }
509  if (!stat(Fname, &Stat)) rc = 1;
510  free(Fname);
511  return (rc);
512 } /* fo_RepExist() */
513 
531 int fo_RepExist2(char* Type, char* Filename)
532 {
533  char* Fname;
534  struct stat Stat;
535  int rc = 0;
536 
537  if (!_RepCheckType(Type))
538  {
539  fprintf(stderr, "ERROR: Invalid type '%s'\n", Type);
540  return (-1);
541  }
543  {
544  fprintf(stderr, "ERROR: Invalid filename '%s'\n", Filename);
545  return (-1);
546  }
547 
548  Fname = fo_RepMkPath(Type, Filename);
549  if (!Fname)
550  {
551  fprintf(stderr, "ERROR: Unable to allocate path for '%s/%s'\n", Type, Filename);
552  return (-1);
553  }
554  if (stat(Fname, &Stat)) rc = errno;
555  free(Fname);
556  return (rc);
557 } /* fo_RepExist2() */
558 
568 int fo_RepRemove(char* Type, char* Filename)
569 {
570  char* Fname;
571  struct stat Stat;
572  int rc = 0;
573 
574  if (!_RepCheckType(Type))
575  {
576  fprintf(stderr, "ERROR: Invalid type '%s'\n", Type);
577  return (0);
578  }
580  {
581  fprintf(stderr, "ERROR: Invalid filename '%s'\n", Filename);
582  return (0);
583  }
584 
585  Fname = fo_RepMkPath(Type, Filename);
586  if (!Fname)
587  {
588  fprintf(stderr, "ERROR: Unable to allocate path for '%s/%s'\n", Type, Filename);
589  return (0);
590  }
591  if (!stat(Fname, &Stat)) rc = unlink(Fname);
592  free(Fname);
593  return (rc);
594 } /* fo_RepRemove() */
595 
601 int fo_RepFclose(FILE* F)
602 {
603  if (!F) return (0);
604  return (fclose(F));
605 } /* fo_RepFclose() */
606 
613 FILE* fo_RepFread(char* Type, char* Filename)
614 {
615  FILE* F = NULL;
616  char* Fname;
617 
618  if (!_RepCheckType(Type))
619  {
620  fprintf(stderr, "ERROR: Invalid type '%s'\n", Type);
621  return (NULL);
622  }
624  {
625  fprintf(stderr, "ERROR: Invalid filename '%s'\n", Filename);
626  return (NULL);
627  }
628 
629  Fname = fo_RepMkPath(Type, Filename);
630  if (!Fname)
631  {
632  fprintf(stderr, "ERROR: Unable to allocate path for '%s/%s'\n", Type, Filename);
633  return (NULL);
634  }
635  _RepUpdateTime(Fname);
636  F = fopen(Fname, "rb");
637  free(Fname);
638  return (F);
639 } /* fo_RepFread() */
640 
648 FILE* fo_RepFwriteTmp(char* Type, char* Filename, char* Ext)
649 {
650  FILE* F = NULL;
651  char* Fname;
652  mode_t Mask;
653 #if GROUP
654  gid_t Gid;
655 #endif
656 
657  if (!_RepCheckType(Type))
658  {
659  fprintf(stderr, "ERROR: Invalid type '%s'\n", Type);
660  return (NULL);
661  }
663  {
664  fprintf(stderr, "ERROR: Invalid filename '%s'\n", Filename);
665  return (NULL);
666  }
667 
668  Fname = fo_RepMkPathTmp(Type, Filename, Ext, 1);
669  if (!Fname)
670  {
671  fprintf(stderr, "ERROR: Unable to allocate path for '%s/%s'\n", Type, Filename);
672  return (NULL);
673  }
674  if (_RepMkDirs(Fname))
675  {
676  free(Fname);
677  return (NULL);
678  }
679  _RepUpdateTime(Fname);
680  Mask = umask(0117); /* mode: 0660 */
681 #if GROUP
682  Gid = getegid();
683  setegid(RepGroup);
684 #endif
685  F = fopen(Fname, "wb");
686  if (!F)
687  {
688  fprintf(stderr, "ERROR: %s, in %s:%d, failed to open [%s]\n",
689  strerror(errno), __FILE__, __LINE__, Fname);
690  free(Fname);
691  return (NULL);
692  }
693  chmod(Fname, S_ISGID | S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP); /* when umask fails */
694 #if GROUP
695  setegid(Gid);
696 #endif
697  umask(Mask);
698  free(Fname);
699  return (F);
700 } /* fo_RepFwriteTmp() */
701 
710 FILE* fo_RepFwrite(char* Type, char* Filename)
711 {
712  return (fo_RepFwriteTmp(Type, Filename, NULL));
713 } /* fo_RepFwrite() */
714 
722 {
723  if (!M) return;
724  if (M->_MmapSize > 0) munmap(M->Mmap, M->_MmapSize);
725  close(M->FileHandle);
726  free(M);
727 } /* fo_RepMunmap() */
728 
735 {
736  RepMmapStruct* M;
737  struct stat Stat;
738  int PageSize;
739 
740  M = (RepMmapStruct*) calloc(1, sizeof(RepMmapStruct));
741  if (!M)
742  {return (NULL);}
743 
744  /* open the file (memory map) */
745  M->FileHandle = open(Fname, O_RDONLY);
746  if (M->FileHandle == -1)
747  {
748  fprintf(stderr, "ERROR: Unable to open file for mmap (%s)\n", Fname);
749  free(M);
750  return (NULL);
751  }
752 
753  /* find how big the file is (to allocate it) */
754  if (fstat(M->FileHandle, &Stat) == -1)
755  {
756  fprintf(stderr, "ERROR: Unable to stat file (%s)\n", Fname);
757  close(M->FileHandle);
758  free(M);
759  return (NULL);
760  }
761  PageSize = getpagesize();
762 
763  /* only mmap the first 1G */
764  if (Stat.st_size > 0x7fffffff) Stat.st_size = 0x80000000;
765 
766  M->MmapSize = Stat.st_size;
767  M->_MmapSize = M->MmapSize + PageSize - (M->MmapSize % PageSize);
768  M->Mmap = mmap(0, M->_MmapSize, PROT_READ, MAP_PRIVATE, M->FileHandle, 0);
769  if (M->Mmap == MAP_FAILED)
770  {
771  fprintf(stderr, "ERROR: Unable to mmap file (%s)\n", Fname);
772  close(M->FileHandle);
773  free(M);
774  return (NULL);
775  }
776  return (M);
777 } /* fo_RepMmapFile() */
778 
786 RepMmapStruct* fo_RepMmap(char* Type, char* Filename)
787 {
788  RepMmapStruct* M;
789  char* Fname;
790 
791  if (!_RepCheckType(Type) || !_RepCheckString(Filename)) return (NULL);
792 
793  Fname = fo_RepMkPath(Type, Filename);
794  if (!Fname) return (NULL);
795  _RepUpdateTime(Fname);
796 
797  M = fo_RepMmapFile(Fname);
798  free(Fname);
799  return (M);
800 } /* fo_RepMmap() */
801 
812 int fo_RepImport(char* Source, char* Type, char* Filename, int Link)
813 {
814  if (0 == strcmp(Type, "files"))
815  {
816  chmod(Source, S_ISGID | S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH); /* change mode */
817  }
818  /*** code uses read/write ***/
819  /*** Could use mmap, but it isn't noticably faster and could have
820  problems with multi-gig files ***/
821  int LenIn, LenOut;
822  int i;
823  char Buf[0x80000]; /* 80K blocks */
824  char vBuf[0x80000]; /* 80K blocks */
825  FILE* Fin;
826  FILE* Fout;
827  char* FoutPath;
828 
829  /* easy route: make a hard link */
830  if (Link)
831  {
832  FoutPath = fo_RepMkPath(Type, Filename);
833  if (!FoutPath) return (0);
834  if (_RepMkDirs(FoutPath)) /* make the directory */
835  {
836  free(FoutPath);
837  return (1);
838  }
839  if (link(Source, FoutPath) == 0)
840  {
841  free(FoutPath);
842  return (0);
843  }
844  free(FoutPath);
845  } /* try a hard link */
846 
847  /* hard route: actually copy the file */
848  Fin = fopen(Source, "rb");
849  if (!Fin)
850  {
851  fprintf(stderr, "ERROR: Unable to open source file '%s'\n", Source);
852  return (1);
853  }
854  setvbuf(Fin, vBuf, _IOFBF, sizeof(vBuf));
855 
856  Fout = fo_RepFwriteTmp(Type, Filename, "I"); /* tmp = ".I" for importing... */
857  if (!Fout)
858  {
859  fprintf(stderr, "ERROR: Invalid -- type='%s' filename='%s'\n", Type, Filename);
860  fclose(Fin);
861  return (2);
862  }
863 
864  LenIn = fread(Buf,1,sizeof(Buf),Fin);
865  while(LenIn > 0)
866  {
867  LenOut=0;
868  while(LenOut < LenIn)
869  {
870  i = fwrite(Buf+LenOut,1,LenIn - LenOut,Fout);
871  LenOut += i;
872  if (i == 0)
873  {
874  /*** Oh no! Write failed! ***/
875  fclose(Fout);
876  fo_RepFclose(Fout);
877  fo_RepRemove(Type,Filename);
878  fprintf(stderr,"ERROR: Write failed -- type='%s' filename='%s'\n",Type,Filename);
879  fclose(Fin);
880  return(3);
881  }
882  }
883  LenIn = fread(Buf,1,sizeof(Buf),Fin);
884  }
885  fo_RepFclose(Fout);
886  fclose(Fin);
887  fo_RepRenameTmp(Type, Filename, "I"); /* mv .I to real name */
888  return (0);
889 } /* fo_RepImport() */
890 
895 {
896  RepDepth = 2; /* default depth */
897  memset(RepPath, '\0', sizeof(RepPath));
898  RepPath[0] = '.'; /* default to local directory */
899 } /* fo_RepClose() */
900 
909 {
910  return fo_RepOpenFull(sysconfig);
911 }
912 
921 {
922  GError* error = NULL;
923  char* path;
924 
925 #if GROUP
926  struct group *Group;
927  gid_t Gid;
928 #endif
929 
930  fo_RepClose(); /* reset everything */
931 
932 #if GROUP
933  /* Make sure we can use group */
934  Group = getgrnam(FOSSGROUP);
935  if (!Group) return(0); /* no such group */
936  RepGroup = Group->gr_gid;
937  Gid = getegid();
938  if ((Gid != RepGroup) && setegid(RepGroup))
939  {
940  perror("Huh?");
941  return(0);
942  }
943  setegid(Gid);
944 #endif
945 
946  /* Load the depth configuration */
947  char* repDepthStr = fo_config_get(config, "FOSSOLOGY", "depth", &error);
948  if (error)
949  {
950  fprintf(stderr, "ERROR %s.%d: %s\n", __FILE__, __LINE__, error->message);
951  return 0;
952  }
953  RepDepth = atoi(repDepthStr);
954 
955  /* Load the path configuration */
956  path = fo_config_get(config, "FOSSOLOGY", "path", &error);
957  if (error)
958  {
959  fprintf(stderr, "ERROR %s.%d: %s\n", __FILE__, __LINE__, error->message);
960  return 0;
961  }
962  strncpy(RepPath, path, sizeof(RepPath)-1);
963  RepPath[sizeof(RepPath)-1] = 0;
964 
965  return 1;
966 } /* fo_RepOpen() */
967 
977 char* fo_RepValidate(fo_conf* config)
978 {
979  char* retval = NULL;
980  int32_t nhosts, nlist, i, j;
981  char* gname = "REPOSITORY";
982  char** hosts;
983  char* curr;
984  GRegex* regex = NULL;
985  GMatchInfo* match = NULL;
986  uint32_t begin, end;
987  gchar* begin_str;
988  gchar* end_str;
989 
990 
991  if ((hosts = fo_config_key_set(config, gname, &nhosts)) == NULL)
992  return g_strdup("The fossology.conf file does not contain a \"REPOSITORY\" group.");
993 
994  /* Regex to match repository lines in the configuration file.
995  *
996  * This will match a file type followed by two hexidecimal numbers. Possible
997  * file types are gold, files, logs, license, test, and all type (denoted by
998  * a *).
999  *
1000  * example match:
1001  * * 00 ff
1002  */
1003  regex = g_regex_new(
1004  "(\\*|gold|files|logs|license|test)\\s+([[:xdigit:]]+)\\s+([[:xdigit:]]+)$",
1005  0, 0, NULL);
1006 
1007  for (i = 0; i < nhosts; i++)
1008  {
1009  nlist = fo_config_list_length(config, gname, hosts[i], NULL);
1010 
1011  for (j = 0; j < nlist; j++)
1012  {
1013  curr = fo_config_get_list(config, gname, hosts[i], j, NULL);
1014 
1015  if (!g_regex_match(regex, curr, 0, &match))
1016  {
1017  retval = g_strdup_printf("%s[] = %s", hosts[i], curr);
1018  break;
1019  }
1020 
1021  begin_str = g_match_info_fetch(match, 2);
1022  end_str = g_match_info_fetch(match, 3);
1023 
1024  begin = strtoul(begin_str, NULL, 16);
1025  end = strtoul(end_str, NULL, 16);
1026 
1027  if (begin >= end)
1028  {
1029  retval = g_strdup_printf("%s[] = %s", hosts[i], curr);
1030  break;
1031  }
1032 
1033  g_free(begin_str);
1034  g_free(end_str);
1035  g_match_info_free(match);
1036  }
1037  }
1038 
1039  g_regex_unref(regex);
1040  return retval;
1041 } /* fo_RepValidate() */
1042 
RepPath($PfilePk, $Repo="files")
Given a pfile id, retrieve the pfile path.
Definition: common-repo.php:58
char * fo_config_get_list(fo_conf *conf, char *group, char *key, int idx, GError **error)
Definition: fossconfig.c:382
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:475
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,...
Definition: fossconfig.c:336
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:614
FOSSology library to read config file.
#define REPONAME
Default repo name.
Definition: libfossrepo.c:35
FILE * fo_RepFwrite(char *Type, char *Filename)
Perform an fwrite. Also creates directories.
Definition: libfossrepo.c:710
char * fo_RepMkPath(const char *Type, char *Filename)
Given a filename, construct the full path to the file.
Definition: libfossrepo.c:352
#define MAXLINE
Max length of a line.
Definition: libfossrepo.c:34
int fo_RepOpenFull(fo_conf *config)
Loads common information from configuration files into ram.
Definition: libfossrepo.c:920
int fo_RepExist2(char *Type, char *Filename)
Determine if a file exists.
Definition: libfossrepo.c:531
int fo_RepImport(char *Source, char *Type, char *Filename, int Link)
Import a file into the repository.
Definition: libfossrepo.c:812
int fo_RepFclose(FILE *F)
Perform an fclose.
Definition: libfossrepo.c:601
char * fo_RepGetRepPath()
Determine the path for the repository's root.
Definition: libfossrepo.c:102
FILE * fo_RepFread(char *Type, char *Filename)
Perform an fopen for reading only.
Definition: libfossrepo.c:613
char * fo_RepValidate(fo_conf *config)
validates the repository configuration information.
Definition: libfossrepo.c:977
int fo_RepOpen()
wrapper function for agents. Simply call fo_RepOpenFull() passing in the default system configuration
Definition: libfossrepo.c:908
int _RepCheckString(char *S)
Simple check to see if the string is valid.
Definition: libfossrepo.c:83
int fo_RepHostExist(char *Type, char *Host)
Determine if a host exists.
Definition: libfossrepo.c:120
char * _RepGetHost(const char *Type, char *Filename, int MatchNum)
Determine the host for the tree.
Definition: libfossrepo.c:158
RepMmapStruct * fo_RepMmap(char *Type, char *Filename)
Perform a mmap.
Definition: libfossrepo.c:786
int fo_RepExist(char *Type, char *Filename)
Determine if a file exists.
Definition: libfossrepo.c:486
char * fo_RepGetHost(char *Type, char *Filename)
Determine the host for a filename.
Definition: libfossrepo.c:221
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:244
int fo_RepRemove(char *Type, char *Filename)
Delete a repository file.
Definition: libfossrepo.c:568
FILE * fo_RepFwriteTmp(char *Type, char *Filename, char *Ext)
Perform an fwrite. Also creates directories.
Definition: libfossrepo.c:648
void fo_RepClose()
Close and unmap the repository configuration file.
Definition: libfossrepo.c:894
int _RepCheckType(const char *S)
Simple check to see if the string S is valid filename.
Definition: libfossrepo.c:61
void fo_RepMunmap(RepMmapStruct *M)
Perform a munmap.
Definition: libfossrepo.c:721
RepMmapStruct * fo_RepMmapFile(char *Fname)
Perform a mmap on a regular file name.
Definition: libfossrepo.c:734
int fo_RepRenameTmp(char *Type, char *Filename, char *Ext)
Rename a temp file to a real file.
Definition: libfossrepo.c:454
void _RepUpdateTime(char *File)
Update the last modified time of a file.
Definition: libfossrepo.c:394
int _RepMkDirs(char *Fname)
Same as command-line "mkdir -p".
Definition: libfossrepo.c:408
fo_conf * sysconfig
start($application)
start the application Assumes application is restartable via /etc/init.d/<script>....
Definition: pkgConfig.php:1214
Definition: monk.h:61
Definition: match.h:20
unsigned char * Mmap
Memory pointer from mmap.
Definition: libfossrepo.h:92
int FileHandle
Handle from open()
Definition: libfossrepo.h:91
uint32_t MmapSize
Size of file mmap.
Definition: libfossrepo.h:93
uint32_t _MmapSize
Real size of mmap (set to page boundary)
Definition: libfossrepo.h:94
Store the results of a regex match.
Definition: scanners.hpp:28
char * Filename
Filename.
Definition: run_tests.c:17