20 #include "libfossrepo.h"
27 long TotalImported = 0;
28 long TotalDuplicate = 0;
39 void CopyFile(
char* Source,
char* Type,
char* Name)
53 if (
fo_RepImport(Source, Type, Name, 1) == 0) TotalImported++;
64 int ReadLine(FILE* Fin,
char* Line,
int MaxLine)
68 memset(Line, 0, MaxLine);
69 if (feof(Fin))
return (-1);
70 while (!feof(Fin) && (i < MaxLine - 1) && (C !=
'\n') && (C > 0))
73 if ((C > 0) && (C !=
'\n'))
89 if (!isxdigit(C))
return (0);
90 if (isdigit(C))
return (C -
'0');
91 if (isupper(C))
return (C -
'A' + 10);
92 return (C -
'a' + 10);
103 if ((S[0] ==
'&') && (S[1] ==
'#') && (S[2] ==
'x')
104 && isxdigit(S[3]) && isxdigit(S[4]) && (S[5] ==
';'))
120 char Dst[FILENAME_MAX];
121 char Src[FILENAME_MAX];
125 while (
ReadLine(Fin, Buf,
sizeof(Buf)) > 0)
129 while ((Buf[Space] !=
'\0') && (Buf[Space] !=
' ')) Space++;
130 strncpy(
Dst, Buf, Space);
133 memset(
Dst,
'\0',
sizeof(
Dst));
134 memset(
Src,
'\0',
sizeof(
Src));
135 strncpy(
Dst, Buf, Space);
137 for (i = Space + 1; Buf[i] !=
'\0'; i++)
139 if (Buf[i] !=
'&')
Src[
s++] = Buf[i];
148 else Src[
s++] = Buf[i];
152 printf(
"Dst='%s' Src='%s'\n",
Dst,
Src);
171 char Dst[FILENAME_MAX];
172 char Src[FILENAME_MAX];
180 while (
ReadLine(Fin, Buf,
sizeof(Buf)) > 0)
183 if (!strncmp(Buf,
"<item ", 6)) FileType = Type;
184 else if (!strncmp(Buf,
"<source ", 8)) FileType = TypeSource;
188 fuid = strstr(Buf,
" fuid=\"");
193 source = strstr(Buf,
" source=\"");
194 if (!source)
continue;
198 field = strstr(Buf,
" artifact=\"1\"");
200 field = strstr(Buf,
" mime=\"directory\"");
204 memset(
Dst,
'\0',
sizeof(
Dst));
205 memset(
Src,
'\0',
sizeof(
Src));
207 for (i = 0; source[i] !=
'\"'; i++)
209 if (source[i] !=
'&')
Src[j++] = source[i];
218 else Src[j++] = source[i];
222 for (i = 0; fuid[i] !=
'\"'; i++)
224 if (fuid[i] !=
'&')
Dst[j++] = fuid[i];
233 else Dst[j++] = fuid[i];
237 printf(
"Dst='%s' Src='%s'\n",
Dst,
Src);
248 int main(
int argc,
char* argv[])
250 if ((argc < 2) || (argc > 4))
252 fprintf(stderr,
"Usage: (depends on the parameters)\n");
253 fprintf(stderr,
" %s type filename sha1.md5.len\n", argv[0]);
254 fprintf(stderr,
" echo 'sha1.md5.len filename' | %s type\n", argv[0]);
255 fprintf(stderr,
" echo '<xml from ununpack>...</xml>' | %s typesource type\n", argv[0]);
256 fprintf(stderr,
" type = repository for storing files\n");
257 fprintf(stderr,
" typesource = repository for storing source files (XML only)\n");
270 CopyFile(argv[2], argv[1], argv[3]);
274 printf(
"Total Imported: %ld\n", TotalImported);
275 printf(
"Total Duplicates: %ld\n", TotalDuplicate);
276 printf(
"Total Errors: %ld\n", TotalError);
277 if (TotalError > 0)
return (1);
int s
The socket that the CLI will use to communicate.
int fo_RepImport(char *Source, char *Type, char *Filename, int Link)
Import a file into the repository.
int fo_RepExist(char *Type, char *Filename)
Determine if a file exists.
void CopyFile(char *Source, char *Type, char *Name)
void ProcessXML(FILE *Fin, char *TypeSource, char *Type)
Process Ununpack XML.
int UnUnicodeHex(char *S)
void ProcessPairs(FILE *Fin, char *Type)
int ReadLine(FILE *Fin, char *Line, int MaxLine)
static char * Dst
Destination location.
static char * Src
Souce location.