Click
Loading...
Searching...
No Matches
archive.hh
Go to the documentation of this file.
1// -*- c-basic-offset: 4; related-file-name: "../../lib/archive.cc" -*-
2#ifndef CLICK_ARCHIVE_HH
3#define CLICK_ARCHIVE_HH
4#include <click/string.hh>
5#include <click/vector.hh>
6#include <click/error.hh>
7CLICK_DECLS
8class ErrorHandler;
9
22
24 int date;
25 int uid;
26 int gid;
27 int mode;
29
31 bool live() const {
32 return name;
33 }
34
36 void kill() {
37 name = String();
38 }
39
45 static int parse(const String &str, Vector<ArchiveElement> &ar,
46 ErrorHandler *errh = 0);
47
52 static String unparse(const Vector<ArchiveElement> &ar,
53 ErrorHandler *errh = 0);
54
60 for (ArchiveElement *ae = ar.begin(); ae != ar.end(); ++ae)
61 if (ae->name == name)
62 return ae;
63 return 0;
64 }
65
67 static const ArchiveElement *find(const Vector<ArchiveElement> &ar, const String &name) {
68 for (const ArchiveElement *ae = ar.begin(); ae != ar.end(); ++ae)
69 if (ae->name == name)
70 return ae;
71 return 0;
72 }
73
74 static int extract(const Vector<ArchiveElement> &ar, const String &name, const String &dest, ErrorHandler* errh = 0) {
75 const ArchiveElement *ae = find(ar, name);
76 FILE *f = fopen(dest.c_str(), "wb");
77 if (!f) {
78 if (errh)
79 errh->error("%s: %s", name.c_str(), strerror(errno));
80 return -1;
81 }
82 int r = fwrite(ae->data.c_str(), 1, ae->data.length(), f);
83 fclose(f);
84 return r >= 0;
85 }
86
87};
88
89CLICK_ENDDECLS
90#endif
Error reporting class.
Definition error.hh:90
A string of characters.
Definition string.hh:22
int length() const
Return the string's length.
Definition string.hh:509
const char * c_str() const
Null-terminate the string.
Definition string.hh:519
Vector template.
Definition vector.hh:111
iterator end()
Return an iterator for the end of the vector.
Definition vector.hh:266
iterator begin()
Return an iterator for the first element in the vector.
Definition vector.hh:253
Flexible error handling classes.
Click's String class.
Member of an 'ar' archive.
Definition archive.hh:21
static const ArchiveElement * find(const Vector< ArchiveElement > &ar, const String &name)
Definition archive.hh:67
static int parse(const String &str, Vector< ArchiveElement > &ar, ErrorHandler *errh=0)
Parse a string into a vector of ArchiveElement objects.
Definition archive.cc:62
int date
Decimal seconds since the epoch (1/1/1970)
Definition archive.hh:24
int uid
User ID of member.
Definition archive.hh:25
bool live() const
Return true iff the member should be included in an archive.
Definition archive.hh:31
static String unparse(const Vector< ArchiveElement > &ar, ErrorHandler *errh=0)
Unparse a vector of ArchiveElement objects into a string.
Definition archive.cc:155
String data
Member contents.
Definition archive.hh:28
String name
Member name (no slashes allowed)
Definition archive.hh:23
int gid
Group ID of member.
Definition archive.hh:26
int mode
File mode.
Definition archive.hh:27
static ArchiveElement * find(Vector< ArchiveElement > &ar, const String &name)
Locate an ArchiveElement in an archive by name.
Definition archive.hh:59
void kill()
Kill a member, preventing it from being archived.
Definition archive.hh:36
Click's vector container template.