FOSSology  3.2.0rc1
Open Source License Compliance by Open Source Software
libfossrepo.h
1 /************************************************************
2 librep: A set of functions for accessing the file repository.
3 
4 Copyright (C) 2007-2011 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 Repository config files:
21 /etc/fossology/
22 RepPath.conf # contains path to the mounted directory
23 # If it does not exist, then "." is used.
24 Depth.conf # contains a number for the current depth
25 Hosts.conf # list of hosts and hex ranges (used to find host with data)
26 
27 The layout looks like:
28 host1/ # Each host has a directory. This can be mounted or local
29 host1/type/ # Type describes the repository (e.g., gold, file, license)
30 host1/type/00/ # Directories are lowercase octets (00 to ff)
31 host1/type/00/00/ # Directories are lowercase octets (00 to ff)
32 host1/type/00/00/sha1.md5.len # Files are lowercase octets and digits
33 host2/ # Each host has a directory. This can be mounted or local
34 host2/type/ # Type describes the repository (e.g., gold, file, license)
35 host2/type/00/ # Directories are lowercase octets (00 to ff)
36 host2/type/00/00/ # Directories are lowercase octets (00 to ff)
37 ************************************************************/
38 
39 #ifndef LIBFOSSREPO_H
40 #define LIBFOSSREPO_H
41 
42 #include <fossconfig.h>
43 
44 #include <stdlib.h>
45 #include <stdint.h>
46 #include <stdio.h>
47 #include <unistd.h>
48 #include <string.h>
49 #include <ctype.h>
50 #include <limits.h>
51 #include <utime.h>
52 #include <errno.h>
53 #include <time.h>
54 #include <sys/types.h>
55 #include <sys/mman.h>
56 #include <fcntl.h>
57 #include <grp.h>
58 
59 #ifndef FOSSREPO_CONF
60 #define FOSSREPO_CONF "/srv/fossology/repository"
61 #endif
62 #ifndef FOSSGROUP
63 #define FOSSGROUP "fossology"
64 #endif
65 
66 
67 /* General Repository usage */
68 int fo_RepOpen();
69 /* call before using any other function */
70 void fo_RepClose();
71 /* call after using all other functions */
72 int fo_RepOpenFull(fo_conf* config);
73 /* agents should call fo_RepOpen() */
74 char* fo_RepValidate(fo_conf* config); /* checks the repo config */
75 
76 /* Get info -- caller must free() returned string. */
77 char* fo_RepGetRepPath();
78 /* path to mounted repository */
79 char* fo_RepGetHost(char* Type, char* Filename);
80 char* fo_RepMkPath(const char* Type, char* Filename);
81 
82 /* Not intended for external use */
83 int _RepMkDirs(char* Filename);
84 
85 /* Sanity checks */
86 int fo_RepExist(char* Type, char* Filename);
87 int fo_RepExist2(char* Type, char* Filename);
88 int fo_RepHostExist(char* Type, char* Host);
89 
90 /* Removal */
91 int fo_RepRemove(char* Type, char* Filename);
92 
93 /* Replacements for fopen/fclose */
94 FILE* fo_RepFread(char* Type, char* Filename);
95 FILE* fo_RepFwrite(char* Type, char* Filename);
96 int fo_RepFclose(FILE* F);
97 int fo_RepImport(char* Source, char* Type, char* Filename, int HardLink);
98 
101 {
103  unsigned char* Mmap;
104  uint32_t MmapSize;
105  uint32_t _MmapSize;
106 };
107 typedef struct RepMmapStruct RepMmapStruct;
108 void fo_RepMunmap(RepMmapStruct* M);
109 RepMmapStruct* fo_RepMmap(char* Type, char* Filename);
110 RepMmapStruct* fo_RepMmapFile(char* FullFilename);
111 
112 #endif
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
uint32_t MmapSize
Size of file mmap.
Definition: libfossrepo.h:104
int fo_RepHostExist(char *Type, char *Host)
Determine if a host exists.
Definition: libfossrepo.c:132
char * fo_RepGetRepPath()
Determine the path for the repository&#39;s root.
Definition: libfossrepo.c:114
char * fo_RepValidate(fo_conf *config)
validates the repository configuration information.
Definition: libfossrepo.c:989
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
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
int FileHandle
Handle from open()
Definition: libfossrepo.h:102
int _RepMkDirs(char *Fname)
Same as command-line "mkdir -p".
Definition: libfossrepo.c:420
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
int fo_RepExist2(char *Type, char *Filename)
Determine if a file exists.
Definition: libfossrepo.c:543
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_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