CARDS 2.4.121
Package manager for the NuTyX GNU/Linux distribution
libcards.h
1 /*
2  GNU GENERAL PUBLIC LICENSE
3  Version 2, June 1991
4 
5  Copyright (C) 1989, 1991 Free Software Foundation, Inc.
6  59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
7 
8  Everyone is permitted to copy and distribute verbatim copies
9  of this license document, but changing it is not allowed.
10 
11  Preamble
12 
13  The licenses for most software are designed to take away your
14 freedom to share and change it. By contrast, the GNU General Public
15 License is intended to guarantee your freedom to share and change free
16 software--to make sure the software is free for all its users. This
17 General Public License applies to most of the Free Software
18 Foundation's software and to any other program whose authors commit to
19 using it. (Some other Free Software Foundation software is covered by
20 the GNU Library General Public License instead.) You can apply it to
21 your programs, too.
22 
23  When we speak of free software, we are referring to freedom, not
24 price. Our General Public Licenses are designed to make sure that you
25 have the freedom to distribute copies of free software (and charge for
26 this service if you wish), that you receive source code or can get it
27 if you want it, that you can change the software or use pieces of it
28 in new free programs; and that you know you can do these things.
29 
30  To protect your rights, we need to make restrictions that forbid
31 anyone to deny you these rights or to ask you to surrender the rights.
32 These restrictions translate to certain responsibilities for you if you
33 distribute copies of the software, or if you modify it.
34 
35  For example, if you distribute copies of such a program, whether
36 gratis or for a fee, you must give the recipients all the rights that
37 you have. You must make sure that they, too, receive or can get the
38 source code. And you must show them these terms so they know their
39 rights.
40 
41  We protect your rights with two steps: (1) copyright the software, and
42 (2) offer you this license which gives you legal permission to copy,
43 distribute and/or modify the software.
44 
45  Also, for each author's protection and ours, we want to make certain
46 that everyone understands that there is no warranty for this free
47 software. If the software is modified by someone else and passed on, we
48 want its recipients to know that what they have is not the original, so
49 that any problems introduced by others will not reflect on the original
50 authors' reputations.
51 
52  Finally, any free program is threatened constantly by software
53 patents. We wish to avoid the danger that redistributors of a free
54 program will individually obtain patent licenses, in effect making the
55 program proprietary. To prevent this, we have made it clear that any
56 patent must be licensed for everyone's free use or not licensed at all.
57 
58  The precise terms and conditions for copying, distribution and
59 modification follow.
60 
61  GNU GENERAL PUBLIC LICENSE
62  TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
63 
64  0. This License applies to any program or other work which contains
65 a notice placed by the copyright holder saying it may be distributed
66 under the terms of this General Public License. The "Program", below,
67 refers to any such program or work, and a "work based on the Program"
68 means either the Program or any derivative work under copyright law:
69 that is to say, a work containing the Program or a portion of it,
70 either verbatim or with modifications and/or translated into another
71 language. (Hereinafter, translation is included without limitation in
72 the term "modification".) Each licensee is addressed as "you".
73 
74 Activities other than copying, distribution and modification are not
75 covered by this License; they are outside its scope. The act of
76 running the Program is not restricted, and the output from the Program
77 is covered only if its contents constitute a work based on the
78 Program (independent of having been made by running the Program).
79 Whether that is true depends on what the Program does.
80 
81  1. You may copy and distribute verbatim copies of the Program's
82 source code as you receive it, in any medium, provided that you
83 conspicuously and appropriately publish on each copy an appropriate
84 copyright notice and disclaimer of warranty; keep intact all the
85 notices that refer to this License and to the absence of any warranty;
86 and give any other recipients of the Program a copy of this License
87 along with the Program.
88 
89 You may charge a fee for the physical act of transferring a copy, and
90 you may at your option offer warranty protection in exchange for a fee.
91 
92  2. You may modify your copy or copies of the Program or any portion
93 of it, thus forming a work based on the Program, and copy and
94 distribute such modifications or work under the terms of Section 1
95 above, provided that you also meet all of these conditions:
96 
97  a) You must cause the modified files to carry prominent notices
98  stating that you changed the files and the date of any change.
99 
100  b) You must cause any work that you distribute or publish, that in
101  whole or in part contains or is derived from the Program or any
102  part thereof, to be licensed as a whole at no charge to all third
103  parties under the terms of this License.
104 
105  c) If the modified program normally reads commands interactively
106  when run, you must cause it, when started running for such
107  interactive use in the most ordinary way, to print or display an
108  announcement including an appropriate copyright notice and a
109  notice that there is no warranty (or else, saying that you provide
110  a warranty) and that users may redistribute the program under
111  these conditions, and telling the user how to view a copy of this
112  License. (Exception: if the Program itself is interactive but
113  does not normally print such an announcement, your work based on
114  the Program is not required to print an announcement.)
115 
116 These requirements apply to the modified work as a whole. If
117 identifiable sections of that work are not derived from the Program,
118 and can be reasonably considered independent and separate works in
119 themselves, then this License, and its terms, do not apply to those
120 sections when you distribute them as separate works. But when you
121 distribute the same sections as part of a whole which is a work based
122 on the Program, the distribution of the whole must be on the terms of
123 this License, whose permissions for other licensees extend to the
124 entire whole, and thus to each and every part regardless of who wrote it.
125 
126 Thus, it is not the intent of this section to claim rights or contest
127 your rights to work written entirely by you; rather, the intent is to
128 exercise the right to control the distribution of derivative or
129 collective works based on the Program.
130 
131 In addition, mere aggregation of another work not based on the Program
132 with the Program (or with a work based on the Program) on a volume of
133 a storage or distribution medium does not bring the other work under
134 the scope of this License.
135 
136  3. You may copy and distribute the Program (or a work based on it,
137 under Section 2) in object code or executable form under the terms of
138 Sections 1 and 2 above provided that you also do one of the following:
139 
140  a) Accompany it with the complete corresponding machine-readable
141  source code, which must be distributed under the terms of Sections
142  1 and 2 above on a medium customarily used for software interchange; or,
143 
144  b) Accompany it with a written offer, valid for at least three
145  years, to give any third party, for a charge no more than your
146  cost of physically performing source distribution, a complete
147  machine-readable copy of the corresponding source code, to be
148  distributed under the terms of Sections 1 and 2 above on a medium
149  customarily used for software interchange; or,
150 
151  c) Accompany it with the information you received as to the offer
152  to distribute corresponding source code. (This alternative is
153  allowed only for noncommercial distribution and only if you
154  received the program in object code or executable form with such
155  an offer, in accord with Subsection b above.)
156 
157 The source code for a work means the preferred form of the work for
158 making modifications to it. For an executable work, complete source
159 code means all the source code for all modules it contains, plus any
160 associated interface definition files, plus the scripts used to
161 control compilation and installation of the executable. However, as a
162 special exception, the source code distributed need not include
163 anything that is normally distributed (in either source or binary
164 form) with the major components (compiler, kernel, and so on) of the
165 operating system on which the executable runs, unless that component
166 itself accompanies the executable.
167 
168 If distribution of executable or object code is made by offering
169 access to copy from a designated place, then offering equivalent
170 access to copy the source code from the same place counts as
171 distribution of the source code, even though third parties are not
172 compelled to copy the source along with the object code.
173 
174  4. You may not copy, modify, sublicense, or distribute the Program
175 except as expressly provided under this License. Any attempt
176 otherwise to copy, modify, sublicense or distribute the Program is
177 void, and will automatically terminate your rights under this License.
178 However, parties who have received copies, or rights, from you under
179 this License will not have their licenses terminated so long as such
180 parties remain in full compliance.
181 
182  5. You are not required to accept this License, since you have not
183 signed it. However, nothing else grants you permission to modify or
184 distribute the Program or its derivative works. These actions are
185 prohibited by law if you do not accept this License. Therefore, by
186 modifying or distributing the Program (or any work based on the
187 Program), you indicate your acceptance of this License to do so, and
188 all its terms and conditions for copying, distributing or modifying
189 the Program or works based on it.
190 
191  6. Each time you redistribute the Program (or any work based on the
192 Program), the recipient automatically receives a license from the
193 original licensor to copy, distribute or modify the Program subject to
194 these terms and conditions. You may not impose any further
195 restrictions on the recipients' exercise of the rights granted herein.
196 You are not responsible for enforcing compliance by third parties to
197 this License.
198 
199  7. If, as a consequence of a court judgment or allegation of patent
200 infringement or for any other reason (not limited to patent issues),
201 conditions are imposed on you (whether by court order, agreement or
202 otherwise) that contradict the conditions of this License, they do not
203 excuse you from the conditions of this License. If you cannot
204 distribute so as to satisfy simultaneously your obligations under this
205 License and any other pertinent obligations, then as a consequence you
206 may not distribute the Program at all. For example, if a patent
207 license would not permit royalty-free redistribution of the Program by
208 all those who receive copies directly or indirectly through you, then
209 the only way you could satisfy both it and this License would be to
210 refrain entirely from distribution of the Program.
211 
212 If any portion of this section is held invalid or unenforceable under
213 any particular circumstance, the balance of the section is intended to
214 apply and the section as a whole is intended to apply in other
215 circumstances.
216 
217 It is not the purpose of this section to induce you to infringe any
218 patents or other property right claims or to contest validity of any
219 such claims; this section has the sole purpose of protecting the
220 integrity of the free software distribution system, which is
221 implemented by public license practices. Many people have made
222 generous contributions to the wide range of software distributed
223 through that system in reliance on consistent application of that
224 system; it is up to the author/donor to decide if he or she is willing
225 to distribute software through any other system and a licensee cannot
226 impose that choice.
227 
228 This section is intended to make thoroughly clear what is believed to
229 be a consequence of the rest of this License.
230 
231  8. If the distribution and/or use of the Program is restricted in
232 certain countries either by patents or by copyrighted interfaces, the
233 original copyright holder who places the Program under this License
234 may add an explicit geographical distribution limitation excluding
235 those countries, so that distribution is permitted only in or among
236 countries not thus excluded. In such case, this License incorporates
237 the limitation as if written in the body of this License.
238 
239  9. The Free Software Foundation may publish revised and/or new versions
240 of the General Public License from time to time. Such new versions will
241 be similar in spirit to the present version, but may differ in detail to
242 address new problems or concerns.
243 
244 Each version is given a distinguishing version number. If the Program
245 specifies a version number of this License which applies to it and "any
246 later version", you have the option of following the terms and conditions
247 either of that version or of any later version published by the Free
248 Software Foundation. If the Program does not specify a version number of
249 this License, you may choose any version ever published by the Free Software
250 Foundation.
251 
252  10. If you wish to incorporate parts of the Program into other free
253 programs whose distribution conditions are different, write to the author
254 to ask for permission. For software which is copyrighted by the Free
255 Software Foundation, write to the Free Software Foundation; we sometimes
256 make exceptions for this. Our decision will be guided by the two goals
257 of preserving the free status of all derivatives of our free software and
258 of promoting the sharing and reuse of software generally.
259 
260  NO WARRANTY
261 
262  11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
263 FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
264 OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
265 PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
266 OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
267 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
268 TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
269 PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
270 REPAIR OR CORRECTION.
271 
272  12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
273 WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
274 REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
275 INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
276 OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
277 TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
278 YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
279 PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
280 POSSIBILITY OF SUCH DAMAGES.
281 
282  END OF TERMS AND CONDITIONS
283 
284  Appendix: How to Apply These Terms to Your New Programs
285 
286  If you develop a new program, and you want it to be of the greatest
287 possible use to the public, the best way to achieve this is to make it
288 free software which everyone can redistribute and change under these terms.
289 
290  To do so, attach the following notices to the program. It is safest
291 to attach them to the start of each source file to most effectively
292 convey the exclusion of warranty; and each file should have at least
293 the "copyright" line and a pointer to where the full notice is found.
294 
295  <one line to give the program's name and a brief idea of what it does.>
296  Copyright (C) 19yy <name of author>
297 
298  This program is free software; you can redistribute it and/or modify
299  it under the terms of the GNU General Public License as published by
300  the Free Software Foundation; either version 2 of the License, or
301  (at your option) any later version.
302 
303  This program is distributed in the hope that it will be useful,
304  but WITHOUT ANY WARRANTY; without even the implied warranty of
305  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
306  GNU General Public License for more details.
307 
308  You should have received a copy of the GNU General Public License
309  along with this program; if not, write to the Free Software
310  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
311 
312 Also add information on how to contact you by electronic and paper mail.
313 
314 If the program is interactive, make it output a short notice like this
315 when it starts in an interactive mode:
316 
317  Gnomovision version 69, Copyright (C) 19yy name of author
318  Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
319  This is free software, and you are welcome to redistribute it
320  under certain conditions; type `show c' for details.
321 
322 The hypothetical commands `show w' and `show c' should show the appropriate
323 parts of the General Public License. Of course, the commands you use may
324 be called something other than `show w' and `show c'; they could even be
325 mouse-clicks or menu items--whatever suits your program.
326 
327 You should also get your employer (if you work as a programmer) or your
328 school, if any, to sign a "copyright disclaimer" for the program, if
329 necessary. Here is a sample; alter the names:
330 
331  Yoyodyne, Inc., hereby disclaims all copyright interest in the program
332  `Gnomovision' (which makes passes at compilers) written by James Hacker.
333 
334  <signature of Ty Coon>, 1 April 1989
335  Ty Coon, President of Vice
336 
337 This General Public License does not permit incorporating your program into
338 proprietary programs. If your program is a subroutine library, you may
339 consider it more useful to permit linking proprietary applications with the
340 library. If this is what you want to do, use the GNU Library General
341 Public License instead of this License.
342 */
343 
344 
345 #ifndef LIB_CARDS_INCLUDED
346 #define LIB_CARDS_INCLUDED
347 
348 
349 #include <string>
350 #include <iterator>
351 #include <iostream>
352 
353 #include <syslog.h>
354 #include <stdio.h>
355 #include <sys/utsname.h>
356 #include <locale.h>
357 #include <libintl.h>
358 
359 #define _ gettext
360 
364 std::string getMachineType ();
365 
366 
367 
368 
369 #include <cstring>
370 
371 #define RED "\033[1;31m"
372 #define GREEN "\033[1;32m"
373 #define YELLOW "\033[1;33m"
374 #define BLUE "\033[1;34m"
375 #define MAGENTA "\033[1;35m"
376 #define CYAN "\033[1;36m"
377 #define WHITE "\033[1;37m"
378 #define NORMAL "\033[1;0m"
379 
380 #define ACTION _("\033[1;33maction:\033[1;0m")
381 #define USAGE _("\033[1;33musage: \033[1;0m")
382 #define OPTIONS _("\033[1;33moptions\033[1;0m")
383 #define REQUIRED _("\033[1;33mrequired\033[1;0m")
384 #define DESCRIPTION _("\033[1;33mdescription: \033[1;0m")
385 #define COMMAND _("\033[1;34mcommand\033[1;0m")
386 
387 
388 enum error
389 {
390 CANNOT_FIND_DEPOT,
391 CANNOT_DOWNLOAD_FILE,
392 CANNOT_CREATE_FILE,
393 CANNOT_OPEN_FILE,
394 CANNOT_FIND_FILE,
395 CANNOT_READ_FILE,
396 CANNOT_COPY_FILE,
397 CANNOT_PARSE_FILE,
398 CANNOT_READ_DIRECTORY,
399 CANNOT_WRITE_FILE,
400 CANNOT_SYNCHRONIZE,
401 CANNOT_RENAME_FILE,
402 CANNOT_DETERMINE_NAME_BUILDNR,
403 WRONG_ARCHITECTURE,
404 EMPTY_PACKAGE,
405 CANNOT_FORK,
406 WAIT_PID_FAILED,
407 DATABASE_LOCKED,
408 CANNOT_LOCK_DIRECTORY,
409 CANNOT_REMOVE_FILE,
410 CANNOT_CREATE_DIRECTORY,
411 CANNOT_RENAME_DIRECTORY,
412 OPTION_ONE_ARGUMENT,
413 INVALID_OPTION,
414 OPTION_MISSING,
415 TOO_MANY_OPTIONS,
416 ONLY_ROOT_CAN_INSTALL_UPGRADE_REMOVE,
417 PACKAGE_NOT_EXIST,
418 PACKAGE_NOT_FOUND,
419 PACKAGE_ALLREADY_INSTALL,
420 PACKAGE_NOT_INSTALL,
421 PACKAGE_NOT_PREVIOUSLY_INSTALL,
422 LISTED_FILES_ALLREADY_INSTALLED,
423 PKGADD_CONFIG_LINE_TOO_LONG,
424 PKGADD_CONFIG_WRONG_NUMBER_ARGUMENTS,
425 PKGADD_CONFIG_UNKNOWN_ACTION,
426 PKGADD_CONFIG_UNKNOWN_EVENT,
427 CANNOT_COMPILE_REGULAR_EXPRESSION,
428 CANNOT_GENERATE_LEVEL,
429 NOT_INSTALL_PACKAGE_NEITHER_PACKAGE_FILE
430 };
431 
432 class RunTimeErrorWithErrno : public std::runtime_error
433 {
434  public:
435  explicit RunTimeErrorWithErrno(const std::string& msg) throw();
436  explicit RunTimeErrorWithErrno(const std::string& msg, int e) throw();
437 };
438 
439 
440 #include <string.h>
441 
442 #define uint8 unsigned char
443 #define uint32 unsigned long int
444 
446 {
447  uint32 total[2];
448  uint32 state[4];
449  uint8 buffer[64];
450 };
451 
452 void md5_starts( struct md5_context *ctx );
453 void md5_update( struct md5_context *ctx, uint8 *input, uint32 length );
454 void md5_finish( struct md5_context *ctx, uint8 digest[16] );
455 
456 
457 
458 
459 #include <fstream>
460 #include <map>
461 #include <set>
462 #include <vector>
463 
464 #include <sys/stat.h>
465 
466 #define GIGA 1e9
467 #define MEGA 1e6
468 #define KILO 1e3
469 #define PACKAGE_LOCALE_DIR "/usr/share/locale"
470 #define GETTEXT_PACKAGE "cards"
471 
472 void *Malloc(size_t s);
473 
474 struct keyValue
475 {
476  std::string parameter;
477  std::string value;
478 };
479 
483 typedef struct
484 {
485  char **items;
486  unsigned int count;
487 } itemList;
488 
492 itemList *initItemList(void);
493 
497 void addItemToItemList(itemList *list, const char *item);
498 
503 void freeItemList(itemList *list);
504 
508 keyValue splitKeyValue
509 (std::string s, char delimiter);
510 
511 std::set<std::string> getKeysList
512 (std::string file, std::string delimiter);
513 
514 std::string getValueOfKey
515 (std::string file, std::string delimiter,std::string parameter);
516 
517 std::string getValue(const std::string& s, char delimiter);
518 std::string getValueBefore( const std::string& s, char del );
519 std::string getValueBeforeLast( const std::string& s, char del );
520 
521 std::string itos(unsigned int value);
522 std::string ultos(unsigned long int value);
523 
524 std::string mtos(mode_t mode);
525 std::string trimFileName(const std::string& filename);
526 std::string sizeHumanRead(int value);
527 
528 /*param s the string to be searched, param delimiter the delimiter char
529 return the value after the first occurance of a delimiter */
530 std::string getFirstValueOfKeyAfterDelim(const std::string& s, char delimiter);
531 
532 /* strip whitespace in the beginning and end of string, return a stripped string */
533 std::string stripWhiteSpace(const std::string& s);
534 
535 /* populate a vector of string with delimited character */
536 std::vector<std::string> parseDelimitedList
537 (const std::string& s, const char delimiter);
538 
539 /* populate a set of string with delimited character */
540 std::set<std::string> parseDelimitedSetList
541 (const std::string& s, const char delimiter);
542 
543 /* make sure s1 starts with s2 */
544 bool startsWith(const std::string& s, const std::string& with);
545 
550 bool startsWithNoCase(const std::string& s1, const std::string& s2);
551 
552 std::string convertToLowerCase(const std::string& s);
553 std::string convertToUpperCase(const std::string& s);
554 
555 std::string replaceAll
556 ( std::string& in, const std::string& oldString, const std::string& newString );
557 
567 template <class T>
568 void split( const std::string& s, char del,
569  T& target,
570  int startPos, bool useEmpty )
571 {
572  std::string line = s;
573  std::string ss;
574  std::string::size_type pos;
575  int offset = startPos;
576  while ( ( pos = line.find( del, offset ) ) != std::string::npos ) {
577  offset = 0;
578  if ( line[pos-1] == '\\' ) {
579  line.erase(pos-1,1);
580  ss = ss + line.substr(0,pos);
581  line.erase(0,pos);
582  continue;
583  }
584  std::string val = line.substr( 0, pos );
585  if ( ( useEmpty || !stripWhiteSpace( val ).empty() ) ||
586  ( ss.length() > 0 ) ) {
587  target.push_back( ss + val );
588  }
589  line.erase( 0, pos+1 );
590  }
591 
592  if ( ( line.length() > 0 ) || ( ss.length() > 0 ) ) {
593  target.push_back( ss + line );
594  }
595 }
596 
597 
598 
599 
600 #include <utime.h>
601 #include <dirent.h>
602 #include <sys/param.h>
603 #include <sys/file.h>
604 #include <unistd.h>
605 #include <libgen.h>
606 #include <err.h>
607 
608 #define S_CARDS_MODE 0755
609 
610 #define WS_NONE 0
611 #define WS_RECURSIVE (1 << 0)
612 #define WS_DEFAULT WS_RECURSIVE
613 #define WS_FOLLOWLINK (1 << 1) /* follow symlinks */
614 #define WS_DOTFILES (1 << 2) /* per unix convention, .file is hidden */
615 #define WS_MATCHDIRS (1 << 3) /* if pattern is used on dir names too */
616 
617 enum {
618  WALK_OK = 0,
619  WALK_BADPATTERN,
620  WALK_NAMETOOLONG,
621  WALK_BADIO
622 };
623 
624 struct InfoFile
625 {
626  std::string url;
627  std::string filename;
628  std::string dirname;
629  std::string md5sum;
630  long int filetime;
631  utimbuf acmodtime;
632  FILE *stream;
633 };
634 
635 struct DirUrl {
636  std::string Dir;
637  std::string Url;
638 };
639 
640 struct Config {
641  Config() {}
642  std::string hostname;
643  std::string database;
644  std::string username;
645  std::string password;
646  std::string socket;
647  std::string collection;
648  std::string name;
649  std::string version;
650  std::string arch;
651  std::string url;
652  std::string logdir;
653  std::vector<std::string> group;
654  std::vector<DirUrl> dirUrl;
655  std::vector<std::string> baseDir;
656  std::vector<std::string> archs;
657 };
658 
659 int getConfig(const char *fileName, Config& config);
660 void * getDatas ( void * var, FILE * file, long offset, size_t size, size_t nmemb);
661 std::string trimFileName(const std::string& filename);
662 time_t getEpochModifyTimeFile(const std::string& filename);
663 std::string getDateFromEpoch(const time_t& epoch);
664 std::string getModifyTimeFile(const std::string& filename);
665 bool checkFileExist(const std::string& filename);
666 bool checkFileEmpty(const std::string& filename);
667 bool checkRegularFile(const std::string& filename);
668 bool checkFileSignature(const std::string& filename, const std::string& signature);
669 bool checkFilesEqual(const std::string& file1, const std::string& file2);
670 bool checkPermissionsEqual(const std::string& file1, const std::string& file2);
671 bool createRecursiveDirs(const std::string& pathname);
672 void cleanupMetaFiles(const std::string& basedir);
673 void removeFile(const std::string& basedir, const std::string& filename);
674 int copyFile(const char * destFile, const char * origFile);
675 int findFile(std::set<std::string>& filesList, const std::string& basedir);
676 int findDir(itemList *filenameList, const char *path);
677 int findRecursiveFile(std::set<std::string>& filenameList, const char *filename, int spec);
678 int readFileStripSpace(itemList *fileContent, const char *fileName);
679 int readFile(itemList *fileContent, const char *fileName);
680 int parseFile(std::set<std::string>& fileContent, const char* fileName);
681 int parseFile(std::vector<std::string>& fileContent, const char* fileName);
682 int parseFile(std::string& Depends, const char* key, const char* fileName);
683 bool findMD5sum(const std::string& fileName, unsigned char* result);
684 bool checkMD5sum(const char * fileName, const char * MD5Sum);
685 /* read a file
686  return it into a template container */
687 template <class T>
688 int parseFile( T& target, const char* fileName)
689 {
690  FILE *fp = fopen (fileName, "r");
691  if (!fp)
692  return -1;
693  const int length = BUFSIZ;
694  char input[length];
695  std::string line;
696  while (fgets(input, length, fp)) {
697  input[strlen(input)-1] = '\0';
698  line = input;
699  target.push_back(line);
700  }
701  fclose(fp);
702  return 0;
703 }
704 
705 
706 
707 
708 
709 #include <archive.h>
710 #include <archive_entry.h>
711 
712 
713 #if ARCHIVE_VERSION_NUMBER >= 3000000
714 #define INIT_ARCHIVE(ar) \
715  archive_read_support_filter_gzip((ar)); \
716  archive_read_support_filter_bzip2((ar)); \
717  archive_read_support_filter_xz((ar)); \
718  archive_read_support_filter_zstd((ar)); \
719  archive_read_support_format_tar((ar))
720 #define FREE_ARCHIVE(ar) \
721  archive_read_free((ar))
722 #else
723 #define INIT_ARCHIVE(ar) \
724  archive_read_support_compression_gzip((ar)); \
725  archive_read_support_compression_bzip2((ar)); \
726  archive_read_support_compression_xz((ar)); \
727  archive_read_support_format_tar((ar))
728 #define FREE_ARCHIVE(ar) \
729  archive_read_finish((ar))
730 #endif
731 
732 #define DEFAULT_BYTES_PER_BLOCK (20 * 512)
733 #define METAFILE ".META"
734 #define INFOFILE ".INFO"
735 #define MTREEFILE ".MTREE"
736 
737 enum archive_error
738 {
739 CANNOT_OPEN_ARCHIVE,
740 CANNOT_READ_ARCHIVE,
741 CANNOT_FIND_META_FILE,
742 CANNOT_FIND_MTREE_FILE,
743 CANNOT_FIND_NAME,
744 CANNOT_FIND_ARCH,
745 EMPTY_ARCHIVE
746 };
747 
748 
749 class ArchiveUtils
750 {
751  public:
752 
753 
754  ArchiveUtils(const std::string& fileName);
755  virtual ~ArchiveUtils();
756 
757  virtual void treatErrors(const std::string& s) const;
758 
759  void printDeps(); // Print Out the dependencies
760  void printMeta(); // Print Out the .META file
761  void printInfo(); // the .INFO file
762  void list(); // list the files to stdio
763 
764 
765  unsigned int long size(); // Numbers of files in the archive
766  std::set<std::string> setofFiles(); // return a order set of string
767  std::set<std::string> listofDependencies(); // return an order set of dependencies
768  std::set<std::string> listofAlias(); // return the alias list
769  std::set<std::pair<std::string,time_t> > listofDependenciesBuildDate(); // return an order set of dependencies,BuildDate
770  std::string arch(); // return the arch of the package
771  std::string version(); // return the version of the package
772  int release(); // return the release of the package
773  std::string description();// return the description of the package
774  std::string url(); // return the url of the package
775  std::string contributors(); // return the Contributor(s) of the package
776  std::string maintainer(); // return the Maintainer(s) of the package
777  std::string collection(); // return the collection of the package
778  std::string packager(); // return the Packager(s) of the package
779  std::string builddate(); // return the date like Mon Mar 24 10:16:00 2014
780  std::string name(); // return the name of the package
781  std::string group(); // return the group of the package
782  std::string namebuildn(); // return the name + epochvalue
783  std::string epochBuildDate(); // return the epochvalue in string format
784  time_t buildn(); // return the epoch value
785 
786  private:
787 
788  std::string getPackageName();
789  std::string getPackageArch();
790  std::vector<std::string> extractFileContent(const char * fileName);
791  void getRunTimeDependencies();
792  void getRunTimeDependenciesEpoch();
793  void getAliasList();
794 
795  unsigned int long m_size;
796 
797  std::vector<std::string> m_contentMtree;
798  std::vector<std::string> m_contentMeta;
799  std::vector<std::string> m_contentInfo;
800 
801  std::set<std::string> m_rtDependenciesList;
802  std::set<std::pair<std::string,time_t> > m_rtDependenciesEpochList;
803  std::string m_fileName;
804  std::string m_packageName;
805  std::string m_packageArch;
806  std::set<std::string> m_filesList;
807  std::set<std::string> m_aliasList;
808 
809  archive_error m_actualError;
810 };
811 
812 int openArchive(const char *fileName);
813 
814 /*
815  * pkg.h
816  *
817  * Copyright 2017 - 2020 NuTyX <tnut@nutyx.org>
818  *
819  * This program is free software; you can redistribute it and/or modify
820  * it under the terms of the GNU General Public License as published by
821  * the Free Software Foundation; either version 2 of the License, or
822  * (at your option) any later version.
823  *
824  * This program is distributed in the hope that it will be useful,
825  * but WITHOUT ANY WARRANTY; without even the implied warranty of
826  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
827  * GNU General Public License for more details.
828  *
829  * You should have received a copy of the GNU General Public License
830  * along with this program; if not, write to the Free Software
831  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
832  * MA 02110-1301, USA.
833  *
834  *
835  */
836 
837 #define PKG_H
838 
839 #include <string>
840 
841 enum CPSTATUS
842 {
843  INSTALLED = 0x01,
844  TO_INSTALL = 0x02,
845  TO_REMOVE = 0x04,
846  TO_UPGRADE = 0x08
847 };
848 
849 class Pkg
850 {
851 public:
852  Pkg();
853  ~Pkg();
854  std::string getCollection();
855  std::string getName();
856  std::string getVersion();
857  std::string getPackager();
858  std::string getDescription();
859  void setName(std::string& name);
860  void setDescription(std::string& description);
861  void setVersion(std::string& version);
862  void setCollection(std::string& collection);
863  void setPackager(std::string& packager);
864  bool isInstalled();
865  bool isToBeInstalled();
866  bool isToBeRemoved();
867  void setStatus(CPSTATUS pstatus);
868  void unSetStatus(CPSTATUS pstatus);
869  CPSTATUS getStatus();
870 
871 private:
872  std::string m_collection;
873  std::string m_name;
874  std::string m_version;
875  std::string m_packager;
876  std::string m_description;
877  CPSTATUS m_status;
878 };
879 
880 
881 
882 
884  std::string md5SUM;
885  std::string name;
886  std::string arch;
887 };
888 
895 /*
896  **************************************************
897  * 73193bfc1cb30fe02a880ed088ed7590#1414192958#aalib#1.4rc5##n.a#n.a#n.a#n.a#.cards.tar.xz
898  * 650ed499ce78791d45b91aaf7f91b445#1428615787#firefox#37.0.1#1#Standalone web browser from mozilla.org#http://www.mozilla.com/firefox/#n.a#pierre at nutyx dot org,tnut at nutyx dot org#.cards.tar.xz
899  *************************************************
900  */
902  std::string md5SUM;
903  std::string s_buildDate;
904  std::string basePackageName;
905  std::string extention;
906  std::string version;
907  int release;
908  std::string description;
909  std::string categories;
910  std::string URL;
911  std::string contributors;
912  std::string maintainer;
913  std::string packager;
914  std::string fileDate;
915  std::string alias;
916  std::string set;
917  std::string group;
918  time_t buildDate;
919  std::vector<PortFilesList> portFilesList;
920 };
921 
923  std::string Dir;
924  std::string Url;
925  std::vector<BasePackageInfo> basePackageList;
926 };
930 struct RepoInfo {
931  std::string branch;
932  std::string arch;
933  std::string collection;
934  std::vector<BasePackageInfo> basePackageList;
935 };
936 
937 class Pkgrepo
938 {
939 public:
940 
941  Pkgrepo(const std::string& fileName);
942  virtual ~Pkgrepo() { clearPackagesList(); }
943 
944  static int parseConfig(const char *fileName,
945  Config& config);
946 
947  void throwError(const std::string& s) const;
948 
959  std::set<std::string> getListOutOfDate();
960 
965  std::string getPortDir (const std::string& portName);
966 
967 
973  std::string getBasePortName (const std::string& portName);
978  std::string getBasePackageName(const std::string& packageName);
984  std::string getBasePackageVersion(const std::string& packageName);
988  std::string getPortVersion (const std::string& portName);
989 
994  int getBasePackageRelease (const std::string& packageName);
995 
999  int getPortRelease(const std::string& portName);
1003  bool checkPortExist(const std::string& portName);
1004 
1008  std::set<std::string> getListOfPackagesFromCollection(const std::string& collectionName);
1009 
1013  std::set<std::string> getListOfPackagesFromSet(const std::string& collectionName);
1014 
1018  time_t getBinaryBuildTime (const std::string& portName);
1019 
1024  std::set<std::string> getBinaryPackageList();
1025 
1030  std::set<Pkg*> getBinaryPackageSet();
1035  std::vector<RepoInfo> getRepoInfo();
1041  unsigned int getPortsList();
1042 
1043  bool getBinaryPackageInfo(const std::string& packageName);
1044  bool getPortInfo(const std::string& portName);
1045 
1046 protected:
1051  int parseConfig(const char *fileName);
1052 
1066 
1077  void parseCollectionDirectory();
1078 
1091 
1097  void parsePackagePkgfileFile();
1098 
1099 
1100  bool m_parsePkgRepoCollectionFile;
1101  bool m_parseCollectionDirectory;
1102  bool m_parsePackagePkgfileFile;
1103 
1104  std::vector<PortsDirectory>::iterator m_PortsDirectory_i;
1105  std::vector<BasePackageInfo>::iterator m_BasePackageInfo_i;
1106  std::vector<PortFilesList>::iterator m_PortFilesList_i;
1107 
1108  std::vector<PortFilesList> m_portFilesList;
1109 
1110  std::string m_configFileName;
1111  Config m_config;
1112 
1113  std::vector<PortsDirectory> m_portsDirectoryList;
1114 private:
1115  error m_ErrorCond;
1116  void clearPackagesList();
1117  std::set<Pkg*> m_packagesList;
1118 };
1119 #define REPODWL_H
1120 
1121 
1122 class Repodwl: public Pkgrepo {
1123 public:
1124  Repodwl(const char *fileName);
1135  void downloadPortsPkgRepo(const std::string& packageName);
1136 
1147  void downloadPackageFileName(const std::string& packageName);
1148  bool checkBinaryExist(const std::string& packageName);
1149  std::string getPackageFileName(const std::string& packageName);
1150  std::string getPackageFileNameSignature(const std::string& packageName);
1151 
1152  void setPackageFileName(const std::string& packageFileNmae);
1153 
1154 private:
1155  std::string m_packageFileName;
1156  std::string m_packageFileNameSignature;
1157 };
1158 
1165 #include <curl/curl.h>
1166 
1167 
1168 
1177 class FileDownloadState
1178 {
1179  public:
1180  double dlnow;
1181  double dltotal;
1182  double dlspeed;
1183  std::string filename;
1184 };
1185 
1186 class FileDownload;
1187 
1196 class FileDownloadEvent
1197 {
1198  friend FileDownload;
1199 public:
1201  ~FileDownloadEvent();
1202 
1203  protected:
1204 
1211 };
1212 
1221 class FileDownload
1222 {
1223  public:
1224 
1233  FileDownload(std::string url, std::string dirName, std::string fileName, bool progress);
1234 
1244  FileDownload(std::string fileInfo, std::string url, std::string dirName, std::string fileName, std::string MD5Sum , bool progress);
1245 
1253  FileDownload(std::vector<InfoFile> destinationFiles,bool progress);
1254 
1259  {
1260  curl_slist_free_all(m_slist);
1261  curl_global_cleanup();
1262  curl_easy_cleanup(m_curl);
1263  }
1264 
1265  static void SuscribeToEvents(FileDownloadEvent* callback);
1266  static void UnSuscribeFromEvents(FileDownloadEvent* callback);
1267 
1268 
1269  private:
1270 
1274  bool checkMD5sum();
1275 
1279  void downloadFile();
1280 
1281  static int updateProgressHandle(void *p, double dltotal, double dlnow, double ultotal, double ulnow);
1282  static size_t writeToStreamHandle(void *buffer, size_t size, size_t nmemb, void *stream);
1283  int updateProgress(void *p, double dltotal, double dlnow, double ultotal, double ulnow);
1284  size_t writeToStream(void *buffer, size_t size, size_t nmemb, void *stream);
1285  void initFileToDownload(std::string _url, std::string _file);
1286 
1290  bool checkUpToDate();
1291  void SendProgressEvent(FileDownloadState event);
1292  struct dwlProgress
1293  {
1294  std::string name;
1295  double lastruntime;
1296  CURL *curl;
1297  };
1298  struct curl_slist *m_slist;
1299 
1300  CURL* m_curl;
1301  CURLcode m_curlCode;
1302  dwlProgress m_downloadProgress;
1303  InfoFile m_destinationFile;
1304  std::string m_url;
1305  std::string m_downloadFileName;
1306  std::string m_fileInfo;
1307  bool m_checkMD5;
1308  bool m_progress;
1309  std::string m_MD5Sum;
1310  static std::set<FileDownloadEvent*> m_arrCallBacks;
1311 };
1312 
1313 
1314 
1315 
1316 #include <list>
1317 #include <cassert>
1318 #include <cstddef>
1319 #include <cstdlib>
1320 #include <cstdio>
1321 
1322 #include <unistd.h>
1323 #include <fcntl.h>
1324 #include <sys/types.h>
1325 #include <sys/wait.h>
1326 
1327 
1336 class process
1337 {
1338 public:
1339  process();
1340  process( const std::string& app, const std::string& args, int fileDescriptorLog=0 );
1341 
1342  void execute(const std::string& app, const std::string& arguments, int fileDescriptorLog=0 );
1343 
1348  int execute();
1349 
1354  int executeShell();
1355 
1359  std::string name();
1360 
1364  std::string args();
1365 
1366 private:
1367 
1368  int exec(const int argc, char** argv);
1369  int execLog(const int argc, char** argv);
1370 
1371  int execShell(const char* shell);
1372  int execShellLog(const char* shell);
1373 
1374  std::string m_application;
1375  std::string m_arguments;
1376  int m_fileDescriptorLog;
1377 };
1378 
1379 
1380 
1381 
1382 #include <stdio.h>
1383 #include <stdlib.h>
1384 #include <string.h>
1385 #include <unistd.h>
1386 #include <sys/stat.h>
1387 
1388 
1389 int getRuntimeLibrariesList (std::set<std::string>& runtimeLibrariesList, const std::string& filename);
1390 
1391 
1398 #include <stdexcept>
1399 #include <csignal>
1400 #include <algorithm>
1401 
1402 #include <regex.h>
1403 #include <ext/stdio_filebuf.h>
1404 #include <pwd.h>
1405 #include <grp.h>
1406 
1407 
1408 
1409 #define LDCONFIG "sbin/ldconfig"
1410 #define LDCONFIG_CONF "etc/ld.so.conf"
1411 #define LDCONFIG_CONF_ARGS "-r "
1412 #define SHELL "bin/sh"
1413 
1414 #define INSTALL_INFO "usr/bin/install-info"
1415 #define INSTALL_INFO_ARGS "--info-dir=usr/share/info "
1416 
1417 #define UPDATE_ICON "usr/bin/gtk-update-icon-cache"
1418 #define UPDATE_ICON_ARGS "-f -t "
1419 
1420 #define COMPILE_SCHEMAS "usr/bin/glib-compile-schemas"
1421 #define COMPILE_SCHEMAS_ARGS ""
1422 
1423 #define UPDATE_DESKTOP_DB "usr/bin/update-desktop-database"
1424 #define UPDATE_DESKTOP_DB_ARGS "-q "
1425 
1426 #define UPDATE_MIME_DB "usr/bin/update-mime-database"
1427 #define UPDATE_MIME_DB_ARGS "-n "
1428 
1429 #define GDK_PIXBUF_QUERY_LOADER "usr/bin/gdk-pixbuf-query-loaders"
1430 #define GDK_PIXBUF_QUERY_LOADER_ARGS "--update-cache"
1431 
1432 #define GIO_QUERYMODULES "usr/bin/gio-querymodules"
1433 #define GIO_QUERYMODULES_ARGS "usr/lib/gio/modules"
1434 
1435 #define QUERY_IMMODULES_3 "usr/bin/gtk-query-immodules-3.0"
1436 #define QUERY_IMMODULES_3_ARGS "--update-cache"
1437 
1438 #define QUERY_IMMODULES_2 "usr/bin/gtk-query-immodules-2.0"
1439 #define QUERY_IMMODULES_2_ARGS "--update-cache"
1440 
1441 #define MKFONTDIR "usr/bin/mkfontdir"
1442 #define MKFONTDIR_ARGS ""
1443 
1444 #define MKFONTSCALE "usr/bin/mkfontscale"
1445 #define MKFONTSCALE_ARGS ""
1446 
1447 #define FC_CACHE "usr/bin/fc-cache"
1448 #define FC_CACHE_ARGS ""
1449 
1450 enum action
1451 {
1452 PKG_DOWNLOAD_START,
1453 PKG_DOWNLOAD_RUN,
1454 PKG_DOWNLOAD_END,
1455 DB_OPEN_START,
1456 DB_OPEN_RUN,
1457 DB_OPEN_END,
1458 PKG_PREINSTALL_START,
1459 PKG_PREINSTALL_END,
1460 PKG_INSTALL_START,
1461 PKG_INSTALL_END,
1462 PKG_INSTALL_RUN,
1463 PKG_POSTINSTALL_START,
1464 PKG_POSTINSTALL_END,
1465 PKG_MOVE_META_START,
1466 PKG_MOVE_META_END,
1467 DB_ADD_PKG_START,
1468 DB_ADD_PKG_END,
1469 LDCONFIG_START,
1470 LDCONFIG_END,
1471 RM_PKG_FILES_START,
1472 RM_PKG_FILES_RUN,
1473 RM_PKG_FILES_END
1474 };
1475 
1476 struct pkginfo_t {
1477  std::string group;
1478  std::string collection;
1479  std::string description;
1480  std::string signature;
1481  time_t build; // date of build
1482  std::string version;
1483  int release;
1484  std::string url;
1485  std::string contributors;
1486  std::string packager;
1487  std::string maintainer;
1488  time_t install; // date of last installation
1489  std::string arch;
1490  int size;
1491  bool dependency; // true it's a dependency: automaticaly install
1492  std::set< std::pair<std::string,time_t> > dependencies;
1493  std::set<std::string> alias;
1494  std::set<std::string> set;
1495  std::set<std::string> categories;
1496  std::set<std::string> files;
1497 };
1498 typedef std::map<std::string, pkginfo_t> packages_t;
1499 typedef std::map<std::string, std::string> alias_t;
1500 
1501 enum rule_event_t {
1502  LDCONF,
1503  UPGRADE,
1504  INSTALL,
1505  INFO,
1506  ICONS,
1507  FONTS,
1508  SCHEMAS,
1509  DESKTOP_DB,
1510  MIME_DB,
1511  QUERY_PIXBUF,
1512  GIO_QUERY,
1513  QUERY_IMOD3,
1514  QUERY_IMOD2
1515 };
1516 
1517 struct rule_t {
1518  rule_event_t event;
1519  std::string pattern;
1520  bool action;
1521 };
1522 
1523 class Pkgdbh {
1524 public:
1525 
1526  explicit Pkgdbh(const std::string& name);
1527  virtual ~Pkgdbh();
1528 
1529  /* Following methods can be redefined in derivated class */
1530  virtual void parseArguments(int argc, char** argv);
1531  virtual void run(int argc, char** argv) {};
1532  virtual void run() {};
1533 
1534  virtual void printHelp() const {};
1535 
1536  virtual void progressInfo();
1537  virtual void treatErrors(const std::string& s) const;
1538 
1539 
1540  void print_version() const;
1541  int getNumberOfPackages();
1542  std::set<std::string> getListOfPackageName();
1543 
1544  bool checkPackageNameExist(const std::string& name) const;
1545  bool checkDependency(const std::string& name);
1546  void setDependency();
1547  void resetDependency();
1548 
1549  unsigned int getFilesNumber();
1550  unsigned int getInstalledFilesNumber();
1551  std::set<std::string> getFilesList();
1552 
1553 protected:
1554  // Database
1555 
1556  std::set<std::string> getFilesOfPackage(const std::string& packageName);
1557  int getListOfPackageNames(const std::string& path);
1558  std::pair<std::string, pkginfo_t> getInfosPackage(const std::string& packageName);
1559  void buildSimpleDatabase();
1561 
1562  void buildCompleteDatabase(const bool& silent);
1563  void buildDatabase(const bool& progress,
1564  const bool& simple,
1565  const bool& all,
1566  const bool& files,
1567  const std::string& packageName);
1568 
1569 
1570  void addPackageFilesRefsToDB(const std::string& name,
1571  const pkginfo_t& info);
1572 
1573  bool checkPackageNameUptodate(const std::pair<std::string,
1574  pkginfo_t>& archiveName);
1575  bool checkPackageNameBuildDateSame(const std::pair<std::string,
1576  time_t>& dependencieNameBuild);
1577 
1578  /*
1579  * Remove the physical files after followings some rules
1580  */
1581  void removePackageFiles(const std::string& name);
1582  void removePackageFiles(const std::string& name,
1583  const std::set<std::string>& keep_list);
1584 
1585  /*
1586  * Remove meta data about the removed package
1587  */
1588  void removePackageFilesRefsFromDB(const std::string& name);
1589  void removePackageFilesRefsFromDB(std::set<std::string> files,
1590  const std::set<std::string>& keep_list);
1591  std::set<std::string> getConflictsFilesList(const std::string& name,
1592  const pkginfo_t& info);
1593 
1594  // Tar.gz
1595  std::pair<std::string, pkginfo_t> openArchivePackage(const std::string& filename);
1596  std::set< std::pair<std::string, time_t> > getPackageDependencies(const std::string& filename);
1597  void extractAndRunPREfromPackage(const std::string& filename);
1598  void installArchivePackage(const std::string& filename,
1599  const std::set<std::string>& keep_list,
1600  const std::set<std::string>& non_install_files);
1601 
1602  /*
1603  * The folder holding the meta datas is going to be create here
1604  */
1605  void moveMetaFilesPackage(const std::string& name, pkginfo_t& info);
1606 
1607 
1608  void readRulesFile();
1609  void getInstallRulesList(const std::vector<rule_t>& rules,
1610  rule_event_t event, std::vector<rule_t>& found) const;
1611  bool checkRuleAppliesToFile(const rule_t& rule,
1612  const std::string& file);
1613 
1614  void getFootprintPackage(std::string& filename);
1615 
1616  std::string m_packageArchiveName;
1617  std::string m_packageName;
1618  std::string m_packageArchiveVersion;
1619  std::string m_packageArchiveRelease;
1620  std::string m_packageArchiveCollection;
1621  std::string m_packageVersion;
1622  std::string m_packageRelease;
1623  std::string m_packageCollection;
1624  std::string m_utilName;
1625  std::string m_root;
1626  std::string m_build;
1627  std::vector<rule_t> m_actionRules;
1628  std::set< std::pair<std::string, int> > m_postInstallList;
1629  alias_t m_listOfAlias;
1630 
1631  packages_t m_listOfInstPackages;
1632  packages_t m_listOfDepotPackages;
1633 
1634  std::set<std::pair<std::string,std::set<std::string> > > m_listOfInstalledPackagesWithDeps;
1635 
1636  action m_actualAction;
1637  error m_actualError;
1638 
1639 private:
1640 
1641  void runLastPostInstall();
1642 
1643  std::set<std::string> m_runtimeLibrariesList;
1644  std::set<std::string> m_filesList;
1645  std::set<std::string> m_packageNamesList;
1646  unsigned int m_filesNumber;
1647  unsigned int m_installedFilesNumber;
1648 
1649  bool m_dependency;
1650 
1651  bool m_DB_Empty;
1652  bool m_miniDB_Empty;
1653 };
1654 
1655 class Db_lock {
1656 public:
1657  Db_lock(const std::string& m_root, bool exclusive);
1658  ~Db_lock();
1659 
1660 private:
1661  DIR* m_dir;
1662  struct sigaction m_sa;
1663 };
1664 
1665 void assertArgument(char** argv, int argc, int index);
1666 void rotatingCursor();
1667 
1681 class Pkgadd : public Pkgdbh {
1682 public:
1686  Pkgadd();
1692  Pkgadd(const std::string& commandName);
1693  void parseArguments(int argc, char** argv);
1694  void preRun();
1695  void postRun();
1696  virtual void run();
1697  virtual void run(int argc, char** argv);
1698  virtual void printHelp() const;
1699 
1700 protected:
1701  bool m_runPrePost;
1702  bool m_upgrade;
1703  bool m_force;
1704 private:
1705  std::set<std::string> getKeepFileList(const std::set<std::string>& files,
1706  const std::vector<rule_t>& rules);
1707  std::set<std::string> applyInstallRules(const std::string& name,
1708  pkginfo_t& info,
1709  const std::vector<rule_t>& rules);
1710  void applyPostInstallRules(const std::string& name,
1711  pkginfo_t& info,
1712  const std::vector<rule_t>& rules);
1713  void getInstallRulesList(const std::vector<rule_t>& rules,
1714  rule_event_t event,
1715  std::vector<rule_t>& found) const;
1716  void getPostInstallRulesList(const std::vector<rule_t>& rules,
1717  std::vector<rule_t>& found) const;
1718 };
1719 
1726 class Pkgrm : public Pkgdbh {
1727 public:
1728  Pkgrm(const std::string& commandName) : Pkgdbh(commandName) {}
1729  Pkgrm();
1730  void run();
1731  void run(int argc, char** argv);
1732  void printHelp() const;
1733 
1734 protected:
1735  void getListOfManInstalledPackages ();
1736  std::set<std::string> m_listOfManInstalledPackages;
1737  std::set<std::string> m_listofDependencies;
1738 private:
1739  void getDirectDependencies(std::string& name);
1740 
1741 };
1742 
1743 
1750 #include <sstream>
1751 #include <iomanip>
1752 
1753 
1754 class Pkginfo : public Pkgdbh {
1755 public:
1756  Pkginfo(const std::string& commandName);
1757  Pkginfo();
1758  virtual void run(int argc, char** argv);
1759  virtual void parseArguments(int argc, char** argv);
1760  virtual void run();
1761  virtual void finish();
1762  virtual void printHelp() const;
1763 
1764 protected:
1765  std::string m_arg;
1766  int m_runtimedependencies_mode;
1767  int m_footprint_mode;
1768  int m_archiveinfo;
1769  int m_installed_mode;
1770  int m_list_mode;
1771  int m_owner_mode;
1772  int m_details_mode;
1773  int m_libraries_mode;
1774  int m_runtime_mode;
1775  int m_epoc;
1776  bool m_fulllist_mode;
1777 
1778 };
1779 
1780 
1781 
1782 
1783 
1784 class Pkginst : public Pkgadd, public Repodwl {
1785 public:
1786  Pkginst(const std::string& commandName, const char *configFileName);
1787  void generateDependencies(const std::pair<std::string,time_t>& packageName);
1788  void generateDependencies();
1789 
1790 protected:
1791  std::vector< std::pair<std::string,time_t> > m_dependenciesList;
1792 };
1793 
1794 
1795 #include <cstring>
1796 #include <cstdlib>
1797 #include <iostream>
1798 
1799 
1800 #include <curl/curl.h>
1801 #include <sys/types.h>
1802 #include <sys/stat.h>
1803 #include <unistd.h>
1804 #include <libgen.h>
1805 #include <dirent.h>
1806 
1807 class Pkgsync
1808 {
1809 public:
1814  Pkgsync();
1815  Pkgsync(const std::string& url,
1816  const std::string& directory,
1817  const std::string& repoFile);
1818 
1819  virtual void treatErrors(const std::string& s) const;
1820 
1821  virtual void run();
1822  virtual void purge();
1823  static const std::string DEFAULT_REPOFILE;
1824 
1825  void setRootPath(const std::string& path);
1826  void setConfigFile(const std::string& file);
1827 
1828 private:
1829 
1830  unsigned int getLocalPackages(const std::string& path);
1831  unsigned int getRemotePackages(const std::string& pkgrepoFile);
1832 
1833  void deleteFolder(const std::string& folderName);
1834 
1835  std::set<std::string> m_localPackagesList;
1836  std::set<std::string> m_remotePackagesList;
1837  const std::string m_baseDirectory;
1838  const std::string m_remoteUrl;
1839  std::string m_repoFile;
1840  std::string m_root;
1841  std::string m_configFile;
1842  error m_actualError;
1843 
1844 
1845 };
1846 
1847 #endif
1848 // vim:set ts=2 :
Pkgrm
Definition: libcards.h:1726
pkginfo_t
Definition: libcards.h:1476
Pkgdbh::buildSimpleDependenciesDatabase
void buildSimpleDependenciesDatabase()
Definition: pkgdbh.cxx:475
Pkgrepo::getPortVersion
std::string getPortVersion(const std::string &portName)
Pkg
Definition: libcards.h:850
RunTimeErrorWithErrno
Definition: error_treat.h:91
Db_lock
Definition: libcards.h:1655
itemList
Definition: libcards.h:484
Pkgrepo::getBasePackageName
std::string getBasePackageName(const std::string &packageName)
Pkgrepo::getListOutOfDate
std::set< std::string > getListOutOfDate()
Definition: pkgrepo.cxx:281
Pkgdbh::buildSimpleDatabase
void buildSimpleDatabase()
Definition: pkgdbh.cxx:506
process
Definition: libcards.h:1337
Pkgsync
Definition: libcards.h:1808
Pkgadd::Pkgadd
Pkgadd()
Definition: pkgadd.cxx:28
process::executeShell
int executeShell()
Definition: process.cxx:175
DirUrl
Definition: file_utils.h:64
Pkg::~Pkg
~Pkg()
Destructor.
Definition: pkg.cxx:35
Repodwl::downloadPortsPkgRepo
void downloadPortsPkgRepo(const std::string &packageName)
Pkgrepo::getBasePackageRelease
int getBasePackageRelease(const std::string &packageName)
process::execute
int execute()
Definition: process.cxx:59
FileDownload
File Download class.
Definition: file_download.h:90
BasePackageInfo
Definition: libcards.h:901
Pkgrepo::checkPortExist
bool checkPortExist(const std::string &portName)
ArchiveUtils
Definition: archive_utils.h:69
Pkginst
Definition: libcards.h:1784
FileDownloadEvent
File Download Event class.
Definition: file_download.h:65
Pkgrepo::getPortRelease
int getPortRelease(const std::string &portName)
Pkgdbh::buildDatabase
void buildDatabase(const bool &progress, const bool &simple, const bool &all, const bool &files, const std::string &packageName)
Definition: pkgdbh.cxx:361
RepoInfo
Definition: libcards.h:930
Pkgrepo::getPortDir
std::string getPortDir(const std::string &portName)
Definition: pkgrepo.cxx:619
rule_t
Definition: libcards.h:1517
Pkgrepo::getListOfPackagesFromCollection
std::set< std::string > getListOfPackagesFromCollection(const std::string &collectionName)
Pkgdbh::buildCompleteDatabase
void buildCompleteDatabase(const bool &silent)
Definition: pkgdbh.cxx:572
Pkgsync::Pkgsync
Pkgsync()
Definition: pkgsync.cxx:26
Pkgrepo::parsePackagePkgfileFile
void parsePackagePkgfileFile()
Definition: pkgrepo.cxx:298
PortFilesList
Definition: libcards.h:883
process::args
std::string args()
Definition: process.cxx:55
keyValue
Definition: libcards.h:475
process::name
std::string name()
Definition: process.cxx:51
PortsDirectory
Definition: libcards.h:922
Config
Definition: file_utils.h:69
FileDownloadEvent::OnFileDownloadProgressInfo
virtual void OnFileDownloadProgressInfo(FileDownloadState state)
Definition: libcards.h:1210
Pkgrepo
Definition: libcards.h:938
Pkgrepo::getBasePackageVersion
std::string getBasePackageVersion(const std::string &packageName)
Pkgrepo::getBasePortName
std::string getBasePortName(const std::string &portName)
md5_context
Definition: libcards.h:446
FileDownload::~FileDownload
~FileDownload()
Definition: libcards.h:1258
Pkg::Pkg
Pkg()
Constructor.
Definition: pkg.cxx:29
InfoFile
Definition: file_utils.h:54
Pkgrepo::getBinaryPackageList
std::set< std::string > getBinaryPackageList()
Definition: pkgrepo.cxx:404
Repodwl::downloadPackageFileName
void downloadPackageFileName(const std::string &packageName)
Pkg::getCollection
std::string getCollection()
Return.
Definition: pkg.cxx:61
Pkgrepo::parseCurrentPackagePkgRepoFile
void parseCurrentPackagePkgRepoFile()
Definition: pkgrepo.cxx:213
Pkgrepo::getBinaryPackageSet
std::set< Pkg * > getBinaryPackageSet()
Definition: pkgrepo.cxx:445
Pkgrepo::parseCollectionDirectory
void parseCollectionDirectory()
Definition: pkgrepo.cxx:185
FileDownloadState
File Download State class.
Definition: file_download.h:46
Pkgrepo::getBinaryBuildTime
time_t getBinaryBuildTime(const std::string &portName)
FileDownload::FileDownload
FileDownload(std::string fileInfo, std::string url, std::string dirName, std::string fileName, std::string MD5Sum, bool progress)
Pkgdbh
Definition: libcards.h:1523
Pkgrepo::parsePkgRepoCollectionFile
void parsePkgRepoCollectionFile()
Definition: pkgrepo.cxx:52
Pkgrepo::getPortsList
unsigned int getPortsList()
Definition: pkgrepo.cxx:510
FileDownload::FileDownload
FileDownload(std::vector< InfoFile > destinationFiles, bool progress)
Repodwl
Definition: libcards.h:1122
Pkginfo
Definition: libcards.h:1754
Pkgadd
Pkgadd class.
Definition: libcards.h:1681
FileDownload::FileDownload
FileDownload(std::string url, std::string dirName, std::string fileName, bool progress)
Pkgrepo::getRepoInfo
std::vector< RepoInfo > getRepoInfo()
Definition: pkgrepo.cxx:480
Pkgrepo::getListOfPackagesFromSet
std::set< std::string > getListOfPackagesFromSet(const std::string &collectionName)