33 #include "libfossrepo.h" 40 long TotalImported = 0;
41 long TotalDuplicate = 0;
52 void CopyFile(
char* Source,
char* Type,
char* Name)
66 if (
fo_RepImport(Source, Type, Name, 1) == 0) TotalImported++;
77 int ReadLine(FILE* Fin,
char* Line,
int MaxLine)
81 memset(Line, 0, MaxLine);
82 if (feof(Fin))
return (-1);
83 while (!feof(Fin) && (i < MaxLine - 1) && (C !=
'\n') && (C > 0))
86 if ((C > 0) && (C !=
'\n'))
102 if (!isxdigit(C))
return (0);
103 if (isdigit(C))
return (C -
'0');
104 if (isupper(C))
return (C -
'A' + 10);
105 return (C -
'a' + 10);
116 if ((S[0] ==
'&') && (S[1] ==
'#') && (S[2] ==
'x')
117 && isxdigit(S[3]) && isxdigit(S[4]) && (S[5] ==
';'))
133 char Dst[FILENAME_MAX];
134 char Src[FILENAME_MAX];
138 while (
ReadLine(Fin, Buf,
sizeof(Buf)) > 0)
142 while ((Buf[Space] !=
'\0') && (Buf[Space] !=
' ')) Space++;
143 strncpy(Dst, Buf, Space);
146 memset(Dst,
'\0',
sizeof(Dst));
147 memset(Src,
'\0',
sizeof(Src));
148 strncpy(Dst, Buf, Space);
150 for (i = Space + 1; Buf[i] !=
'\0'; i++)
152 if (Buf[i] !=
'&') Src[s++] = Buf[i];
161 else Src[s++] = Buf[i];
165 printf(
"Dst='%s' Src='%s'\n",Dst,Src);
184 char Dst[FILENAME_MAX];
185 char Src[FILENAME_MAX];
193 while (
ReadLine(Fin, Buf,
sizeof(Buf)) > 0)
196 if (!strncmp(Buf,
"<item ", 6)) FileType = Type;
197 else if (!strncmp(Buf,
"<source ", 8)) FileType = TypeSource;
201 fuid = strstr(Buf,
" fuid=\"");
206 source = strstr(Buf,
" source=\"");
207 if (!source)
continue;
211 field = strstr(Buf,
" artifact=\"1\"");
213 field = strstr(Buf,
" mime=\"directory\"");
217 memset(Dst,
'\0',
sizeof(Dst));
218 memset(Src,
'\0',
sizeof(Src));
220 for (i = 0; source[i] !=
'\"'; i++)
222 if (source[i] !=
'&') Src[j++] = source[i];
231 else Src[j++] = source[i];
235 for (i = 0; fuid[i] !=
'\"'; i++)
237 if (fuid[i] !=
'&') Dst[j++] = fuid[i];
246 else Dst[j++] = fuid[i];
250 printf(
"Dst='%s' Src='%s'\n",Dst,Src);
254 if (FileType != Type)
CopyFile(Src, Type, Dst);
261 int main(
int argc,
char* argv[])
263 if ((argc < 2) || (argc > 4))
265 fprintf(stderr,
"Usage: (depends on the parameters)\n");
266 fprintf(stderr,
" %s type filename sha1.md5.len\n", argv[0]);
267 fprintf(stderr,
" echo 'sha1.md5.len filename' | %s type\n", argv[0]);
268 fprintf(stderr,
" echo '<xml from ununpack>...</xml>' | %s typesource type\n", argv[0]);
269 fprintf(stderr,
" type = repository for storing files\n");
270 fprintf(stderr,
" typesource = repository for storing source files (XML only)\n");
283 CopyFile(argv[2], argv[1], argv[3]);
287 printf(
"Total Imported: %ld\n", TotalImported);
288 printf(
"Total Duplicates: %ld\n", TotalDuplicate);
289 printf(
"Total Errors: %ld\n", TotalError);
290 if (TotalError > 0)
return (1);
int UnUnicodeHex(char *S)
void ProcessPairs(FILE *Fin, char *Type)
void CopyFile(char *Source, char *Type, char *Name)
int s
The socket that the CLI will use to communicate.
static char * Src
Souce location.
static char * Dst
Destination location.
void ProcessXML(FILE *Fin, char *TypeSource, char *Type)
Process Ununpack XML.
int ReadLine(FILE *Fin, char *Line, int MaxLine)
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.