Initial commit.

This commit is contained in:
uroni 2011-01-06 17:43:38 +01:00
commit 89e10b3f04
520 changed files with 198431 additions and 0 deletions

8
AUTHORS Normal file
View File

@ -0,0 +1,8 @@
AUTHORS AND MAINTAINERS:
MAIN DEVELOPER:
Martin Raiber <Martin@urbackup.org>
PROJECT COORDINATOR:
Martin Raiber <Martin@urbackup.org>

184
AcceptThread.cpp Normal file
View File

@ -0,0 +1,184 @@
/*************************************************************************
* UrBackup - Client/Server backup system
* Copyright (C) 2011 Martin Raiber
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
**************************************************************************/
#include "vld.h"
#include <boost/thread/thread.hpp>
#include <boost/bind.hpp>
#include "AcceptThread.h"
#include "Server.h"
#include "stringtools.h"
#include "SelectThread.h"
#include "Client.h"
#include <memory.h>
#ifndef _WIN32
#include <errno.h>
#endif
extern bool run;
OutputCallback::OutputCallback(SOCKET fd_)
{
fd=fd_;
}
OutputCallback::~OutputCallback()
{
closesocket(fd);
}
void OutputCallback::operator() (const void* buf, size_t count)
{
int rc;
rc = send(fd, (const char*)buf, (int)count, MSG_NOSIGNAL);
if (rc < 0)
Server->Log("Send failed in OutputCallback");
}
CAcceptThread::CAcceptThread( unsigned int nWorkerThreadsPerMaster, unsigned short int uPort )
{
WorkerThreadsPerMaster=nWorkerThreadsPerMaster;
Server->Log("Creating SOCKET...",LL_INFO);
s=socket(AF_INET,SOCK_STREAM,0);
if(s<1)
{
Server->Log("Creating SOCKET failed",LL_ERROR);
return;
}
Server->Log("done.",LL_INFO);
sockaddr_in addr;
memset(&addr, 0, sizeof(sockaddr_in));
addr.sin_family=AF_INET;
addr.sin_port=htons(uPort);
addr.sin_addr.s_addr=INADDR_ANY;
int rc=bind(s,(sockaddr*)&addr,sizeof(addr));
if(rc==SOCKET_ERROR)
{
Server->Log("Failed binding SOCKET to Port "+nconvert(uPort),LL_ERROR);
return;
}
listen(s, 10000);
Server->Log("Server started up sucessfully!",LL_INFO);
}
CAcceptThread::~CAcceptThread()
{
closesocket(s);
Server->Log("Deleting SelectThreads..");
for(size_t i=0;i<SelectThreads.size();++i)
{
delete SelectThreads[i];
}
}
#ifndef _WIN32
void printLinError(void)
{
switch(errno)
{
case EWOULDBLOCK: Server->Log("Reason: EWOULDBLOCK", LL_ERROR); break;
case EBADF: Server->Log("Reason: EBADF", LL_ERROR); break;
case ECONNABORTED: Server->Log("Reason: ECONNABORTED", LL_ERROR); break;
case EINTR: Server->Log("Reason: EINTR", LL_ERROR); break;
case EINVAL: Server->Log("Reason: EINVAL", LL_ERROR); break;
case EMFILE: Server->Log("Reason: EMFILE", LL_ERROR); break;
case ENFILE: Server->Log("Reason: ENFILE", LL_ERROR); break;
case ENOTSOCK: Server->Log("Reason: ENOTSOCK", LL_ERROR); break;
case EFAULT: Server->Log("Reason: EFAULT", LL_ERROR); break;
case ENOBUFS: Server->Log("Reason: ENOBUFS", LL_ERROR); break;
case ENOMEM: Server->Log("Reason: ENOMEM", LL_ERROR); break;
case EPROTO: Server->Log("Reason: EPROTO", LL_ERROR); break;
case EPERM: Server->Log("Reason: EPERM", LL_ERROR); break;
}
}
#endif
void CAcceptThread::operator()(bool single)
{
do
{
fd_set fdset;
socklen_t addrsize=sizeof(sockaddr_in);
FD_ZERO(&fdset);
FD_SET(s, &fdset);
timeval lon;
lon.tv_sec=1;
lon.tv_usec=0;
_i32 rc=select((int)s+1, &fdset, 0, 0, &lon);
if( rc<0 )
return;
if( FD_ISSET(s,&fdset) )
{
sockaddr_in naddr;
SOCKET ns=accept(s, (sockaddr*)&naddr, &addrsize);
if(ns>0)
{
Server->Log("New Connection incomming", LL_INFO);
OutputCallback *output=new OutputCallback(ns);
FCGIProtocolDriver *driver=new FCGIProtocolDriver(*output );
CClient *client=new CClient();
client->set(ns, output, driver);
AddToSelectThread(client);
}
else
{
Server->Log("Accepting client failed", LL_ERROR);
#ifndef _WIN32
printLinError();
#endif
Server->wait(1000);
}
}
}while(single==false);
}
void CAcceptThread::AddToSelectThread(CClient *client)
{
for(size_t i=0;i<SelectThreads.size();++i)
{
if( SelectThreads[i]->FreeClients()>0 )
{
SelectThreads[i]->AddClient( client );
return;
}
}
CSelectThread *nt=new CSelectThread(WorkerThreadsPerMaster);
nt->AddClient( client );
SelectThreads.push_back( nt );
Server->createThread(nt);
}

37
AcceptThread.h Normal file
View File

@ -0,0 +1,37 @@
#include <vector>
#include "socket_header.h"
#include "types.h"
#include "libfastcgi/fastcgi.hpp"
class CSelectThread;
class CClient;
class CAcceptThread
{
public:
CAcceptThread(unsigned int nWorkerThreadsPerMaster, unsigned short int uPort);
~CAcceptThread();
void operator()(bool single=false);
private:
void AddToSelectThread(CClient *client);
std::vector<CSelectThread*> SelectThreads;
SOCKET s;
unsigned int WorkerThreadsPerMaster;
};
class OutputCallback : public FCGIProtocolDriver::OutputCallback
{
public:
virtual ~OutputCallback();
OutputCallback(SOCKET fd_);
virtual void operator() (const void* buf, size_t count);
private:
SOCKET fd;
};

674
COPYING Normal file
View File

@ -0,0 +1,674 @@
GNU GENERAL PUBLIC LICENSE
Version 3, 29 June 2007
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
Preamble
The GNU General Public License is a free, copyleft license for
software and other kinds of works.
The licenses for most software and other practical works are designed
to take away your freedom to share and change the works. By contrast,
the GNU General Public License is intended to guarantee your freedom to
share and change all versions of a program--to make sure it remains free
software for all its users. We, the Free Software Foundation, use the
GNU General Public License for most of our software; it applies also to
any other work released this way by its authors. You can apply it to
your programs, too.
When we speak of free software, we are referring to freedom, not
price. Our General Public Licenses are designed to make sure that you
have the freedom to distribute copies of free software (and charge for
them if you wish), that you receive source code or can get it if you
want it, that you can change the software or use pieces of it in new
free programs, and that you know you can do these things.
To protect your rights, we need to prevent others from denying you
these rights or asking you to surrender the rights. Therefore, you have
certain responsibilities if you distribute copies of the software, or if
you modify it: responsibilities to respect the freedom of others.
For example, if you distribute copies of such a program, whether
gratis or for a fee, you must pass on to the recipients the same
freedoms that you received. You must make sure that they, too, receive
or can get the source code. And you must show them these terms so they
know their rights.
Developers that use the GNU GPL protect your rights with two steps:
(1) assert copyright on the software, and (2) offer you this License
giving you legal permission to copy, distribute and/or modify it.
For the developers' and authors' protection, the GPL clearly explains
that there is no warranty for this free software. For both users' and
authors' sake, the GPL requires that modified versions be marked as
changed, so that their problems will not be attributed erroneously to
authors of previous versions.
Some devices are designed to deny users access to install or run
modified versions of the software inside them, although the manufacturer
can do so. This is fundamentally incompatible with the aim of
protecting users' freedom to change the software. The systematic
pattern of such abuse occurs in the area of products for individuals to
use, which is precisely where it is most unacceptable. Therefore, we
have designed this version of the GPL to prohibit the practice for those
products. If such problems arise substantially in other domains, we
stand ready to extend this provision to those domains in future versions
of the GPL, as needed to protect the freedom of users.
Finally, every program is threatened constantly by software patents.
States should not allow patents to restrict development and use of
software on general-purpose computers, but in those that do, we wish to
avoid the special danger that patents applied to a free program could
make it effectively proprietary. To prevent this, the GPL assures that
patents cannot be used to render the program non-free.
The precise terms and conditions for copying, distribution and
modification follow.
TERMS AND CONDITIONS
0. Definitions.
"This License" refers to version 3 of the GNU General Public License.
"Copyright" also means copyright-like laws that apply to other kinds of
works, such as semiconductor masks.
"The Program" refers to any copyrightable work licensed under this
License. Each licensee is addressed as "you". "Licensees" and
"recipients" may be individuals or organizations.
To "modify" a work means to copy from or adapt all or part of the work
in a fashion requiring copyright permission, other than the making of an
exact copy. The resulting work is called a "modified version" of the
earlier work or a work "based on" the earlier work.
A "covered work" means either the unmodified Program or a work based
on the Program.
To "propagate" a work means to do anything with it that, without
permission, would make you directly or secondarily liable for
infringement under applicable copyright law, except executing it on a
computer or modifying a private copy. Propagation includes copying,
distribution (with or without modification), making available to the
public, and in some countries other activities as well.
To "convey" a work means any kind of propagation that enables other
parties to make or receive copies. Mere interaction with a user through
a computer network, with no transfer of a copy, is not conveying.
An interactive user interface displays "Appropriate Legal Notices"
to the extent that it includes a convenient and prominently visible
feature that (1) displays an appropriate copyright notice, and (2)
tells the user that there is no warranty for the work (except to the
extent that warranties are provided), that licensees may convey the
work under this License, and how to view a copy of this License. If
the interface presents a list of user commands or options, such as a
menu, a prominent item in the list meets this criterion.
1. Source Code.
The "source code" for a work means the preferred form of the work
for making modifications to it. "Object code" means any non-source
form of a work.
A "Standard Interface" means an interface that either is an official
standard defined by a recognized standards body, or, in the case of
interfaces specified for a particular programming language, one that
is widely used among developers working in that language.
The "System Libraries" of an executable work include anything, other
than the work as a whole, that (a) is included in the normal form of
packaging a Major Component, but which is not part of that Major
Component, and (b) serves only to enable use of the work with that
Major Component, or to implement a Standard Interface for which an
implementation is available to the public in source code form. A
"Major Component", in this context, means a major essential component
(kernel, window system, and so on) of the specific operating system
(if any) on which the executable work runs, or a compiler used to
produce the work, or an object code interpreter used to run it.
The "Corresponding Source" for a work in object code form means all
the source code needed to generate, install, and (for an executable
work) run the object code and to modify the work, including scripts to
control those activities. However, it does not include the work's
System Libraries, or general-purpose tools or generally available free
programs which are used unmodified in performing those activities but
which are not part of the work. For example, Corresponding Source
includes interface definition files associated with source files for
the work, and the source code for shared libraries and dynamically
linked subprograms that the work is specifically designed to require,
such as by intimate data communication or control flow between those
subprograms and other parts of the work.
The Corresponding Source need not include anything that users
can regenerate automatically from other parts of the Corresponding
Source.
The Corresponding Source for a work in source code form is that
same work.
2. Basic Permissions.
All rights granted under this License are granted for the term of
copyright on the Program, and are irrevocable provided the stated
conditions are met. This License explicitly affirms your unlimited
permission to run the unmodified Program. The output from running a
covered work is covered by this License only if the output, given its
content, constitutes a covered work. This License acknowledges your
rights of fair use or other equivalent, as provided by copyright law.
You may make, run and propagate covered works that you do not
convey, without conditions so long as your license otherwise remains
in force. You may convey covered works to others for the sole purpose
of having them make modifications exclusively for you, or provide you
with facilities for running those works, provided that you comply with
the terms of this License in conveying all material for which you do
not control copyright. Those thus making or running the covered works
for you must do so exclusively on your behalf, under your direction
and control, on terms that prohibit them from making any copies of
your copyrighted material outside their relationship with you.
Conveying under any other circumstances is permitted solely under
the conditions stated below. Sublicensing is not allowed; section 10
makes it unnecessary.
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
No covered work shall be deemed part of an effective technological
measure under any applicable law fulfilling obligations under article
11 of the WIPO copyright treaty adopted on 20 December 1996, or
similar laws prohibiting or restricting circumvention of such
measures.
When you convey a covered work, you waive any legal power to forbid
circumvention of technological measures to the extent such circumvention
is effected by exercising rights under this License with respect to
the covered work, and you disclaim any intention to limit operation or
modification of the work as a means of enforcing, against the work's
users, your or third parties' legal rights to forbid circumvention of
technological measures.
4. Conveying Verbatim Copies.
You may convey verbatim copies of the Program's source code as you
receive it, in any medium, provided that you conspicuously and
appropriately publish on each copy an appropriate copyright notice;
keep intact all notices stating that this License and any
non-permissive terms added in accord with section 7 apply to the code;
keep intact all notices of the absence of any warranty; and give all
recipients a copy of this License along with the Program.
You may charge any price or no price for each copy that you convey,
and you may offer support or warranty protection for a fee.
5. Conveying Modified Source Versions.
You may convey a work based on the Program, or the modifications to
produce it from the Program, in the form of source code under the
terms of section 4, provided that you also meet all of these conditions:
a) The work must carry prominent notices stating that you modified
it, and giving a relevant date.
b) The work must carry prominent notices stating that it is
released under this License and any conditions added under section
7. This requirement modifies the requirement in section 4 to
"keep intact all notices".
c) You must license the entire work, as a whole, under this
License to anyone who comes into possession of a copy. This
License will therefore apply, along with any applicable section 7
additional terms, to the whole of the work, and all its parts,
regardless of how they are packaged. This License gives no
permission to license the work in any other way, but it does not
invalidate such permission if you have separately received it.
d) If the work has interactive user interfaces, each must display
Appropriate Legal Notices; however, if the Program has interactive
interfaces that do not display Appropriate Legal Notices, your
work need not make them do so.
A compilation of a covered work with other separate and independent
works, which are not by their nature extensions of the covered work,
and which are not combined with it such as to form a larger program,
in or on a volume of a storage or distribution medium, is called an
"aggregate" if the compilation and its resulting copyright are not
used to limit the access or legal rights of the compilation's users
beyond what the individual works permit. Inclusion of a covered work
in an aggregate does not cause this License to apply to the other
parts of the aggregate.
6. Conveying Non-Source Forms.
You may convey a covered work in object code form under the terms
of sections 4 and 5, provided that you also convey the
machine-readable Corresponding Source under the terms of this License,
in one of these ways:
a) Convey the object code in, or embodied in, a physical product
(including a physical distribution medium), accompanied by the
Corresponding Source fixed on a durable physical medium
customarily used for software interchange.
b) Convey the object code in, or embodied in, a physical product
(including a physical distribution medium), accompanied by a
written offer, valid for at least three years and valid for as
long as you offer spare parts or customer support for that product
model, to give anyone who possesses the object code either (1) a
copy of the Corresponding Source for all the software in the
product that is covered by this License, on a durable physical
medium customarily used for software interchange, for a price no
more than your reasonable cost of physically performing this
conveying of source, or (2) access to copy the
Corresponding Source from a network server at no charge.
c) Convey individual copies of the object code with a copy of the
written offer to provide the Corresponding Source. This
alternative is allowed only occasionally and noncommercially, and
only if you received the object code with such an offer, in accord
with subsection 6b.
d) Convey the object code by offering access from a designated
place (gratis or for a charge), and offer equivalent access to the
Corresponding Source in the same way through the same place at no
further charge. You need not require recipients to copy the
Corresponding Source along with the object code. If the place to
copy the object code is a network server, the Corresponding Source
may be on a different server (operated by you or a third party)
that supports equivalent copying facilities, provided you maintain
clear directions next to the object code saying where to find the
Corresponding Source. Regardless of what server hosts the
Corresponding Source, you remain obligated to ensure that it is
available for as long as needed to satisfy these requirements.
e) Convey the object code using peer-to-peer transmission, provided
you inform other peers where the object code and Corresponding
Source of the work are being offered to the general public at no
charge under subsection 6d.
A separable portion of the object code, whose source code is excluded
from the Corresponding Source as a System Library, need not be
included in conveying the object code work.
A "User Product" is either (1) a "consumer product", which means any
tangible personal property which is normally used for personal, family,
or household purposes, or (2) anything designed or sold for incorporation
into a dwelling. In determining whether a product is a consumer product,
doubtful cases shall be resolved in favor of coverage. For a particular
product received by a particular user, "normally used" refers to a
typical or common use of that class of product, regardless of the status
of the particular user or of the way in which the particular user
actually uses, or expects or is expected to use, the product. A product
is a consumer product regardless of whether the product has substantial
commercial, industrial or non-consumer uses, unless such uses represent
the only significant mode of use of the product.
"Installation Information" for a User Product means any methods,
procedures, authorization keys, or other information required to install
and execute modified versions of a covered work in that User Product from
a modified version of its Corresponding Source. The information must
suffice to ensure that the continued functioning of the modified object
code is in no case prevented or interfered with solely because
modification has been made.
If you convey an object code work under this section in, or with, or
specifically for use in, a User Product, and the conveying occurs as
part of a transaction in which the right of possession and use of the
User Product is transferred to the recipient in perpetuity or for a
fixed term (regardless of how the transaction is characterized), the
Corresponding Source conveyed under this section must be accompanied
by the Installation Information. But this requirement does not apply
if neither you nor any third party retains the ability to install
modified object code on the User Product (for example, the work has
been installed in ROM).
The requirement to provide Installation Information does not include a
requirement to continue to provide support service, warranty, or updates
for a work that has been modified or installed by the recipient, or for
the User Product in which it has been modified or installed. Access to a
network may be denied when the modification itself materially and
adversely affects the operation of the network or violates the rules and
protocols for communication across the network.
Corresponding Source conveyed, and Installation Information provided,
in accord with this section must be in a format that is publicly
documented (and with an implementation available to the public in
source code form), and must require no special password or key for
unpacking, reading or copying.
7. Additional Terms.
"Additional permissions" are terms that supplement the terms of this
License by making exceptions from one or more of its conditions.
Additional permissions that are applicable to the entire Program shall
be treated as though they were included in this License, to the extent
that they are valid under applicable law. If additional permissions
apply only to part of the Program, that part may be used separately
under those permissions, but the entire Program remains governed by
this License without regard to the additional permissions.
When you convey a copy of a covered work, you may at your option
remove any additional permissions from that copy, or from any part of
it. (Additional permissions may be written to require their own
removal in certain cases when you modify the work.) You may place
additional permissions on material, added by you to a covered work,
for which you have or can give appropriate copyright permission.
Notwithstanding any other provision of this License, for material you
add to a covered work, you may (if authorized by the copyright holders of
that material) supplement the terms of this License with terms:
a) Disclaiming warranty or limiting liability differently from the
terms of sections 15 and 16 of this License; or
b) Requiring preservation of specified reasonable legal notices or
author attributions in that material or in the Appropriate Legal
Notices displayed by works containing it; or
c) Prohibiting misrepresentation of the origin of that material, or
requiring that modified versions of such material be marked in
reasonable ways as different from the original version; or
d) Limiting the use for publicity purposes of names of licensors or
authors of the material; or
e) Declining to grant rights under trademark law for use of some
trade names, trademarks, or service marks; or
f) Requiring indemnification of licensors and authors of that
material by anyone who conveys the material (or modified versions of
it) with contractual assumptions of liability to the recipient, for
any liability that these contractual assumptions directly impose on
those licensors and authors.
All other non-permissive additional terms are considered "further
restrictions" within the meaning of section 10. If the Program as you
received it, or any part of it, contains a notice stating that it is
governed by this License along with a term that is a further
restriction, you may remove that term. If a license document contains
a further restriction but permits relicensing or conveying under this
License, you may add to a covered work material governed by the terms
of that license document, provided that the further restriction does
not survive such relicensing or conveying.
If you add terms to a covered work in accord with this section, you
must place, in the relevant source files, a statement of the
additional terms that apply to those files, or a notice indicating
where to find the applicable terms.
Additional terms, permissive or non-permissive, may be stated in the
form of a separately written license, or stated as exceptions;
the above requirements apply either way.
8. Termination.
You may not propagate or modify a covered work except as expressly
provided under this License. Any attempt otherwise to propagate or
modify it is void, and will automatically terminate your rights under
this License (including any patent licenses granted under the third
paragraph of section 11).
However, if you cease all violation of this License, then your
license from a particular copyright holder is reinstated (a)
provisionally, unless and until the copyright holder explicitly and
finally terminates your license, and (b) permanently, if the copyright
holder fails to notify you of the violation by some reasonable means
prior to 60 days after the cessation.
Moreover, your license from a particular copyright holder is
reinstated permanently if the copyright holder notifies you of the
violation by some reasonable means, this is the first time you have
received notice of violation of this License (for any work) from that
copyright holder, and you cure the violation prior to 30 days after
your receipt of the notice.
Termination of your rights under this section does not terminate the
licenses of parties who have received copies or rights from you under
this License. If your rights have been terminated and not permanently
reinstated, you do not qualify to receive new licenses for the same
material under section 10.
9. Acceptance Not Required for Having Copies.
You are not required to accept this License in order to receive or
run a copy of the Program. Ancillary propagation of a covered work
occurring solely as a consequence of using peer-to-peer transmission
to receive a copy likewise does not require acceptance. However,
nothing other than this License grants you permission to propagate or
modify any covered work. These actions infringe copyright if you do
not accept this License. Therefore, by modifying or propagating a
covered work, you indicate your acceptance of this License to do so.
10. Automatic Licensing of Downstream Recipients.
Each time you convey a covered work, the recipient automatically
receives a license from the original licensors, to run, modify and
propagate that work, subject to this License. You are not responsible
for enforcing compliance by third parties with this License.
An "entity transaction" is a transaction transferring control of an
organization, or substantially all assets of one, or subdividing an
organization, or merging organizations. If propagation of a covered
work results from an entity transaction, each party to that
transaction who receives a copy of the work also receives whatever
licenses to the work the party's predecessor in interest had or could
give under the previous paragraph, plus a right to possession of the
Corresponding Source of the work from the predecessor in interest, if
the predecessor has it or can get it with reasonable efforts.
You may not impose any further restrictions on the exercise of the
rights granted or affirmed under this License. For example, you may
not impose a license fee, royalty, or other charge for exercise of
rights granted under this License, and you may not initiate litigation
(including a cross-claim or counterclaim in a lawsuit) alleging that
any patent claim is infringed by making, using, selling, offering for
sale, or importing the Program or any portion of it.
11. Patents.
A "contributor" is a copyright holder who authorizes use under this
License of the Program or a work on which the Program is based. The
work thus licensed is called the contributor's "contributor version".
A contributor's "essential patent claims" are all patent claims
owned or controlled by the contributor, whether already acquired or
hereafter acquired, that would be infringed by some manner, permitted
by this License, of making, using, or selling its contributor version,
but do not include claims that would be infringed only as a
consequence of further modification of the contributor version. For
purposes of this definition, "control" includes the right to grant
patent sublicenses in a manner consistent with the requirements of
this License.
Each contributor grants you a non-exclusive, worldwide, royalty-free
patent license under the contributor's essential patent claims, to
make, use, sell, offer for sale, import and otherwise run, modify and
propagate the contents of its contributor version.
In the following three paragraphs, a "patent license" is any express
agreement or commitment, however denominated, not to enforce a patent
(such as an express permission to practice a patent or covenant not to
sue for patent infringement). To "grant" such a patent license to a
party means to make such an agreement or commitment not to enforce a
patent against the party.
If you convey a covered work, knowingly relying on a patent license,
and the Corresponding Source of the work is not available for anyone
to copy, free of charge and under the terms of this License, through a
publicly available network server or other readily accessible means,
then you must either (1) cause the Corresponding Source to be so
available, or (2) arrange to deprive yourself of the benefit of the
patent license for this particular work, or (3) arrange, in a manner
consistent with the requirements of this License, to extend the patent
license to downstream recipients. "Knowingly relying" means you have
actual knowledge that, but for the patent license, your conveying the
covered work in a country, or your recipient's use of the covered work
in a country, would infringe one or more identifiable patents in that
country that you have reason to believe are valid.
If, pursuant to or in connection with a single transaction or
arrangement, you convey, or propagate by procuring conveyance of, a
covered work, and grant a patent license to some of the parties
receiving the covered work authorizing them to use, propagate, modify
or convey a specific copy of the covered work, then the patent license
you grant is automatically extended to all recipients of the covered
work and works based on it.
A patent license is "discriminatory" if it does not include within
the scope of its coverage, prohibits the exercise of, or is
conditioned on the non-exercise of one or more of the rights that are
specifically granted under this License. You may not convey a covered
work if you are a party to an arrangement with a third party that is
in the business of distributing software, under which you make payment
to the third party based on the extent of your activity of conveying
the work, and under which the third party grants, to any of the
parties who would receive the covered work from you, a discriminatory
patent license (a) in connection with copies of the covered work
conveyed by you (or copies made from those copies), or (b) primarily
for and in connection with specific products or compilations that
contain the covered work, unless you entered into that arrangement,
or that patent license was granted, prior to 28 March 2007.
Nothing in this License shall be construed as excluding or limiting
any implied license or other defenses to infringement that may
otherwise be available to you under applicable patent law.
12. No Surrender of Others' Freedom.
If conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License. If you cannot convey a
covered work so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you may
not convey it at all. For example, if you agree to terms that obligate you
to collect a royalty for further conveying from those to whom you convey
the Program, the only way you could satisfy both those terms and this
License would be to refrain entirely from conveying the Program.
13. Use with the GNU Affero General Public License.
Notwithstanding any other provision of this License, you have
permission to link or combine any covered work with a work licensed
under version 3 of the GNU Affero General Public License into a single
combined work, and to convey the resulting work. The terms of this
License will continue to apply to the part which is the covered work,
but the special requirements of the GNU Affero General Public License,
section 13, concerning interaction through a network will apply to the
combination as such.
14. Revised Versions of this License.
The Free Software Foundation may publish revised and/or new versions of
the GNU General Public License from time to time. Such new versions will
be similar in spirit to the present version, but may differ in detail to
address new problems or concerns.
Each version is given a distinguishing version number. If the
Program specifies that a certain numbered version of the GNU General
Public License "or any later version" applies to it, you have the
option of following the terms and conditions either of that numbered
version or of any later version published by the Free Software
Foundation. If the Program does not specify a version number of the
GNU General Public License, you may choose any version ever published
by the Free Software Foundation.
If the Program specifies that a proxy can decide which future
versions of the GNU General Public License can be used, that proxy's
public statement of acceptance of a version permanently authorizes you
to choose that version for the Program.
Later license versions may give you additional or different
permissions. However, no additional obligations are imposed on any
author or copyright holder as a result of your choosing to follow a
later version.
15. Disclaimer of Warranty.
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
16. Limitation of Liability.
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
SUCH DAMAGES.
17. Interpretation of Sections 15 and 16.
If the disclaimer of warranty and limitation of liability provided
above cannot be given local legal effect according to their terms,
reviewing courts shall apply local law that most closely approximates
an absolute waiver of all civil liability in connection with the
Program, unless a warranty or assumption of liability accompanies a
copy of the Program in return for a fee.
END OF TERMS AND CONDITIONS
How to Apply These Terms to Your New Programs
If you develop a new program, and you want it to be of the greatest
possible use to the public, the best way to achieve this is to make it
free software which everyone can redistribute and change under these terms.
To do so, attach the following notices to the program. It is safest
to attach them to the start of each source file to most effectively
state the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.
<one line to give the program's name and a brief idea of what it does.>
Copyright (C) <year> <name of author>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
Also add information on how to contact you by electronic and paper mail.
If the program does terminal interaction, make it output a short
notice like this when it starts in an interactive mode:
<program> Copyright (C) <year> <name of author>
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.
The hypothetical commands `show w' and `show c' should show the appropriate
parts of the General Public License. Of course, your program's commands
might be different; for a GUI interface, you would use an "about box".
You should also get your employer (if you work as a programmer) or school,
if any, to sign a "copyright disclaimer" for the program, if necessary.
For more information on this, and how to apply and follow the GNU GPL, see
<http://www.gnu.org/licenses/>.
The GNU General Public License does not permit incorporating your program
into proprietary programs. If your program is a subroutine library, you
may consider it more useful to permit linking proprietary applications with
the library. If this is what you want to do, use the GNU Lesser General
Public License instead of this License. But first, please read
<http://www.gnu.org/philosophy/why-not-lgpl.html>.

3
ChangeLog Normal file
View File

@ -0,0 +1,3 @@
Please see
http://www.urbackup.org
for Changelog

148
Client.cpp Normal file
View File

@ -0,0 +1,148 @@
/*************************************************************************
* UrBackup - Client/Server backup system
* Copyright (C) 2011 Martin Raiber
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
**************************************************************************/
#include "vld.h"
#include "Client.h"
#include "Server.h"
#include "AcceptThread.h"
#include "libfastcgi/fastcgi.hpp"
CClient::CClient()
{
mutex=Server->createMutex();
m_lock=NULL;
processing=false;
}
CClient::~CClient()
{
Server->destroy(mutex);
}
SOCKET CClient::getSocket()
{
return s;
}
OutputCallback * CClient::getOutputCallback()
{
return output;
}
FCGIProtocolDriver * CClient::getFCGIProtocolDriver()
{
return driver;
}
void CClient::set(SOCKET ps, OutputCallback *poutput, FCGIProtocolDriver * pdriver )
{
IScopedLock l(mutex);
s=ps;
output=poutput;
driver=pdriver;
int flag;
#ifdef _WIN32
flag=1;
setsockopt(s, IPPROTO_TCP, TCP_NODELAY, (char *) &flag, sizeof(int));
#else
flag=0;
setsockopt(s, IPPROTO_TCP, TCP_CORK, (char *) &flag, sizeof(int));
#endif
}
void CClient::lock()
{
IScopedLock *n_lock=new IScopedLock(mutex);
m_lock=n_lock;
}
void CClient::unlock()
{
delete m_lock;
}
void CClient::remove()
{
IScopedLock l(mutex);
delete output;
delete driver;
}
void CClient::addRequest( FCGIRequest* req)
{
IScopedLock l(mutex);
requests.push_back( req );
}
bool CClient::removeRequest( FCGIRequest *req)
{
IScopedLock l(mutex);
for(size_t i=0;i<requests.size();++i)
{
if(requests[i]==req )
{
requests.erase( requests.begin()+i);
return true;
}
}
return false;
}
size_t CClient::numRequests(void)
{
IScopedLock l(mutex);
return requests.size();
}
FCGIRequest* CClient::getRequest(size_t num)
{
IScopedLock l(mutex);
if( num>=requests.size() )
return NULL;
return requests[num];
}
FCGIRequest* CClient::getAndRemoveReadyRequest(void)
{
IScopedLock l(mutex);
for(size_t i=0;i<requests.size();++i)
{
if( requests[i]->stdin_eof==true )
{
FCGIRequest* req=requests[i];
requests.erase( requests.begin()+i);
return req;
}
}
return NULL;
}
bool CClient::isProcessing(void)
{
return processing;
}
bool CClient::setProcessing(bool b)
{
IScopedLock l(mutex);
bool ret=processing;
processing=b;
return ret;
}

372
CompiledServer.sln Normal file
View File

@ -0,0 +1,372 @@

Microsoft Visual Studio Solution File, Format Version 11.00
# Visual Studio 2010
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "CompiledServer", "CompiledServer.vcxproj", "{8546D6E2-1872-418B-9766-E40F33689BE4}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "urmail", "urmail\urmail.vcxproj", "{8C7CC2AC-A453-4B3A-A703-D875D1CE15B6}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "pop3_server", "pop3_server\pop3_server.vcxproj", "{5B2AF133-8967-45E8-AFE5-0BB73E048EC9}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "smtp_server", "smtp_server\smtp_server.vcxproj", "{0D566993-9E10-41C3-AFEF-673EBC56274C}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "searchplugin", "searchplugin\searchplugin.vcxproj", "{41B8D0ED-95AD-419F-B997-7BA4F6E376FC}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "bbsuche", "bbsuche\bbsuche.vcxproj", "{FB6E7823-C7B8-4D72-877C-DF745505B78D}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "passwordsafe", "passwordsafe\passwordsafe.vcxproj", "{44FCBBF0-F082-4D28-A390-95FFCD76BAD8}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "fetchmail", "fetchmail\fetchmail.vcxproj", "{A37DE171-F66A-49E1-81AF-B4AEAE7DF1A0}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "cookassistant", "cookassistant\cookassistant.vcxproj", "{0A7CEFC3-2B01-4130-973B-68DA986AFA65}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "sysmgr", "sysmgr\sysmgr.vcxproj", "{AE16E6C5-7919-4E89-98FA-A0FEC448DDCF}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "guestbook", "..\guestbook\guestbook.vcxproj", "{82BD764C-0FFC-40E3-8590-CBD3A8EE427B}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "httpserver", "httpserver\httpserver.vcxproj", "{D1BF1BE4-1F36-4E19-8631-CB4C93B77E9B}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ocamlinterpreter", "ocamlinterpreter\ocamlinterpreter.vcxproj", "{E57E4168-34AB-423D-81D0-F62CD5DD488D}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "piped_process", "piped_process\piped_process.vcxproj", "{CE40A480-BD9D-446F-A549-23FD1D6868C2}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "bimuxxi", "bimuxxi\bimuxxi.vcxproj", "{1586287F-DA39-425D-AAF9-C688569E50A9}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ircsearch", "ircsearch\ircsearch.vcxproj", "{6D57C528-DAFB-42BA-9884-7D3B06F916DE}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "dcsearch", "dcsearch\dcsearch.vcxproj", "{4BA4796E-008A-4963-8D0E-9C375C9A2B4B}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "passwordsafe2", "passwordsafe2\passwordsafe2.vcxproj", "{23D4C1E4-8721-4F25-B94C-4100B5E874E8}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "cryptoplugin", "cryptoplugin\cryptoplugin.vcxproj", "{A9B12FBF-84D8-4BB6-B4A3-DD57F06637B0}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "urbackup", "urbackup\urbackup.vcxproj", "{A4E2527B-4886-4163-9411-10BF66A931BE}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "fileservplugin", "fileservplugin\fileservplugin.vcxproj", "{B1F1AF2E-E544-45F7-864A-883461A4B574}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "fsimageplugin", "fsimageplugin\fsimageplugin.vcxproj", "{20375DC0-38DA-4254-B479-EFA8028C29B1}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "pychart", "pychart\pychart.vcxproj", "{DB4FFADB-B1D0-4D52-8CD5-C9AE479CA565}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "downloadplugin", "downloadplugin\downloadplugin.vcxproj", "{835A9C1D-BDEE-44A2-97DB-EF9C4AE59F45}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "jswiki", "jswiki\jswiki.vcxproj", "{81EE2F6D-6A48-423B-8BBB-B97DB74EDD0F}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug WinXP|Win32 = Debug WinXP|Win32
Debug WinXP|x64 = Debug WinXP|x64
Debug XP|Win32 = Debug XP|Win32
Debug XP|x64 = Debug XP|x64
Debug|Win32 = Debug|Win32
Debug|x64 = Debug|x64
Release|Win32 = Release|Win32
Release|x64 = Release|x64
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{8546D6E2-1872-418B-9766-E40F33689BE4}.Debug WinXP|Win32.ActiveCfg = Debug|Win32
{8546D6E2-1872-418B-9766-E40F33689BE4}.Debug WinXP|Win32.Build.0 = Debug|Win32
{8546D6E2-1872-418B-9766-E40F33689BE4}.Debug WinXP|x64.ActiveCfg = Debug|Win32
{8546D6E2-1872-418B-9766-E40F33689BE4}.Debug XP|Win32.ActiveCfg = Debug|Win32
{8546D6E2-1872-418B-9766-E40F33689BE4}.Debug XP|Win32.Build.0 = Debug|Win32
{8546D6E2-1872-418B-9766-E40F33689BE4}.Debug XP|x64.ActiveCfg = Debug|Win32
{8546D6E2-1872-418B-9766-E40F33689BE4}.Debug|Win32.ActiveCfg = Debug|Win32
{8546D6E2-1872-418B-9766-E40F33689BE4}.Debug|Win32.Build.0 = Debug|Win32
{8546D6E2-1872-418B-9766-E40F33689BE4}.Debug|x64.ActiveCfg = Debug|Win32
{8546D6E2-1872-418B-9766-E40F33689BE4}.Release|Win32.ActiveCfg = Release|Win32
{8546D6E2-1872-418B-9766-E40F33689BE4}.Release|Win32.Build.0 = Release|Win32
{8546D6E2-1872-418B-9766-E40F33689BE4}.Release|x64.ActiveCfg = Release Service|x64
{8C7CC2AC-A453-4B3A-A703-D875D1CE15B6}.Debug WinXP|Win32.ActiveCfg = Debug|Win32
{8C7CC2AC-A453-4B3A-A703-D875D1CE15B6}.Debug WinXP|Win32.Build.0 = Debug|Win32
{8C7CC2AC-A453-4B3A-A703-D875D1CE15B6}.Debug WinXP|x64.ActiveCfg = Debug|Win32
{8C7CC2AC-A453-4B3A-A703-D875D1CE15B6}.Debug XP|Win32.ActiveCfg = Debug|Win32
{8C7CC2AC-A453-4B3A-A703-D875D1CE15B6}.Debug XP|Win32.Build.0 = Debug|Win32
{8C7CC2AC-A453-4B3A-A703-D875D1CE15B6}.Debug XP|x64.ActiveCfg = Debug|Win32
{8C7CC2AC-A453-4B3A-A703-D875D1CE15B6}.Debug|Win32.ActiveCfg = Debug|Win32
{8C7CC2AC-A453-4B3A-A703-D875D1CE15B6}.Debug|Win32.Build.0 = Debug|Win32
{8C7CC2AC-A453-4B3A-A703-D875D1CE15B6}.Debug|x64.ActiveCfg = Debug|Win32
{8C7CC2AC-A453-4B3A-A703-D875D1CE15B6}.Release|Win32.ActiveCfg = Release|Win32
{8C7CC2AC-A453-4B3A-A703-D875D1CE15B6}.Release|Win32.Build.0 = Release|Win32
{8C7CC2AC-A453-4B3A-A703-D875D1CE15B6}.Release|x64.ActiveCfg = Release|Win32
{5B2AF133-8967-45E8-AFE5-0BB73E048EC9}.Debug WinXP|Win32.ActiveCfg = Debug|Win32
{5B2AF133-8967-45E8-AFE5-0BB73E048EC9}.Debug WinXP|Win32.Build.0 = Debug|Win32
{5B2AF133-8967-45E8-AFE5-0BB73E048EC9}.Debug WinXP|x64.ActiveCfg = Debug|Win32
{5B2AF133-8967-45E8-AFE5-0BB73E048EC9}.Debug XP|Win32.ActiveCfg = Debug|Win32
{5B2AF133-8967-45E8-AFE5-0BB73E048EC9}.Debug XP|Win32.Build.0 = Debug|Win32
{5B2AF133-8967-45E8-AFE5-0BB73E048EC9}.Debug XP|x64.ActiveCfg = Debug|Win32
{5B2AF133-8967-45E8-AFE5-0BB73E048EC9}.Debug|Win32.ActiveCfg = Debug|Win32
{5B2AF133-8967-45E8-AFE5-0BB73E048EC9}.Debug|Win32.Build.0 = Debug|Win32
{5B2AF133-8967-45E8-AFE5-0BB73E048EC9}.Debug|x64.ActiveCfg = Debug|Win32
{5B2AF133-8967-45E8-AFE5-0BB73E048EC9}.Release|Win32.ActiveCfg = Release|Win32
{5B2AF133-8967-45E8-AFE5-0BB73E048EC9}.Release|Win32.Build.0 = Release|Win32
{5B2AF133-8967-45E8-AFE5-0BB73E048EC9}.Release|x64.ActiveCfg = Release|Win32
{0D566993-9E10-41C3-AFEF-673EBC56274C}.Debug WinXP|Win32.ActiveCfg = Debug|Win32
{0D566993-9E10-41C3-AFEF-673EBC56274C}.Debug WinXP|Win32.Build.0 = Debug|Win32
{0D566993-9E10-41C3-AFEF-673EBC56274C}.Debug WinXP|x64.ActiveCfg = Debug|Win32
{0D566993-9E10-41C3-AFEF-673EBC56274C}.Debug XP|Win32.ActiveCfg = Debug|Win32
{0D566993-9E10-41C3-AFEF-673EBC56274C}.Debug XP|Win32.Build.0 = Debug|Win32
{0D566993-9E10-41C3-AFEF-673EBC56274C}.Debug XP|x64.ActiveCfg = Debug|Win32
{0D566993-9E10-41C3-AFEF-673EBC56274C}.Debug|Win32.ActiveCfg = Debug|Win32
{0D566993-9E10-41C3-AFEF-673EBC56274C}.Debug|Win32.Build.0 = Debug|Win32
{0D566993-9E10-41C3-AFEF-673EBC56274C}.Debug|x64.ActiveCfg = Debug|Win32
{0D566993-9E10-41C3-AFEF-673EBC56274C}.Release|Win32.ActiveCfg = Release|Win32
{0D566993-9E10-41C3-AFEF-673EBC56274C}.Release|Win32.Build.0 = Release|Win32
{0D566993-9E10-41C3-AFEF-673EBC56274C}.Release|x64.ActiveCfg = Release|Win32
{41B8D0ED-95AD-419F-B997-7BA4F6E376FC}.Debug WinXP|Win32.ActiveCfg = Debug|Win32
{41B8D0ED-95AD-419F-B997-7BA4F6E376FC}.Debug WinXP|Win32.Build.0 = Debug|Win32
{41B8D0ED-95AD-419F-B997-7BA4F6E376FC}.Debug WinXP|x64.ActiveCfg = Debug|Win32
{41B8D0ED-95AD-419F-B997-7BA4F6E376FC}.Debug XP|Win32.ActiveCfg = Debug|Win32
{41B8D0ED-95AD-419F-B997-7BA4F6E376FC}.Debug XP|Win32.Build.0 = Debug|Win32
{41B8D0ED-95AD-419F-B997-7BA4F6E376FC}.Debug XP|x64.ActiveCfg = Debug|Win32
{41B8D0ED-95AD-419F-B997-7BA4F6E376FC}.Debug|Win32.ActiveCfg = Debug|Win32
{41B8D0ED-95AD-419F-B997-7BA4F6E376FC}.Debug|Win32.Build.0 = Debug|Win32
{41B8D0ED-95AD-419F-B997-7BA4F6E376FC}.Debug|x64.ActiveCfg = Debug|Win32
{41B8D0ED-95AD-419F-B997-7BA4F6E376FC}.Release|Win32.ActiveCfg = Release|Win32
{41B8D0ED-95AD-419F-B997-7BA4F6E376FC}.Release|Win32.Build.0 = Release|Win32
{41B8D0ED-95AD-419F-B997-7BA4F6E376FC}.Release|x64.ActiveCfg = Release|Win32
{FB6E7823-C7B8-4D72-877C-DF745505B78D}.Debug WinXP|Win32.ActiveCfg = Debug|Win32
{FB6E7823-C7B8-4D72-877C-DF745505B78D}.Debug WinXP|Win32.Build.0 = Debug|Win32
{FB6E7823-C7B8-4D72-877C-DF745505B78D}.Debug WinXP|x64.ActiveCfg = Debug|Win32
{FB6E7823-C7B8-4D72-877C-DF745505B78D}.Debug XP|Win32.ActiveCfg = Debug|Win32
{FB6E7823-C7B8-4D72-877C-DF745505B78D}.Debug XP|Win32.Build.0 = Debug|Win32
{FB6E7823-C7B8-4D72-877C-DF745505B78D}.Debug XP|x64.ActiveCfg = Debug|Win32
{FB6E7823-C7B8-4D72-877C-DF745505B78D}.Debug|Win32.ActiveCfg = Debug|Win32
{FB6E7823-C7B8-4D72-877C-DF745505B78D}.Debug|Win32.Build.0 = Debug|Win32
{FB6E7823-C7B8-4D72-877C-DF745505B78D}.Debug|x64.ActiveCfg = Debug|Win32
{FB6E7823-C7B8-4D72-877C-DF745505B78D}.Release|Win32.ActiveCfg = Release|Win32
{FB6E7823-C7B8-4D72-877C-DF745505B78D}.Release|Win32.Build.0 = Release|Win32
{FB6E7823-C7B8-4D72-877C-DF745505B78D}.Release|x64.ActiveCfg = Release|Win32
{44FCBBF0-F082-4D28-A390-95FFCD76BAD8}.Debug WinXP|Win32.ActiveCfg = Debug|Win32
{44FCBBF0-F082-4D28-A390-95FFCD76BAD8}.Debug WinXP|Win32.Build.0 = Debug|Win32
{44FCBBF0-F082-4D28-A390-95FFCD76BAD8}.Debug WinXP|x64.ActiveCfg = Debug|Win32
{44FCBBF0-F082-4D28-A390-95FFCD76BAD8}.Debug XP|Win32.ActiveCfg = Debug|Win32
{44FCBBF0-F082-4D28-A390-95FFCD76BAD8}.Debug XP|Win32.Build.0 = Debug|Win32
{44FCBBF0-F082-4D28-A390-95FFCD76BAD8}.Debug XP|x64.ActiveCfg = Debug|Win32
{44FCBBF0-F082-4D28-A390-95FFCD76BAD8}.Debug|Win32.ActiveCfg = Debug|Win32
{44FCBBF0-F082-4D28-A390-95FFCD76BAD8}.Debug|Win32.Build.0 = Debug|Win32
{44FCBBF0-F082-4D28-A390-95FFCD76BAD8}.Debug|x64.ActiveCfg = Debug|Win32
{44FCBBF0-F082-4D28-A390-95FFCD76BAD8}.Release|Win32.ActiveCfg = Release|Win32
{44FCBBF0-F082-4D28-A390-95FFCD76BAD8}.Release|Win32.Build.0 = Release|Win32
{44FCBBF0-F082-4D28-A390-95FFCD76BAD8}.Release|x64.ActiveCfg = Release|Win32
{A37DE171-F66A-49E1-81AF-B4AEAE7DF1A0}.Debug WinXP|Win32.ActiveCfg = Debug|Win32
{A37DE171-F66A-49E1-81AF-B4AEAE7DF1A0}.Debug WinXP|Win32.Build.0 = Debug|Win32
{A37DE171-F66A-49E1-81AF-B4AEAE7DF1A0}.Debug WinXP|x64.ActiveCfg = Debug|Win32
{A37DE171-F66A-49E1-81AF-B4AEAE7DF1A0}.Debug XP|Win32.ActiveCfg = Debug|Win32
{A37DE171-F66A-49E1-81AF-B4AEAE7DF1A0}.Debug XP|Win32.Build.0 = Debug|Win32
{A37DE171-F66A-49E1-81AF-B4AEAE7DF1A0}.Debug XP|x64.ActiveCfg = Debug|Win32
{A37DE171-F66A-49E1-81AF-B4AEAE7DF1A0}.Debug|Win32.ActiveCfg = Debug|Win32
{A37DE171-F66A-49E1-81AF-B4AEAE7DF1A0}.Debug|Win32.Build.0 = Debug|Win32
{A37DE171-F66A-49E1-81AF-B4AEAE7DF1A0}.Debug|x64.ActiveCfg = Debug|Win32
{A37DE171-F66A-49E1-81AF-B4AEAE7DF1A0}.Release|Win32.ActiveCfg = Release|Win32
{A37DE171-F66A-49E1-81AF-B4AEAE7DF1A0}.Release|Win32.Build.0 = Release|Win32
{A37DE171-F66A-49E1-81AF-B4AEAE7DF1A0}.Release|x64.ActiveCfg = Release|Win32
{0A7CEFC3-2B01-4130-973B-68DA986AFA65}.Debug WinXP|Win32.ActiveCfg = Debug|Win32
{0A7CEFC3-2B01-4130-973B-68DA986AFA65}.Debug WinXP|Win32.Build.0 = Debug|Win32
{0A7CEFC3-2B01-4130-973B-68DA986AFA65}.Debug WinXP|x64.ActiveCfg = Debug|Win32
{0A7CEFC3-2B01-4130-973B-68DA986AFA65}.Debug XP|Win32.ActiveCfg = Debug|Win32
{0A7CEFC3-2B01-4130-973B-68DA986AFA65}.Debug XP|Win32.Build.0 = Debug|Win32
{0A7CEFC3-2B01-4130-973B-68DA986AFA65}.Debug XP|x64.ActiveCfg = Debug|Win32
{0A7CEFC3-2B01-4130-973B-68DA986AFA65}.Debug|Win32.ActiveCfg = Debug|Win32
{0A7CEFC3-2B01-4130-973B-68DA986AFA65}.Debug|Win32.Build.0 = Debug|Win32
{0A7CEFC3-2B01-4130-973B-68DA986AFA65}.Debug|x64.ActiveCfg = Debug|Win32
{0A7CEFC3-2B01-4130-973B-68DA986AFA65}.Release|Win32.ActiveCfg = Release|Win32
{0A7CEFC3-2B01-4130-973B-68DA986AFA65}.Release|Win32.Build.0 = Release|Win32
{0A7CEFC3-2B01-4130-973B-68DA986AFA65}.Release|x64.ActiveCfg = Release|Win32
{AE16E6C5-7919-4E89-98FA-A0FEC448DDCF}.Debug WinXP|Win32.ActiveCfg = Debug|Win32
{AE16E6C5-7919-4E89-98FA-A0FEC448DDCF}.Debug WinXP|Win32.Build.0 = Debug|Win32
{AE16E6C5-7919-4E89-98FA-A0FEC448DDCF}.Debug WinXP|x64.ActiveCfg = Debug|Win32
{AE16E6C5-7919-4E89-98FA-A0FEC448DDCF}.Debug XP|Win32.ActiveCfg = Debug|Win32
{AE16E6C5-7919-4E89-98FA-A0FEC448DDCF}.Debug XP|Win32.Build.0 = Debug|Win32
{AE16E6C5-7919-4E89-98FA-A0FEC448DDCF}.Debug XP|x64.ActiveCfg = Debug|Win32
{AE16E6C5-7919-4E89-98FA-A0FEC448DDCF}.Debug|Win32.ActiveCfg = Debug|Win32
{AE16E6C5-7919-4E89-98FA-A0FEC448DDCF}.Debug|Win32.Build.0 = Debug|Win32
{AE16E6C5-7919-4E89-98FA-A0FEC448DDCF}.Debug|x64.ActiveCfg = Debug|Win32
{AE16E6C5-7919-4E89-98FA-A0FEC448DDCF}.Release|Win32.ActiveCfg = Release|Win32
{AE16E6C5-7919-4E89-98FA-A0FEC448DDCF}.Release|Win32.Build.0 = Release|Win32
{AE16E6C5-7919-4E89-98FA-A0FEC448DDCF}.Release|x64.ActiveCfg = Release|Win32
{82BD764C-0FFC-40E3-8590-CBD3A8EE427B}.Debug WinXP|Win32.ActiveCfg = Debug|Win32
{82BD764C-0FFC-40E3-8590-CBD3A8EE427B}.Debug WinXP|x64.ActiveCfg = Debug|Win32
{82BD764C-0FFC-40E3-8590-CBD3A8EE427B}.Debug XP|Win32.ActiveCfg = Debug|Win32
{82BD764C-0FFC-40E3-8590-CBD3A8EE427B}.Debug XP|x64.ActiveCfg = Debug|Win32
{82BD764C-0FFC-40E3-8590-CBD3A8EE427B}.Debug|Win32.ActiveCfg = Debug|Win32
{82BD764C-0FFC-40E3-8590-CBD3A8EE427B}.Debug|Win32.Build.0 = Debug|Win32
{82BD764C-0FFC-40E3-8590-CBD3A8EE427B}.Debug|x64.ActiveCfg = Debug|Win32
{82BD764C-0FFC-40E3-8590-CBD3A8EE427B}.Release|Win32.ActiveCfg = Release|Win32
{82BD764C-0FFC-40E3-8590-CBD3A8EE427B}.Release|Win32.Build.0 = Release|Win32
{82BD764C-0FFC-40E3-8590-CBD3A8EE427B}.Release|x64.ActiveCfg = Release|Win32
{D1BF1BE4-1F36-4E19-8631-CB4C93B77E9B}.Debug WinXP|Win32.ActiveCfg = Debug|Win32
{D1BF1BE4-1F36-4E19-8631-CB4C93B77E9B}.Debug WinXP|Win32.Build.0 = Debug|Win32
{D1BF1BE4-1F36-4E19-8631-CB4C93B77E9B}.Debug WinXP|x64.ActiveCfg = Debug|Win32
{D1BF1BE4-1F36-4E19-8631-CB4C93B77E9B}.Debug XP|Win32.ActiveCfg = Debug|Win32
{D1BF1BE4-1F36-4E19-8631-CB4C93B77E9B}.Debug XP|Win32.Build.0 = Debug|Win32
{D1BF1BE4-1F36-4E19-8631-CB4C93B77E9B}.Debug XP|x64.ActiveCfg = Debug|Win32
{D1BF1BE4-1F36-4E19-8631-CB4C93B77E9B}.Debug|Win32.ActiveCfg = Debug|Win32
{D1BF1BE4-1F36-4E19-8631-CB4C93B77E9B}.Debug|Win32.Build.0 = Debug|Win32
{D1BF1BE4-1F36-4E19-8631-CB4C93B77E9B}.Debug|x64.ActiveCfg = Debug|Win32
{D1BF1BE4-1F36-4E19-8631-CB4C93B77E9B}.Release|Win32.ActiveCfg = Release|Win32
{D1BF1BE4-1F36-4E19-8631-CB4C93B77E9B}.Release|Win32.Build.0 = Release|Win32
{D1BF1BE4-1F36-4E19-8631-CB4C93B77E9B}.Release|x64.ActiveCfg = Release|Win32
{E57E4168-34AB-423D-81D0-F62CD5DD488D}.Debug WinXP|Win32.ActiveCfg = Debug|Win32
{E57E4168-34AB-423D-81D0-F62CD5DD488D}.Debug WinXP|Win32.Build.0 = Debug|Win32
{E57E4168-34AB-423D-81D0-F62CD5DD488D}.Debug WinXP|x64.ActiveCfg = Debug|Win32
{E57E4168-34AB-423D-81D0-F62CD5DD488D}.Debug XP|Win32.ActiveCfg = Debug|Win32
{E57E4168-34AB-423D-81D0-F62CD5DD488D}.Debug XP|Win32.Build.0 = Debug|Win32
{E57E4168-34AB-423D-81D0-F62CD5DD488D}.Debug XP|x64.ActiveCfg = Debug|Win32
{E57E4168-34AB-423D-81D0-F62CD5DD488D}.Debug|Win32.ActiveCfg = Debug|Win32
{E57E4168-34AB-423D-81D0-F62CD5DD488D}.Debug|Win32.Build.0 = Debug|Win32
{E57E4168-34AB-423D-81D0-F62CD5DD488D}.Debug|x64.ActiveCfg = Debug|Win32
{E57E4168-34AB-423D-81D0-F62CD5DD488D}.Release|Win32.ActiveCfg = Release|Win32
{E57E4168-34AB-423D-81D0-F62CD5DD488D}.Release|Win32.Build.0 = Release|Win32
{E57E4168-34AB-423D-81D0-F62CD5DD488D}.Release|x64.ActiveCfg = Release|Win32
{CE40A480-BD9D-446F-A549-23FD1D6868C2}.Debug WinXP|Win32.ActiveCfg = Debug|Win32
{CE40A480-BD9D-446F-A549-23FD1D6868C2}.Debug WinXP|Win32.Build.0 = Debug|Win32
{CE40A480-BD9D-446F-A549-23FD1D6868C2}.Debug WinXP|x64.ActiveCfg = Debug|Win32
{CE40A480-BD9D-446F-A549-23FD1D6868C2}.Debug XP|Win32.ActiveCfg = Debug|Win32
{CE40A480-BD9D-446F-A549-23FD1D6868C2}.Debug XP|Win32.Build.0 = Debug|Win32
{CE40A480-BD9D-446F-A549-23FD1D6868C2}.Debug XP|x64.ActiveCfg = Debug|Win32
{CE40A480-BD9D-446F-A549-23FD1D6868C2}.Debug|Win32.ActiveCfg = Debug|Win32
{CE40A480-BD9D-446F-A549-23FD1D6868C2}.Debug|Win32.Build.0 = Debug|Win32
{CE40A480-BD9D-446F-A549-23FD1D6868C2}.Debug|x64.ActiveCfg = Debug|Win32
{CE40A480-BD9D-446F-A549-23FD1D6868C2}.Release|Win32.ActiveCfg = Release|Win32
{CE40A480-BD9D-446F-A549-23FD1D6868C2}.Release|Win32.Build.0 = Release|Win32
{CE40A480-BD9D-446F-A549-23FD1D6868C2}.Release|x64.ActiveCfg = Release|Win32
{1586287F-DA39-425D-AAF9-C688569E50A9}.Debug WinXP|Win32.ActiveCfg = Debug|Win32
{1586287F-DA39-425D-AAF9-C688569E50A9}.Debug WinXP|Win32.Build.0 = Debug|Win32
{1586287F-DA39-425D-AAF9-C688569E50A9}.Debug WinXP|x64.ActiveCfg = Debug|Win32
{1586287F-DA39-425D-AAF9-C688569E50A9}.Debug XP|Win32.ActiveCfg = Debug|Win32
{1586287F-DA39-425D-AAF9-C688569E50A9}.Debug XP|Win32.Build.0 = Debug|Win32
{1586287F-DA39-425D-AAF9-C688569E50A9}.Debug XP|x64.ActiveCfg = Debug|Win32
{1586287F-DA39-425D-AAF9-C688569E50A9}.Debug|Win32.ActiveCfg = Debug|Win32
{1586287F-DA39-425D-AAF9-C688569E50A9}.Debug|Win32.Build.0 = Debug|Win32
{1586287F-DA39-425D-AAF9-C688569E50A9}.Debug|x64.ActiveCfg = Debug|Win32
{1586287F-DA39-425D-AAF9-C688569E50A9}.Release|Win32.ActiveCfg = Release|Win32
{1586287F-DA39-425D-AAF9-C688569E50A9}.Release|Win32.Build.0 = Release|Win32
{1586287F-DA39-425D-AAF9-C688569E50A9}.Release|x64.ActiveCfg = Release|Win32
{6D57C528-DAFB-42BA-9884-7D3B06F916DE}.Debug WinXP|Win32.ActiveCfg = Debug|Win32
{6D57C528-DAFB-42BA-9884-7D3B06F916DE}.Debug WinXP|Win32.Build.0 = Debug|Win32
{6D57C528-DAFB-42BA-9884-7D3B06F916DE}.Debug WinXP|x64.ActiveCfg = Debug|Win32
{6D57C528-DAFB-42BA-9884-7D3B06F916DE}.Debug XP|Win32.ActiveCfg = Debug|Win32
{6D57C528-DAFB-42BA-9884-7D3B06F916DE}.Debug XP|Win32.Build.0 = Debug|Win32
{6D57C528-DAFB-42BA-9884-7D3B06F916DE}.Debug XP|x64.ActiveCfg = Debug|Win32
{6D57C528-DAFB-42BA-9884-7D3B06F916DE}.Debug|Win32.ActiveCfg = Debug|Win32
{6D57C528-DAFB-42BA-9884-7D3B06F916DE}.Debug|Win32.Build.0 = Debug|Win32
{6D57C528-DAFB-42BA-9884-7D3B06F916DE}.Debug|x64.ActiveCfg = Debug|Win32
{6D57C528-DAFB-42BA-9884-7D3B06F916DE}.Release|Win32.ActiveCfg = Release|Win32
{6D57C528-DAFB-42BA-9884-7D3B06F916DE}.Release|Win32.Build.0 = Release|Win32
{6D57C528-DAFB-42BA-9884-7D3B06F916DE}.Release|x64.ActiveCfg = Release|Win32
{4BA4796E-008A-4963-8D0E-9C375C9A2B4B}.Debug WinXP|Win32.ActiveCfg = Debug|Win32
{4BA4796E-008A-4963-8D0E-9C375C9A2B4B}.Debug WinXP|Win32.Build.0 = Debug|Win32
{4BA4796E-008A-4963-8D0E-9C375C9A2B4B}.Debug WinXP|x64.ActiveCfg = Debug|Win32
{4BA4796E-008A-4963-8D0E-9C375C9A2B4B}.Debug XP|Win32.ActiveCfg = Debug|Win32
{4BA4796E-008A-4963-8D0E-9C375C9A2B4B}.Debug XP|Win32.Build.0 = Debug|Win32
{4BA4796E-008A-4963-8D0E-9C375C9A2B4B}.Debug XP|x64.ActiveCfg = Debug|Win32
{4BA4796E-008A-4963-8D0E-9C375C9A2B4B}.Debug|Win32.ActiveCfg = Debug|Win32
{4BA4796E-008A-4963-8D0E-9C375C9A2B4B}.Debug|Win32.Build.0 = Debug|Win32
{4BA4796E-008A-4963-8D0E-9C375C9A2B4B}.Debug|x64.ActiveCfg = Debug|Win32
{4BA4796E-008A-4963-8D0E-9C375C9A2B4B}.Release|Win32.ActiveCfg = Release|Win32
{4BA4796E-008A-4963-8D0E-9C375C9A2B4B}.Release|Win32.Build.0 = Release|Win32
{4BA4796E-008A-4963-8D0E-9C375C9A2B4B}.Release|x64.ActiveCfg = Release|Win32
{23D4C1E4-8721-4F25-B94C-4100B5E874E8}.Debug WinXP|Win32.ActiveCfg = Debug|Win32
{23D4C1E4-8721-4F25-B94C-4100B5E874E8}.Debug WinXP|Win32.Build.0 = Debug|Win32
{23D4C1E4-8721-4F25-B94C-4100B5E874E8}.Debug WinXP|x64.ActiveCfg = Debug|Win32
{23D4C1E4-8721-4F25-B94C-4100B5E874E8}.Debug XP|Win32.ActiveCfg = Debug|Win32
{23D4C1E4-8721-4F25-B94C-4100B5E874E8}.Debug XP|Win32.Build.0 = Debug|Win32
{23D4C1E4-8721-4F25-B94C-4100B5E874E8}.Debug XP|x64.ActiveCfg = Debug|Win32
{23D4C1E4-8721-4F25-B94C-4100B5E874E8}.Debug|Win32.ActiveCfg = Debug|Win32
{23D4C1E4-8721-4F25-B94C-4100B5E874E8}.Debug|Win32.Build.0 = Debug|Win32
{23D4C1E4-8721-4F25-B94C-4100B5E874E8}.Debug|x64.ActiveCfg = Debug|Win32
{23D4C1E4-8721-4F25-B94C-4100B5E874E8}.Release|Win32.ActiveCfg = Release|Win32
{23D4C1E4-8721-4F25-B94C-4100B5E874E8}.Release|Win32.Build.0 = Release|Win32
{23D4C1E4-8721-4F25-B94C-4100B5E874E8}.Release|x64.ActiveCfg = Release|Win32
{A9B12FBF-84D8-4BB6-B4A3-DD57F06637B0}.Debug WinXP|Win32.ActiveCfg = Debug|Win32
{A9B12FBF-84D8-4BB6-B4A3-DD57F06637B0}.Debug WinXP|Win32.Build.0 = Debug|Win32
{A9B12FBF-84D8-4BB6-B4A3-DD57F06637B0}.Debug WinXP|x64.ActiveCfg = Debug|Win32
{A9B12FBF-84D8-4BB6-B4A3-DD57F06637B0}.Debug XP|Win32.ActiveCfg = Debug|Win32
{A9B12FBF-84D8-4BB6-B4A3-DD57F06637B0}.Debug XP|Win32.Build.0 = Debug|Win32
{A9B12FBF-84D8-4BB6-B4A3-DD57F06637B0}.Debug XP|x64.ActiveCfg = Debug|Win32
{A9B12FBF-84D8-4BB6-B4A3-DD57F06637B0}.Debug|Win32.ActiveCfg = Debug|Win32
{A9B12FBF-84D8-4BB6-B4A3-DD57F06637B0}.Debug|Win32.Build.0 = Debug|Win32
{A9B12FBF-84D8-4BB6-B4A3-DD57F06637B0}.Debug|x64.ActiveCfg = Debug|Win32
{A9B12FBF-84D8-4BB6-B4A3-DD57F06637B0}.Release|Win32.ActiveCfg = Release|Win32
{A9B12FBF-84D8-4BB6-B4A3-DD57F06637B0}.Release|Win32.Build.0 = Release|Win32
{A9B12FBF-84D8-4BB6-B4A3-DD57F06637B0}.Release|x64.ActiveCfg = Release|x64
{A4E2527B-4886-4163-9411-10BF66A931BE}.Debug WinXP|Win32.ActiveCfg = Debug WinXP|Win32
{A4E2527B-4886-4163-9411-10BF66A931BE}.Debug WinXP|Win32.Build.0 = Debug WinXP|Win32
{A4E2527B-4886-4163-9411-10BF66A931BE}.Debug WinXP|x64.ActiveCfg = Release WinXP|x64
{A4E2527B-4886-4163-9411-10BF66A931BE}.Debug WinXP|x64.Build.0 = Debug WinXP|x64
{A4E2527B-4886-4163-9411-10BF66A931BE}.Debug XP|Win32.ActiveCfg = Release|Win32
{A4E2527B-4886-4163-9411-10BF66A931BE}.Debug XP|Win32.Build.0 = Release|Win32
{A4E2527B-4886-4163-9411-10BF66A931BE}.Debug XP|x64.ActiveCfg = Debug WinXP|x64
{A4E2527B-4886-4163-9411-10BF66A931BE}.Debug XP|x64.Build.0 = Debug WinXP|x64
{A4E2527B-4886-4163-9411-10BF66A931BE}.Debug|Win32.ActiveCfg = Debug|Win32
{A4E2527B-4886-4163-9411-10BF66A931BE}.Debug|Win32.Build.0 = Debug|Win32
{A4E2527B-4886-4163-9411-10BF66A931BE}.Debug|x64.ActiveCfg = Debug|x64
{A4E2527B-4886-4163-9411-10BF66A931BE}.Debug|x64.Build.0 = Debug|x64
{A4E2527B-4886-4163-9411-10BF66A931BE}.Release|Win32.ActiveCfg = Release Server 2003|x64
{A4E2527B-4886-4163-9411-10BF66A931BE}.Release|Win32.Build.0 = Release Server 2003|x64
{A4E2527B-4886-4163-9411-10BF66A931BE}.Release|x64.ActiveCfg = Release|x64
{A4E2527B-4886-4163-9411-10BF66A931BE}.Release|x64.Build.0 = Release|x64
{B1F1AF2E-E544-45F7-864A-883461A4B574}.Debug WinXP|Win32.ActiveCfg = Debug|Win32
{B1F1AF2E-E544-45F7-864A-883461A4B574}.Debug WinXP|Win32.Build.0 = Debug|Win32
{B1F1AF2E-E544-45F7-864A-883461A4B574}.Debug WinXP|x64.ActiveCfg = Debug|Win32
{B1F1AF2E-E544-45F7-864A-883461A4B574}.Debug XP|Win32.ActiveCfg = Debug|Win32
{B1F1AF2E-E544-45F7-864A-883461A4B574}.Debug XP|Win32.Build.0 = Debug|Win32
{B1F1AF2E-E544-45F7-864A-883461A4B574}.Debug XP|x64.ActiveCfg = Debug|Win32
{B1F1AF2E-E544-45F7-864A-883461A4B574}.Debug|Win32.ActiveCfg = Debug|Win32
{B1F1AF2E-E544-45F7-864A-883461A4B574}.Debug|Win32.Build.0 = Debug|Win32
{B1F1AF2E-E544-45F7-864A-883461A4B574}.Debug|x64.ActiveCfg = Debug|Win32
{B1F1AF2E-E544-45F7-864A-883461A4B574}.Release|Win32.ActiveCfg = Release|Win32
{B1F1AF2E-E544-45F7-864A-883461A4B574}.Release|Win32.Build.0 = Release|Win32
{B1F1AF2E-E544-45F7-864A-883461A4B574}.Release|x64.ActiveCfg = Release|x64
{20375DC0-38DA-4254-B479-EFA8028C29B1}.Debug WinXP|Win32.ActiveCfg = Debug|Win32
{20375DC0-38DA-4254-B479-EFA8028C29B1}.Debug WinXP|Win32.Build.0 = Debug|Win32
{20375DC0-38DA-4254-B479-EFA8028C29B1}.Debug WinXP|x64.ActiveCfg = Debug|Win32
{20375DC0-38DA-4254-B479-EFA8028C29B1}.Debug XP|Win32.ActiveCfg = Debug|Win32
{20375DC0-38DA-4254-B479-EFA8028C29B1}.Debug XP|Win32.Build.0 = Debug|Win32
{20375DC0-38DA-4254-B479-EFA8028C29B1}.Debug XP|x64.ActiveCfg = Debug|Win32
{20375DC0-38DA-4254-B479-EFA8028C29B1}.Debug|Win32.ActiveCfg = Debug|Win32
{20375DC0-38DA-4254-B479-EFA8028C29B1}.Debug|Win32.Build.0 = Debug|Win32
{20375DC0-38DA-4254-B479-EFA8028C29B1}.Debug|x64.ActiveCfg = Debug|Win32
{20375DC0-38DA-4254-B479-EFA8028C29B1}.Release|Win32.ActiveCfg = Release|Win32
{20375DC0-38DA-4254-B479-EFA8028C29B1}.Release|Win32.Build.0 = Release|Win32
{20375DC0-38DA-4254-B479-EFA8028C29B1}.Release|x64.ActiveCfg = Release|x64
{DB4FFADB-B1D0-4D52-8CD5-C9AE479CA565}.Debug WinXP|Win32.ActiveCfg = Debug|Win32
{DB4FFADB-B1D0-4D52-8CD5-C9AE479CA565}.Debug WinXP|Win32.Build.0 = Debug|Win32
{DB4FFADB-B1D0-4D52-8CD5-C9AE479CA565}.Debug WinXP|x64.ActiveCfg = Debug|Win32
{DB4FFADB-B1D0-4D52-8CD5-C9AE479CA565}.Debug XP|Win32.ActiveCfg = Debug|Win32
{DB4FFADB-B1D0-4D52-8CD5-C9AE479CA565}.Debug XP|Win32.Build.0 = Debug|Win32
{DB4FFADB-B1D0-4D52-8CD5-C9AE479CA565}.Debug XP|x64.ActiveCfg = Debug|Win32
{DB4FFADB-B1D0-4D52-8CD5-C9AE479CA565}.Debug|Win32.ActiveCfg = Debug|Win32
{DB4FFADB-B1D0-4D52-8CD5-C9AE479CA565}.Debug|Win32.Build.0 = Debug|Win32
{DB4FFADB-B1D0-4D52-8CD5-C9AE479CA565}.Debug|x64.ActiveCfg = Debug|Win32
{DB4FFADB-B1D0-4D52-8CD5-C9AE479CA565}.Release|Win32.ActiveCfg = Release|Win32
{DB4FFADB-B1D0-4D52-8CD5-C9AE479CA565}.Release|Win32.Build.0 = Release|Win32
{DB4FFADB-B1D0-4D52-8CD5-C9AE479CA565}.Release|x64.ActiveCfg = Release|Win32
{835A9C1D-BDEE-44A2-97DB-EF9C4AE59F45}.Debug WinXP|Win32.ActiveCfg = Debug|Win32
{835A9C1D-BDEE-44A2-97DB-EF9C4AE59F45}.Debug WinXP|Win32.Build.0 = Debug|Win32
{835A9C1D-BDEE-44A2-97DB-EF9C4AE59F45}.Debug WinXP|x64.ActiveCfg = Debug|Win32
{835A9C1D-BDEE-44A2-97DB-EF9C4AE59F45}.Debug XP|Win32.ActiveCfg = Debug|Win32
{835A9C1D-BDEE-44A2-97DB-EF9C4AE59F45}.Debug XP|Win32.Build.0 = Debug|Win32
{835A9C1D-BDEE-44A2-97DB-EF9C4AE59F45}.Debug XP|x64.ActiveCfg = Debug|Win32
{835A9C1D-BDEE-44A2-97DB-EF9C4AE59F45}.Debug|Win32.ActiveCfg = Debug|Win32
{835A9C1D-BDEE-44A2-97DB-EF9C4AE59F45}.Debug|Win32.Build.0 = Debug|Win32
{835A9C1D-BDEE-44A2-97DB-EF9C4AE59F45}.Debug|x64.ActiveCfg = Debug|Win32
{835A9C1D-BDEE-44A2-97DB-EF9C4AE59F45}.Release|Win32.ActiveCfg = Release|Win32
{835A9C1D-BDEE-44A2-97DB-EF9C4AE59F45}.Release|Win32.Build.0 = Release|Win32
{835A9C1D-BDEE-44A2-97DB-EF9C4AE59F45}.Release|x64.ActiveCfg = Release|Win32
{81EE2F6D-6A48-423B-8BBB-B97DB74EDD0F}.Debug WinXP|Win32.ActiveCfg = Debug|Win32
{81EE2F6D-6A48-423B-8BBB-B97DB74EDD0F}.Debug WinXP|Win32.Build.0 = Debug|Win32
{81EE2F6D-6A48-423B-8BBB-B97DB74EDD0F}.Debug WinXP|x64.ActiveCfg = Debug|Win32
{81EE2F6D-6A48-423B-8BBB-B97DB74EDD0F}.Debug XP|Win32.ActiveCfg = Debug|Win32
{81EE2F6D-6A48-423B-8BBB-B97DB74EDD0F}.Debug XP|Win32.Build.0 = Debug|Win32
{81EE2F6D-6A48-423B-8BBB-B97DB74EDD0F}.Debug XP|x64.ActiveCfg = Debug|Win32
{81EE2F6D-6A48-423B-8BBB-B97DB74EDD0F}.Debug|Win32.ActiveCfg = Debug|Win32
{81EE2F6D-6A48-423B-8BBB-B97DB74EDD0F}.Debug|Win32.Build.0 = Debug|Win32
{81EE2F6D-6A48-423B-8BBB-B97DB74EDD0F}.Debug|x64.ActiveCfg = Debug|Win32
{81EE2F6D-6A48-423B-8BBB-B97DB74EDD0F}.Release|Win32.ActiveCfg = Release|Win32
{81EE2F6D-6A48-423B-8BBB-B97DB74EDD0F}.Release|Win32.Build.0 = Release|Win32
{81EE2F6D-6A48-423B-8BBB-B97DB74EDD0F}.Release|x64.ActiveCfg = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal

371
CompiledServer.vcxproj Normal file
View File

@ -0,0 +1,371 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug|x64">
<Configuration>Debug</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release Service|Win32">
<Configuration>Release Service</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release Service|x64">
<Configuration>Release Service</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|x64">
<Configuration>Release</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{8546D6E2-1872-418B-9766-E40F33689BE4}</ProjectGuid>
<RootNamespace>CompiledServer</RootNamespace>
<Keyword>Win32Proj</Keyword>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release Service|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<CharacterSet>Unicode</CharacterSet>
<WholeProgramOptimization>true</WholeProgramOptimization>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<CharacterSet>Unicode</CharacterSet>
<WholeProgramOptimization>true</WholeProgramOptimization>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release Service|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<CharacterSet>Unicode</CharacterSet>
<WholeProgramOptimization>true</WholeProgramOptimization>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<CharacterSet>Unicode</CharacterSet>
<WholeProgramOptimization>true</WholeProgramOptimization>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release Service|Win32'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release Service|x64'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup>
<_ProjectFileVersion>10.0.30319.1</_ProjectFileVersion>
<OutDir Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">$(SolutionDir)$(Configuration)\</OutDir>
<IntDir Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">$(Configuration)\</IntDir>
<LinkIncremental Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</LinkIncremental>
<OutDir Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">$(SolutionDir)$(Platform)\$(Configuration)\</OutDir>
<IntDir Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">$(Platform)\$(Configuration)\</IntDir>
<LinkIncremental Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</LinkIncremental>
<OutDir Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">$(SolutionDir)$(Configuration)\</OutDir>
<IntDir Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">$(Configuration)\</IntDir>
<LinkIncremental Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">false</LinkIncremental>
<OutDir Condition="'$(Configuration)|$(Platform)'=='Release|x64'">$(SolutionDir)$(Platform)\$(Configuration)\</OutDir>
<IntDir Condition="'$(Configuration)|$(Platform)'=='Release|x64'">$(Platform)\$(Configuration)\</IntDir>
<LinkIncremental Condition="'$(Configuration)|$(Platform)'=='Release|x64'">false</LinkIncremental>
<OutDir Condition="'$(Configuration)|$(Platform)'=='Release Service|Win32'">$(SolutionDir)$(Configuration)\</OutDir>
<IntDir Condition="'$(Configuration)|$(Platform)'=='Release Service|Win32'">$(Configuration)\</IntDir>
<LinkIncremental Condition="'$(Configuration)|$(Platform)'=='Release Service|Win32'">false</LinkIncremental>
<OutDir Condition="'$(Configuration)|$(Platform)'=='Release Service|x64'">$(SolutionDir)$(Platform)\$(Configuration)\</OutDir>
<IntDir Condition="'$(Configuration)|$(Platform)'=='Release Service|x64'">$(Platform)\$(Configuration)\</IntDir>
<LinkIncremental Condition="'$(Configuration)|$(Platform)'=='Release Service|x64'">false</LinkIncremental>
<CodeAnalysisRuleSet Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">AllRules.ruleset</CodeAnalysisRuleSet>
<CodeAnalysisRules Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" />
<CodeAnalysisRuleAssemblies Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" />
<CodeAnalysisRuleSet Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">AllRules.ruleset</CodeAnalysisRuleSet>
<CodeAnalysisRules Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" />
<CodeAnalysisRuleAssemblies Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" />
<CodeAnalysisRuleSet Condition="'$(Configuration)|$(Platform)'=='Release Service|Win32'">AllRules.ruleset</CodeAnalysisRuleSet>
<CodeAnalysisRules Condition="'$(Configuration)|$(Platform)'=='Release Service|Win32'" />
<CodeAnalysisRuleAssemblies Condition="'$(Configuration)|$(Platform)'=='Release Service|Win32'" />
<CodeAnalysisRuleSet Condition="'$(Configuration)|$(Platform)'=='Release Service|x64'">AllRules.ruleset</CodeAnalysisRuleSet>
<CodeAnalysisRules Condition="'$(Configuration)|$(Platform)'=='Release Service|x64'" />
<CodeAnalysisRuleAssemblies Condition="'$(Configuration)|$(Platform)'=='Release Service|x64'" />
<CodeAnalysisRuleSet Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">AllRules.ruleset</CodeAnalysisRuleSet>
<CodeAnalysisRules Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" />
<CodeAnalysisRuleAssemblies Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" />
<CodeAnalysisRuleSet Condition="'$(Configuration)|$(Platform)'=='Release|x64'">AllRules.ruleset</CodeAnalysisRuleSet>
<CodeAnalysisRules Condition="'$(Configuration)|$(Platform)'=='Release|x64'" />
<CodeAnalysisRuleAssemblies Condition="'$(Configuration)|$(Platform)'=='Release|x64'" />
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<Optimization>Disabled</Optimization>
<AdditionalIncludeDirectories>./libfastcgi_win;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;SQLITE_ENABLE_UNLOCK_NOTIFY;THREAD_BOOST;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<MinimalRebuild>true</MinimalRebuild>
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
<RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
<PrecompiledHeader>
</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<DebugInformationFormat>EditAndContinue</DebugInformationFormat>
<DisableSpecificWarnings>4005;%(DisableSpecificWarnings)</DisableSpecificWarnings>
</ClCompile>
<Link>
<AdditionalLibraryDirectories>libx86;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<GenerateDebugInformation>true</GenerateDebugInformation>
<SubSystem>Console</SubSystem>
<RandomizedBaseAddress>false</RandomizedBaseAddress>
<DataExecutionPrevention>
</DataExecutionPrevention>
<TargetMachine>MachineX86</TargetMachine>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<Midl>
<TargetEnvironment>X64</TargetEnvironment>
</Midl>
<ClCompile>
<Optimization>Disabled</Optimization>
<AdditionalIncludeDirectories>./libfastcgi_win;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;SQLITE_ENABLE_UNLOCK_NOTIFY;THREAD_BOOST;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<MinimalRebuild>true</MinimalRebuild>
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
<RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
<PrecompiledHeader>
</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
<DisableSpecificWarnings>4005;%(DisableSpecificWarnings)</DisableSpecificWarnings>
</ClCompile>
<Link>
<AdditionalLibraryDirectories>%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<GenerateDebugInformation>true</GenerateDebugInformation>
<SubSystem>Console</SubSystem>
<RandomizedBaseAddress>false</RandomizedBaseAddress>
<DataExecutionPrevention>
</DataExecutionPrevention>
<TargetMachine>MachineX64</TargetMachine>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<AdditionalIncludeDirectories>./libfastcgi_win;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;SQLITE_ENABLE_UNLOCK_NOTIFY;THREAD_BOOST;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
<PrecompiledHeader>
</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
</ClCompile>
<Link>
<AdditionalLibraryDirectories>libx86;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<GenerateDebugInformation>true</GenerateDebugInformation>
<SubSystem>Console</SubSystem>
<OptimizeReferences>true</OptimizeReferences>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<RandomizedBaseAddress>false</RandomizedBaseAddress>
<DataExecutionPrevention>
</DataExecutionPrevention>
<TargetMachine>MachineX86</TargetMachine>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<Midl>
<TargetEnvironment>X64</TargetEnvironment>
</Midl>
<ClCompile>
<AdditionalIncludeDirectories>./libfastcgi_win;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;SQLITE_ENABLE_UNLOCK_NOTIFY;THREAD_BOOST;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
<PrecompiledHeader>
</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
</ClCompile>
<Link>
<GenerateDebugInformation>true</GenerateDebugInformation>
<SubSystem>Console</SubSystem>
<OptimizeReferences>true</OptimizeReferences>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<RandomizedBaseAddress>false</RandomizedBaseAddress>
<DataExecutionPrevention>
</DataExecutionPrevention>
<TargetMachine>MachineX64</TargetMachine>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release Service|Win32'">
<ClCompile>
<AdditionalIncludeDirectories>./libfastcgi_win;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;AS_SERVICE;SQLITE_ENABLE_UNLOCK_NOTIFY;THREAD_BOOST;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
<PrecompiledHeader>
</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
</ClCompile>
<Link>
<AdditionalLibraryDirectories>libx86/;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<GenerateDebugInformation>true</GenerateDebugInformation>
<SubSystem>Console</SubSystem>
<OptimizeReferences>true</OptimizeReferences>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<RandomizedBaseAddress>false</RandomizedBaseAddress>
<DataExecutionPrevention>
</DataExecutionPrevention>
<TargetMachine>MachineX86</TargetMachine>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release Service|x64'">
<Midl>
<TargetEnvironment>X64</TargetEnvironment>
</Midl>
<ClCompile>
<AdditionalIncludeDirectories>./libfastcgi_win;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;AS_SERVICE;SQLITE_ENABLE_UNLOCK_NOTIFY;THREAD_BOOST;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
<PrecompiledHeader>
</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
</ClCompile>
<Link>
<AdditionalLibraryDirectories>libx64/;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<GenerateDebugInformation>true</GenerateDebugInformation>
<SubSystem>Console</SubSystem>
<OptimizeReferences>true</OptimizeReferences>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<RandomizedBaseAddress>false</RandomizedBaseAddress>
<DataExecutionPrevention>
</DataExecutionPrevention>
<TargetMachine>MachineX64</TargetMachine>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="AcceptThread.cpp" />
<ClCompile Include="Client.cpp" />
<ClCompile Include="Condition_boost.cpp" />
<ClCompile Include="Database.cpp" />
<ClCompile Include="DBSettingsReader.cpp" />
<ClCompile Include="file_common.cpp" />
<ClCompile Include="file_fstream.cpp" />
<ClCompile Include="file_linux.cpp" />
<ClCompile Include="file_memory.cpp" />
<ClCompile Include="file_win.cpp" />
<ClCompile Include="FileSettingsReader.cpp" />
<ClCompile Include="LoadbalancerClient.cpp" />
<ClCompile Include="LookupService.cpp" />
<ClCompile Include="main.cpp" />
<ClCompile Include="maintest.cpp" />
<ClCompile Include="md5.cpp" />
<ClCompile Include="MemoryPipe.cpp" />
<ClCompile Include="MemorySettingsReader.cpp" />
<ClCompile Include="Mutex_boost.cpp" />
<ClCompile Include="OutputStream.cpp" />
<ClCompile Include="Query.cpp" />
<ClCompile Include="SelectThread.cpp" />
<ClCompile Include="Server.cpp" />
<ClCompile Include="ServerWin32.cpp" />
<ClCompile Include="ServiceAcceptor.cpp" />
<ClCompile Include="ServiceWorker.cpp" />
<ClCompile Include="SessionMgr.cpp" />
<ClCompile Include="SettingsReader.cpp" />
<ClCompile Include="StreamPipe.cpp" />
<ClCompile Include="stringtools.cpp" />
<ClCompile Include="Table.cpp" />
<ClCompile Include="Template.cpp" />
<ClCompile Include="ThreadPool.cpp" />
<ClCompile Include="WorkerThread.cpp" />
<ClCompile Include="libfastcgi\fastcgi.cpp" />
<ClCompile Include="win_service\nt_service.cpp" />
<ClCompile Include="sqlite\sqlite3.c" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="AcceptThread.h" />
<ClInclude Include="Client.h" />
<ClInclude Include="Condition_boost.h" />
<ClInclude Include="Database.h" />
<ClInclude Include="DBSettingsReader.h" />
<ClInclude Include="defaults.h" />
<ClInclude Include="file.h" />
<ClInclude Include="file_memory.h" />
<ClInclude Include="FileSettingsReader.h" />
<ClInclude Include="libs.h" />
<ClInclude Include="LoadbalancerClient.h" />
<ClInclude Include="LookupService.h" />
<ClInclude Include="md5.h" />
<ClInclude Include="MemoryPipe.h" />
<ClInclude Include="MemorySettingsReader.h" />
<ClInclude Include="Mutex_boost.h" />
<ClInclude Include="OutputStream.h" />
<ClInclude Include="Query.h" />
<ClInclude Include="SelectThread.h" />
<ClInclude Include="Server.h" />
<ClInclude Include="ServiceAcceptor.h" />
<ClInclude Include="ServiceWorker.h" />
<ClInclude Include="SessionMgr.h" />
<ClInclude Include="SettingsReader.h" />
<ClInclude Include="socket_header.h" />
<ClInclude Include="StreamPipe.h" />
<ClInclude Include="stringtools.h" />
<ClInclude Include="Table.h" />
<ClInclude Include="Template.h" />
<ClInclude Include="ThreadPool.h" />
<ClInclude Include="types.h" />
<ClInclude Include="vld.h" />
<ClInclude Include="WorkerThread.h" />
<ClInclude Include="Interface\Action.h" />
<ClInclude Include="Interface\Condition.h" />
<ClInclude Include="Interface\CustomClient.h" />
<ClInclude Include="Interface\Database.h" />
<ClInclude Include="Interface\File.h" />
<ClInclude Include="Interface\Mutex.h" />
<ClInclude Include="Interface\Object.h" />
<ClInclude Include="Interface\OutputStream.h" />
<ClInclude Include="Interface\Pipe.h" />
<ClInclude Include="Interface\Plugin.h" />
<ClInclude Include="Interface\PluginMgr.h" />
<ClInclude Include="Interface\Query.h" />
<ClInclude Include="Interface\Server.h" />
<ClInclude Include="Interface\Service.h" />
<ClInclude Include="Interface\SessionMgr.h" />
<ClInclude Include="Interface\SettingsReader.h" />
<ClInclude Include="Interface\Table.h" />
<ClInclude Include="Interface\Template.h" />
<ClInclude Include="Interface\Thread.h" />
<ClInclude Include="Interface\ThreadPool.h" />
<ClInclude Include="Interface\Types.h" />
<ClInclude Include="Interface\User.h" />
<ClInclude Include="libfastcgi\fastcgi.hpp" />
<ClInclude Include="win_service\nt_service.h" />
<ClInclude Include="win_service\nt_service_impl.h" />
<ClInclude Include="sqlite\sqlite3.h" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>

View File

@ -0,0 +1,321 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="Source Files">
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
</Filter>
<Filter Include="Header Files">
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
<Extensions>h;hpp;hxx;hm;inl;inc;xsd</Extensions>
</Filter>
<Filter Include="Resource Files">
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav</Extensions>
</Filter>
<Filter Include="Interface">
<UniqueIdentifier>{dbe5d795-4050-4d15-823d-60fdb163a210}</UniqueIdentifier>
</Filter>
<Filter Include="fastcgi">
<UniqueIdentifier>{ee9dafbd-6268-4f17-b4fc-c50aa8ad1f78}</UniqueIdentifier>
</Filter>
<Filter Include="win_service">
<UniqueIdentifier>{b763e0d2-04f4-461a-92d0-01ae72cb1aaf}</UniqueIdentifier>
</Filter>
<Filter Include="sqlite">
<UniqueIdentifier>{7a557854-2437-489d-b88e-d49cd2e7bbda}</UniqueIdentifier>
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="AcceptThread.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="Client.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="Condition_boost.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="Database.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="DBSettingsReader.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="file_common.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="file_fstream.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="file_linux.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="file_memory.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="file_win.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="FileSettingsReader.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="LoadbalancerClient.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="LookupService.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="main.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="maintest.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="md5.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="MemoryPipe.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="MemorySettingsReader.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="Mutex_boost.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="OutputStream.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="Query.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="SelectThread.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="Server.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="ServerWin32.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="ServiceAcceptor.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="ServiceWorker.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="SessionMgr.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="SettingsReader.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="StreamPipe.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="stringtools.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="Table.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="Template.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="ThreadPool.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="WorkerThread.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="libfastcgi\fastcgi.cpp">
<Filter>fastcgi</Filter>
</ClCompile>
<ClCompile Include="win_service\nt_service.cpp">
<Filter>win_service</Filter>
</ClCompile>
<ClCompile Include="sqlite\sqlite3.c">
<Filter>sqlite</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="AcceptThread.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Client.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Condition_boost.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Database.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="DBSettingsReader.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="defaults.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="file.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="file_memory.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="FileSettingsReader.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="libs.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="LoadbalancerClient.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="LookupService.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="md5.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="MemoryPipe.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="MemorySettingsReader.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Mutex_boost.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="OutputStream.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Query.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="SelectThread.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Server.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="ServiceAcceptor.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="ServiceWorker.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="SessionMgr.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="SettingsReader.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="socket_header.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="StreamPipe.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="stringtools.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Table.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Template.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="ThreadPool.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="types.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="vld.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="WorkerThread.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Interface\Action.h">
<Filter>Interface</Filter>
</ClInclude>
<ClInclude Include="Interface\Condition.h">
<Filter>Interface</Filter>
</ClInclude>
<ClInclude Include="Interface\CustomClient.h">
<Filter>Interface</Filter>
</ClInclude>
<ClInclude Include="Interface\Database.h">
<Filter>Interface</Filter>
</ClInclude>
<ClInclude Include="Interface\File.h">
<Filter>Interface</Filter>
</ClInclude>
<ClInclude Include="Interface\Mutex.h">
<Filter>Interface</Filter>
</ClInclude>
<ClInclude Include="Interface\Object.h">
<Filter>Interface</Filter>
</ClInclude>
<ClInclude Include="Interface\OutputStream.h">
<Filter>Interface</Filter>
</ClInclude>
<ClInclude Include="Interface\Pipe.h">
<Filter>Interface</Filter>
</ClInclude>
<ClInclude Include="Interface\Plugin.h">
<Filter>Interface</Filter>
</ClInclude>
<ClInclude Include="Interface\PluginMgr.h">
<Filter>Interface</Filter>
</ClInclude>
<ClInclude Include="Interface\Query.h">
<Filter>Interface</Filter>
</ClInclude>
<ClInclude Include="Interface\Server.h">
<Filter>Interface</Filter>
</ClInclude>
<ClInclude Include="Interface\Service.h">
<Filter>Interface</Filter>
</ClInclude>
<ClInclude Include="Interface\SessionMgr.h">
<Filter>Interface</Filter>
</ClInclude>
<ClInclude Include="Interface\SettingsReader.h">
<Filter>Interface</Filter>
</ClInclude>
<ClInclude Include="Interface\Table.h">
<Filter>Interface</Filter>
</ClInclude>
<ClInclude Include="Interface\Template.h">
<Filter>Interface</Filter>
</ClInclude>
<ClInclude Include="Interface\Thread.h">
<Filter>Interface</Filter>
</ClInclude>
<ClInclude Include="Interface\ThreadPool.h">
<Filter>Interface</Filter>
</ClInclude>
<ClInclude Include="Interface\Types.h">
<Filter>Interface</Filter>
</ClInclude>
<ClInclude Include="Interface\User.h">
<Filter>Interface</Filter>
</ClInclude>
<ClInclude Include="libfastcgi\fastcgi.hpp">
<Filter>fastcgi</Filter>
</ClInclude>
<ClInclude Include="win_service\nt_service.h">
<Filter>win_service</Filter>
</ClInclude>
<ClInclude Include="win_service\nt_service_impl.h">
<Filter>win_service</Filter>
</ClInclude>
<ClInclude Include="sqlite\sqlite3.h">
<Filter>sqlite</Filter>
</ClInclude>
</ItemGroup>
</Project>

56
Condition_boost.cpp Normal file
View File

@ -0,0 +1,56 @@
/*************************************************************************
* UrBackup - Client/Server backup system
* Copyright (C) 2011 Martin Raiber
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
**************************************************************************/
#include "Condition_boost.h"
#include "Mutex_boost.h"
#include "Server.h"
void CCondition::wait(IScopedLock *lock, int timems)
{
boost::recursive_mutex::scoped_lock *tl=((CLock*)lock->getLock())->getLock();
if(timems<0)
cond.wait(*tl);
else
{
cond.timed_wait(*tl, getWaitTime(timems));
}
}
boost::xtime CCondition::getWaitTime(int timeoutms)
{
boost::xtime xt;
xtime_get(&xt, boost::TIME_UTC);
if( timeoutms>1000 )
{
xt.sec+=timeoutms/1000;
timeoutms=timeoutms%1000;
}
xt.nsec+=timeoutms*1000000;
return xt;
}
void CCondition::notify_one(void)
{
cond.notify_one();
}
void CCondition::notify_all(void)
{
cond.notify_all();
}

18
Condition_boost.h Normal file
View File

@ -0,0 +1,18 @@
#include "Interface/Condition.h"
#include <boost/thread/condition.hpp>
#include <boost/thread/xtime.hpp>
class CCondition : public ICondition
{
public:
CCondition(void){}
virtual void wait(IScopedLock *lock, int timems=-1);
virtual void notify_one(void);
virtual void notify_all(void);
static boost::xtime getWaitTime(int timeoutms);
private:
boost::condition cond;
};

62
Condition_lin.cpp Normal file
View File

@ -0,0 +1,62 @@
/*************************************************************************
* UrBackup - Client/Server backup system
* Copyright (C) 2011 Martin Raiber
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
**************************************************************************/
#include "Condition_lin.h"
#include "Mutex_lin.h"
#ifndef _WIN32
#include <sys/time.h>
#endif
CCondition::CCondition()
{
pthread_cond_init(&cond, NULL);
}
CCondition::~CCondition()
{
pthread_cond_destroy(&cond);
}
void CCondition::wait(IScopedLock *lock, int timems)
{
pthread_mutex_t *ptmutex=((CLock*)lock->getLock())->getLock();
if(timems<0)
{
pthread_cond_wait(&cond, ptmutex);
}
else
{
timeval tp;
gettimeofday(&tp, NULL);
timespec t;
t.tv_sec=tp.tv_sec+timems/(int)1000;
t.tv_nsec=tp.tv_usec+(timems%1000)*1000000;
pthread_cond_timedwait(&cond, ptmutex, &t);
}
}
void CCondition::notify_one(void)
{
pthread_cond_signal(&cond);
}
void CCondition::notify_all(void)
{
pthread_cond_broadcast(&cond);
}

16
Condition_lin.h Normal file
View File

@ -0,0 +1,16 @@
#include "Interface/Condition.h"
#include <pthread.h>
class CCondition : public ICondition
{
public:
CCondition();
~CCondition();
virtual void wait(IScopedLock *lock, int timems=-1);
virtual void notify_one(void);
virtual void notify_all(void);
private:
pthread_cond_t cond;
};

78
DBSettingsReader.cpp Normal file
View File

@ -0,0 +1,78 @@
/*************************************************************************
* UrBackup - Client/Server backup system
* Copyright (C) 2011 Martin Raiber
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
**************************************************************************/
#include "Interface/Types.h"
#include "SettingsReader.h"
#include "stringtools.h"
#include "Server.h"
#include "DBSettingsReader.h"
#include <iostream>
CDBSettingsReader::CDBSettingsReader(THREAD_ID tid, DATABASE_ID did, const std::string &pTable, const std::string &pSQL)
{
table=pTable;
IDatabase *db=Server->getDatabase(tid, did);
if(pSQL.empty() )
query=db->Prepare("SELECT value FROM "+table+" WHERE key=?");
else
query=db->Prepare(pSQL);
}
CDBSettingsReader::CDBSettingsReader(IDatabase *pDB, const std::string &pTable, const std::string &pSQL)
{
table=pTable;
if(pSQL.empty() )
query=pDB->Prepare("SELECT value FROM "+table+" WHERE key=?");
else
query=pDB->Prepare(pSQL);
}
bool CDBSettingsReader::getValue(std::string key, std::string *value)
{
query->Bind(key);
db_nresults res=query->ReadN();
query->Reset();
if( res.size()>0 )
{
*value=res[0]["value"];
return true;
}
else
return false;
}
bool CDBSettingsReader::getValue(std::wstring key, std::wstring *value)
{
query->Bind(key);
db_results res=query->Read();
query->Reset();
if( res.size()>0 )
{
*value=res[0][L"value"];
return true;
}
else
return false;
}

17
DBSettingsReader.h Normal file
View File

@ -0,0 +1,17 @@
class IDatabase;
class IQuery;
class CDBSettingsReader : public CSettingsReader
{
public:
CDBSettingsReader(THREAD_ID tid, DATABASE_ID did, const std::string &pTable, const std::string &pSQL="");
CDBSettingsReader(IDatabase *pDB, const std::string &pTable, const std::string &pSQL="");
bool getValue(std::string key, std::string *value);
bool getValue(std::wstring key, std::wstring *value);
private:
std::string table;
IQuery *query;
};

310
Database.cpp Normal file
View File

@ -0,0 +1,310 @@
/*************************************************************************
* UrBackup - Client/Server backup system
* Copyright (C) 2011 Martin Raiber
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
**************************************************************************/
#include "vld.h"
#include "Server.h"
#include "Query.h"
#include "sqlite/sqlite3.h"
IMutex * CDatabase::lock_mutex=NULL;
#ifdef _WIN32
#ifdef _DEBUG
#pragma comment ( lib , "sqlite/sqlite3_dll_debug.lib" )
#else if _RELEASE
#pragma comment ( lib , "sqlite/sqlite3_dll_release.lib" )
#endif
#endif
struct UnlockNotification {
bool fired;
ICondition* cond;
IMutex *mutex;
};
static int callback(void *CPtr, int argc, char **argv, char **azColName)
{
CDatabase* db=(CDatabase*)CPtr;
db_nsingle_result result;
for(int i=0; i<argc; i++)
{
//printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
if( azColName[i] && argv[i])
result.insert(std::pair<std::string,std::string>(azColName[i], argv[i]) );
}
db->InsertResults(result);
return 0;
}
static void unlock_notify_cb(void **apArg, int nArg)
{
for(int i=0; i<nArg; i++)
{
UnlockNotification *p = (UnlockNotification *)apArg[i];
IScopedLock lock(p->mutex);
p->fired = true;
p->cond->notify_all();
}
}
CDatabase::~CDatabase()
{
destroyAllQueries();
for(std::map<int, IQuery*>::iterator iter=prepared_queries.begin();iter!=prepared_queries.end();++iter)
{
CQuery *q=(CQuery*)iter->second;
delete q;
}
prepared_queries.clear();
sqlite3_close(db);
}
bool CDatabase::Open(std::string pFile)
{
if( sqlite3_open(pFile.c_str(), &db) )
{
Server->Log("Could not open db ["+pFile+"]");
sqlite3_close(db);
return false;
}
else
{
sqlite3_busy_timeout(db, 50);
Write("PRAGMA foreign_keys = ON");
return true;
}
}
void CDatabase::initMutex(void)
{
lock_mutex=Server->createMutex();
}
void CDatabase::destroyMutex(void)
{
Server->destroy(lock_mutex);
}
db_nresults CDatabase::ReadN(std::string pQuery)
{
//Server->Log("SQL Query(Read): "+pQuery);
results.clear();
char *zErrMsg = 0;
int rc=sqlite3_exec(db, pQuery.c_str(), callback, this, &zErrMsg);
if( rc!=SQLITE_OK )
{
Server->Log("SQL ERROR: "+(std::string)zErrMsg);
}
if( zErrMsg!=NULL )
sqlite3_free(zErrMsg);
return results;
}
db_results CDatabase::Read(std::string pQuery)
{
//Server->Log("SQL Query(Read): "+pQuery, LL_DEBUG);
IQuery *q=Prepare(pQuery, false);
db_results ret=q->Read();
delete ((CQuery*)q);
return ret;
}
bool CDatabase::Write(std::string pQuery)
{
//Server->Log("SQL Query(Write): "+pQuery, LL_DEBUG);
IQuery *q=Prepare(pQuery, false);
if(q!=NULL)
{
bool b=q->Write();
delete ((CQuery*)q);
return b;
}
else
{
return false;
}
}
void CDatabase::InsertResults(const db_nsingle_result &pResult)
{
results.push_back(pResult);
}
//ToDo: Cache Writings
void CDatabase::BeginTransaction(void)
{
Write("BEGIN IMMEDIATE;");
}
bool CDatabase::EndTransaction(void)
{
Write("END;");
if(lock_mutex->TryLock())
{
lock_mutex->Unlock();
Server->wait(100);
}
return true;
}
IQuery* CDatabase::Prepare(std::string pQuery, bool autodestroy)
{
sqlite3_stmt *prepared_statement;
const char* tail;
int err;
bool transaction_lock=false;
while((err=sqlite3_prepare_v2(db, pQuery.c_str(), (int)pQuery.size(), &prepared_statement, &tail) )==SQLITE_LOCKED || err==SQLITE_BUSY)
{
if(err==SQLITE_LOCKED)
{
if(LockForTransaction())
{
transaction_lock=true;
if(!WaitForUnlock())
Server->Log("DATABASE DEADLOCKED in CDatabase::Prepare", LL_ERROR);
}
}
else
{
if(transaction_lock==false)
{
if(LockForTransaction())
{
transaction_lock=true;
}
sqlite3_busy_timeout(db, 10000);
}
else
{
Server->Log("DATABASE BUSY in CDatabase::Prepare", LL_ERROR);
}
}
}
if(transaction_lock)
{
UnlockForTransaction();
sqlite3_busy_timeout(db, 50);
}
if( err!=SQLITE_OK )
{
Server->Log("Error preparing Query ["+pQuery+"]: "+sqlite3_errmsg(db),LL_ERROR);
return NULL;
}
CQuery *q=new CQuery(pQuery, prepared_statement, this);
if( autodestroy )
queries.push_back(q);
return q;
}
IQuery* CDatabase::Prepare(int id, std::string pQuery)
{
std::map<int, IQuery*>::iterator iter=prepared_queries.find(id);
if( iter!=prepared_queries.end() )
{
iter->second->Reset();
return iter->second;
}
else
{
IQuery *q=Prepare(pQuery, false);
prepared_queries.insert(std::pair<int, IQuery*>(id, q) );
return q;
}
}
void CDatabase::destroyQuery(IQuery *q)
{
for(size_t i=0;i<queries.size();++i)
{
if( queries[i]==q )
{
CQuery *cq=(CQuery*)q;
delete cq;
queries.erase( queries.begin()+i);
return;
}
}
CQuery *cq=(CQuery*)q;
delete cq;
}
void CDatabase::destroyAllQueries(void)
{
for(size_t i=0;i<queries.size();++i)
{
CQuery *cq=(CQuery*)queries[i];
delete cq;
}
queries.clear();
}
_i64 CDatabase::getLastInsertID(void)
{
return sqlite3_last_insert_rowid(db);
}
bool CDatabase::WaitForUnlock(void)
{
int rc;
UnlockNotification un;
un.fired = false;
un.mutex=Server->createMutex();
un.cond=Server->createCondition();
rc = sqlite3_unlock_notify(db, unlock_notify_cb, (void *)&un);
if( rc==SQLITE_OK )
{
IScopedLock lock(un.mutex);
if( !un.fired )
{
un.cond->wait(&lock);
}
}
Server->destroy(un.mutex);
Server->destroy(un.cond);
return rc==SQLITE_OK;
}
sqlite3 *CDatabase::getDatabase(void)
{
return db;
}
bool CDatabase::LockForTransaction(void)
{
return lock_mutex->TryLock();
}
void CDatabase::UnlockForTransaction(void)
{
lock_mutex->Unlock();
}

53
Database.h Normal file
View File

@ -0,0 +1,53 @@
#include <string>
#include <vector>
#include <map>
#include "Interface/Database.h"
#include "Interface/Types.h"
#include "Interface/Mutex.h"
#include "Interface/Condition.h"
struct sqlite3;
class CQuery;
class CDatabase : public IDatabase
{
public:
bool Open(std::string pFile);
~CDatabase();
virtual db_nresults ReadN(std::string pQuery);
virtual db_results Read(std::string pQuery);
virtual bool Write(std::string pQuery);
virtual void BeginTransaction(void);
virtual bool EndTransaction(void);
virtual IQuery* Prepare(std::string pQuery, bool autodestroy=true);
virtual IQuery* Prepare(int id, std::string pQuery);
virtual void destroyQuery(IQuery *q);
virtual void destroyAllQueries(void);
virtual _i64 getLastInsertID(void);
sqlite3 *getDatabase(void);
//private function
void InsertResults(const db_nsingle_result &pResult);
bool WaitForUnlock(void);
bool LockForTransaction(void);
void UnlockForTransaction(void);
static void initMutex(void);
static void destroyMutex(void);
private:
db_nresults results;
sqlite3 *db;
std::vector<CQuery*> queries;
std::map<int, IQuery*> prepared_queries;
static IMutex* lock_mutex;
};

145
FileSettingsReader.cpp Normal file
View File

@ -0,0 +1,145 @@
/*************************************************************************
* UrBackup - Client/Server backup system
* Copyright (C) 2011 Martin Raiber
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
**************************************************************************/
#include "FileSettingsReader.h"
#include "stringtools.h"
#include "Server.h"
#include <iostream>
std::map<std::string, SCachedSettings*>* CFileSettingsReader::settings=new std::map<std::string, SCachedSettings*>;
IMutex* CFileSettingsReader::settings_mutex=NULL;
CFileSettingsReader::CFileSettingsReader(std::string pFile)
{
std::map<std::string, SCachedSettings*>::iterator iter;
{
IScopedLock lock(settings_mutex);
iter=settings->find(pFile);
}
if( iter==settings->end() )
{
std::string fdata=getFile(pFile);
std::vector<SSetting> mSettings;
int num_lines=linecount(fdata);
for(int i=0;i<num_lines;++i)
{
std::string line=getline(i,fdata);
if(line.size()<2 || line[0]=='#' )
continue;
SSetting setting;
setting.key=getuntil("=",line);
if(setting.key=="")
setting.value=line;
else
{
line.erase(0,setting.key.size()+1);
setting.value=line;
}
mSettings.push_back(setting);
}
cached_settings=new SCachedSettings;
cached_settings->smutex=Server->createMutex();
for(size_t i=0;i<mSettings.size();++i)
{
cached_settings->mSettingsMap[Server->ConvertToUnicode(mSettings[i].key)]=Server->ConvertToUnicode(mSettings[i].value);
}
cached_settings->refcount=1;
cached_settings->key=pFile;
IScopedLock lock(settings_mutex);
settings->insert(std::pair<std::string, SCachedSettings*>(pFile, cached_settings) );
}
else
{
IScopedLock lock(settings_mutex);
cached_settings=iter->second;
++cached_settings->refcount;
}
}
CFileSettingsReader::~CFileSettingsReader()
{
IScopedLock lock(settings_mutex);
--cached_settings->refcount;
if(cached_settings->refcount<=0)
{
std::map<std::string, SCachedSettings*>::iterator it=settings->find(cached_settings->key);
if(it!=settings->end())
{
settings->erase(it);
}
Server->destroy(cached_settings->smutex);
delete cached_settings;
}
}
bool CFileSettingsReader::getValue(std::string key, std::string *value)
{
std::wstring s_value;
bool b=getValue( widen(key), &s_value);
if(b==true)
{
std::string nvalue=wnarrow(s_value);
*value=nvalue;
return true;
}
return false;
}
bool CFileSettingsReader::getValue(std::wstring key, std::wstring *value)
{
IScopedLock lock(cached_settings->smutex);
std::map<std::wstring,std::wstring>::iterator i=cached_settings->mSettingsMap.find(key);
if( i!= cached_settings->mSettingsMap.end() )
{
*value=i->second;
return true;
}
return false;
}
void CFileSettingsReader::cleanup()
{
{
IScopedLock lock(settings_mutex);
for(std::map<std::string, SCachedSettings*>::iterator iter=settings->begin();iter!=settings->end();++iter)
{
Server->destroy(iter->second->smutex);
delete iter->second;
}
}
Server->destroy(settings_mutex);
delete settings;
}
void CFileSettingsReader::setup()
{
settings_mutex=Server->createMutex();
}

39
FileSettingsReader.h Normal file
View File

@ -0,0 +1,39 @@
#include <vector>
#include <map>
#include "Interface/Mutex.h"
#include "SettingsReader.h"
struct SSetting
{
std::string key;
std::string value;
};
struct SCachedSettings
{
std::map<std::wstring,std::wstring> mSettingsMap;
IMutex *smutex;
int refcount;
std::string key;
};
class CFileSettingsReader : public CSettingsReader
{
public:
CFileSettingsReader(std::string pFile);
~CFileSettingsReader();
virtual bool getValue(std::string key, std::string *value);
virtual bool getValue(std::wstring key, std::wstring *value);
static void cleanup();
static void setup();
private:
static std::map<std::string, SCachedSettings*> *settings;
static IMutex *settings_mutex;
SCachedSettings *cached_settings;
};

29
Helper_win32.h Normal file
View File

@ -0,0 +1,29 @@
__int64 unix_timestamp(SYSTEMTIME *sysTime)
{
SYSTEMTIME unixTime;
FILETIME unixTime2;
FILETIME sysTime2;
__int64 unixTime3;
__int64 sysTime3;
// Unix-Timestamp starts January 1 1970 00:00:00
unixTime.wDay=1;
unixTime.wDayOfWeek=4;
unixTime.wHour=0;
unixTime.wMilliseconds=0;
unixTime.wMinute=0;
unixTime.wMonth=1;
unixTime.wSecond=0;
unixTime.wYear=1970;
SystemTimeToFileTime(&unixTime,&unixTime2);
SystemTimeToFileTime(sysTime,&sysTime2);
unixTime3=((ULARGE_INTEGER*)&unixTime2)->QuadPart;
sysTime3=((ULARGE_INTEGER*)&sysTime2)->QuadPart;
unixTime3=unixTime3/10000000;
sysTime3=sysTime3/10000000;
return (sysTime3-unixTime3);
}

234
INSTALL Normal file
View File

@ -0,0 +1,234 @@
Installation Instructions
*************************
Copyright (C) 1994, 1995, 1996, 1999, 2000, 2001, 2002, 2004, 2005,
2006 Free Software Foundation, Inc.
This file is free documentation; the Free Software Foundation gives
unlimited permission to copy, distribute and modify it.
Basic Installation
==================
Briefly, the shell commands `./configure; make; make install' should
configure, build, and install this package. The following
more-detailed instructions are generic; see the `README' file for
instructions specific to this package.
The `configure' shell script attempts to guess correct values for
various system-dependent variables used during compilation. It uses
those values to create a `Makefile' in each directory of the package.
It may also create one or more `.h' files containing system-dependent
definitions. Finally, it creates a shell script `config.status' that
you can run in the future to recreate the current configuration, and a
file `config.log' containing compiler output (useful mainly for
debugging `configure').
It can also use an optional file (typically called `config.cache'
and enabled with `--cache-file=config.cache' or simply `-C') that saves
the results of its tests to speed up reconfiguring. Caching is
disabled by default to prevent problems with accidental use of stale
cache files.
If you need to do unusual things to compile the package, please try
to figure out how `configure' could check whether to do them, and mail
diffs or instructions to the address given in the `README' so they can
be considered for the next release. If you are using the cache, and at
some point `config.cache' contains results you don't want to keep, you
may remove or edit it.
The file `configure.ac' (or `configure.in') is used to create
`configure' by a program called `autoconf'. You need `configure.ac' if
you want to change it or regenerate `configure' using a newer version
of `autoconf'.
The simplest way to compile this package is:
1. `cd' to the directory containing the package's source code and type
`./configure' to configure the package for your system.
Running `configure' might take a while. While running, it prints
some messages telling which features it is checking for.
2. Type `make' to compile the package.
3. Optionally, type `make check' to run any self-tests that come with
the package.
4. Type `make install' to install the programs and any data files and
documentation.
5. You can remove the program binaries and object files from the
source code directory by typing `make clean'. To also remove the
files that `configure' created (so you can compile the package for
a different kind of computer), type `make distclean'. There is
also a `make maintainer-clean' target, but that is intended mainly
for the package's developers. If you use it, you may have to get
all sorts of other programs in order to regenerate files that came
with the distribution.
Compilers and Options
=====================
Some systems require unusual options for compilation or linking that the
`configure' script does not know about. Run `./configure --help' for
details on some of the pertinent environment variables.
You can give `configure' initial values for configuration parameters
by setting variables in the command line or in the environment. Here
is an example:
./configure CC=c99 CFLAGS=-g LIBS=-lposix
*Note Defining Variables::, for more details.
Compiling For Multiple Architectures
====================================
You can compile the package for more than one kind of computer at the
same time, by placing the object files for each architecture in their
own directory. To do this, you can use GNU `make'. `cd' to the
directory where you want the object files and executables to go and run
the `configure' script. `configure' automatically checks for the
source code in the directory that `configure' is in and in `..'.
With a non-GNU `make', it is safer to compile the package for one
architecture at a time in the source code directory. After you have
installed the package for one architecture, use `make distclean' before
reconfiguring for another architecture.
Installation Names
==================
By default, `make install' installs the package's commands under
`/usr/local/bin', include files under `/usr/local/include', etc. You
can specify an installation prefix other than `/usr/local' by giving
`configure' the option `--prefix=PREFIX'.
You can specify separate installation prefixes for
architecture-specific files and architecture-independent files. If you
pass the option `--exec-prefix=PREFIX' to `configure', the package uses
PREFIX as the prefix for installing programs and libraries.
Documentation and other data files still use the regular prefix.
In addition, if you use an unusual directory layout you can give
options like `--bindir=DIR' to specify different values for particular
kinds of files. Run `configure --help' for a list of the directories
you can set and what kinds of files go in them.
If the package supports it, you can cause programs to be installed
with an extra prefix or suffix on their names by giving `configure' the
option `--program-prefix=PREFIX' or `--program-suffix=SUFFIX'.
Optional Features
=================
Some packages pay attention to `--enable-FEATURE' options to
`configure', where FEATURE indicates an optional part of the package.
They may also pay attention to `--with-PACKAGE' options, where PACKAGE
is something like `gnu-as' or `x' (for the X Window System). The
`README' should mention any `--enable-' and `--with-' options that the
package recognizes.
For packages that use the X Window System, `configure' can usually
find the X include and library files automatically, but if it doesn't,
you can use the `configure' options `--x-includes=DIR' and
`--x-libraries=DIR' to specify their locations.
Specifying the System Type
==========================
There may be some features `configure' cannot figure out automatically,
but needs to determine by the type of machine the package will run on.
Usually, assuming the package is built to be run on the _same_
architectures, `configure' can figure that out, but if it prints a
message saying it cannot guess the machine type, give it the
`--build=TYPE' option. TYPE can either be a short name for the system
type, such as `sun4', or a canonical name which has the form:
CPU-COMPANY-SYSTEM
where SYSTEM can have one of these forms:
OS KERNEL-OS
See the file `config.sub' for the possible values of each field. If
`config.sub' isn't included in this package, then this package doesn't
need to know the machine type.
If you are _building_ compiler tools for cross-compiling, you should
use the option `--target=TYPE' to select the type of system they will
produce code for.
If you want to _use_ a cross compiler, that generates code for a
platform different from the build platform, you should specify the
"host" platform (i.e., that on which the generated programs will
eventually be run) with `--host=TYPE'.
Sharing Defaults
================
If you want to set default values for `configure' scripts to share, you
can create a site shell script called `config.site' that gives default
values for variables like `CC', `cache_file', and `prefix'.
`configure' looks for `PREFIX/share/config.site' if it exists, then
`PREFIX/etc/config.site' if it exists. Or, you can set the
`CONFIG_SITE' environment variable to the location of the site script.
A warning: not all `configure' scripts look for a site script.
Defining Variables
==================
Variables not defined in a site shell script can be set in the
environment passed to `configure'. However, some packages may run
configure again during the build, and the customized values of these
variables may be lost. In order to avoid this problem, you should set
them in the `configure' command line, using `VAR=value'. For example:
./configure CC=/usr/local2/bin/gcc
causes the specified `gcc' to be used as the C compiler (unless it is
overridden in the site shell script).
Unfortunately, this technique does not work for `CONFIG_SHELL' due to
an Autoconf bug. Until the bug is fixed you can use this workaround:
CONFIG_SHELL=/bin/bash /bin/bash ./configure CONFIG_SHELL=/bin/bash
`configure' Invocation
======================
`configure' recognizes the following options to control how it operates.
`--help'
`-h'
Print a summary of the options to `configure', and exit.
`--version'
`-V'
Print the version of Autoconf used to generate the `configure'
script, and exit.
`--cache-file=FILE'
Enable the cache: use and save the results of the tests in FILE,
traditionally `config.cache'. FILE defaults to `/dev/null' to
disable caching.
`--config-cache'
`-C'
Alias for `--cache-file=config.cache'.
`--quiet'
`--silent'
`-q'
Do not print messages saying which checks are being made. To
suppress all normal output, redirect it to `/dev/null' (any error
messages will still be shown).
`--srcdir=DIR'
Look for the package's source code in directory DIR. Usually
`configure' can determine that directory automatically.
`configure' also accepts some other, not widely useful, options. Run
`configure --help' for more details.

22
Interface/Action.h Normal file
View File

@ -0,0 +1,22 @@
#ifndef IACTION_H
#define IACTION_H
#include <map>
#include <string>
#include "Types.h"
#include "Object.h"
#define ACTION(x) class x : public IAction\
{public: virtual void Execute(str_map &GET, str_map &POST, THREAD_ID tid, str_nmap &PARAMS); virtual std::wstring getName(void);};
#define ACTION_IMPL(x) std::wstring Actions::x::getName(void){ return L ## #x; }\
void Actions::x::Execute(str_map &GET, str_map &POST, THREAD_ID tid, str_nmap &PARAMS)
class IAction : public IObject
{
public:
virtual void Execute(str_map &GET, str_map &POST, THREAD_ID tid, str_nmap &PARAMS)=0;
virtual std::wstring getName(void)=0;
};
#endif //IACTION_H

16
Interface/Condition.h Normal file
View File

@ -0,0 +1,16 @@
#ifndef ICONDITION_H
#define ICONDITION_H
#include "Mutex.h"
#include "Object.h"
class ICondition : public IObject
{
public:
virtual void wait(IScopedLock *lock, int timems=-1)=0;
virtual void notify_one(void)=0;
virtual void notify_all(void)=0;
};
#endif //ICONDITION_H

18
Interface/CustomClient.h Normal file
View File

@ -0,0 +1,18 @@
#ifndef INTERFACE_CUSTOMCLIENT_H
#define INTERFACE_CUSTOMCLIENT_H
#include "Object.h"
#include "Types.h"
class IPipe;
class ICustomClient : public IObject
{
public:
virtual void Init(THREAD_ID pTID, IPipe *pPipe)=0;
virtual bool Run(void)=0;
virtual void ReceivePackets(void)=0;
};
#endif

27
Interface/Database.h Normal file
View File

@ -0,0 +1,27 @@
#ifndef INTERFACE_DATABASE_H
#define INTERFACE_DATABASE_H
#include <vector>
#include <string>
#include <map>
#include "Query.h"
class IDatabase
{
public:
virtual db_nresults ReadN(std::string pQuery)=0;
virtual db_results Read(std::string pQuery)=0;
virtual bool Write(std::string pQuery)=0;
virtual void BeginTransaction(void)=0;
virtual bool EndTransaction(void)=0;
virtual IQuery* Prepare(std::string pQuery, bool autodestroy=true)=0;
virtual void destroyQuery(IQuery *q)=0;
virtual void destroyAllQueries(void)=0;
virtual _i64 getLastInsertID(void)=0;
};
#endif

28
Interface/File.h Normal file
View File

@ -0,0 +1,28 @@
#ifndef IFILE_H
#define IFILE_H
#include <string>
#include "Types.h"
#include "Object.h"
const int MODE_READ=0;
const int MODE_WRITE=1;
const int MODE_APPEND=2;
const int MODE_RW=3;
class IFile : public IObject
{
public:
virtual std::string Read(_u32 tr)=0;
virtual _u32 Read(char* buffer, _u32 bsize)=0;
virtual _u32 Write(const std::string &tw)=0;
virtual _u32 Write(const char* buffer, _u32 bsize)=0;
virtual bool Seek(_i64 spos)=0;
virtual _i64 Size(void)=0;
virtual std::string getFilename(void)=0;
virtual std::wstring getFilenameW(void)=0;
};
#endif //IFILE_H

32
Interface/Mutex.h Normal file
View File

@ -0,0 +1,32 @@
#ifndef IMUTEX_H
#define IMUTEX_H
#include "Object.h"
#include "Types.h"
class ILock : public IObject
{
};
class IMutex : public IObject
{
public:
virtual void Lock(void)=0;
virtual ILock * Lock2(void)=0;
virtual void Unlock(void)=0;
virtual bool TryLock(void)=0;
};
class IScopedLock
{
public:
IScopedLock(IMutex *pMutex){ if(pMutex!=NULL)lock=pMutex->Lock2();else lock=NULL; }
~IScopedLock(){ if(lock!=NULL) lock->Remove(); }
void relock(IMutex *pMutex){ if(lock!=NULL) lock->Remove(); if(pMutex!=NULL)lock=pMutex->Lock2();else lock=NULL; }
ILock * getLock(){ return lock; }
private:
ILock *lock;
};
#endif //IMUTEX_H

17
Interface/Object.h Normal file
View File

@ -0,0 +1,17 @@
#ifndef IOBJECT_H
#define IOBJECT_H
class IObject
{
public:
virtual ~IObject(void)
{
}
virtual void Remove(void)
{
delete this;
}
};
#endif //IOBJECT_H

13
Interface/OutputStream.h Normal file
View File

@ -0,0 +1,13 @@
#include <string>
enum ostream_type_t
{ STDOUT
, STDERR
};
class IOutputStream
{
public:
virtual void write(const std::string &tw)=0;
virtual void write(const char* buf, size_t count, ostream_type_t stream = STDOUT)=0;
};

35
Interface/Pipe.h Normal file
View File

@ -0,0 +1,35 @@
#ifndef IPIPE_H
#define IPIPE_H
#include <string>
#include "Object.h"
class IPipe : public IObject
{
public:
/**
* @param timeoutms -1 for blocking >=0 to block only for x ms. Default: blocking
*/
virtual size_t Read(char *buffer, size_t bsize, int timeoutms=-1)=0;
virtual bool Write(const char *buffer, size_t bsize, int timeoutms=-1)=0;
virtual size_t Read(std::string *ret, int timeoutms=-1)=0;
virtual bool Write(const std::string &str, int timeoutms=-1)=0;
/**
* @param timeoutms -1 for blocking >=0 to block only for x ms. Default: nonblocking
*/
virtual bool isWritable(int timeoutms=0)=0;
virtual bool isReadable(int timeoutms=0)=0;
virtual bool hasError(void)=0;
virtual void shutdown(void)=0;
/**
* only works with memory pipe
**/
virtual size_t getNumElements(void)=0;
};
#endif //IPIPE_H

22
Interface/Plugin.h Normal file
View File

@ -0,0 +1,22 @@
#ifndef INTERFACE_PLUGIN_H
#define INTERFACE_PLUGIN_H
#include "Object.h"
#include "Types.h"
class IPlugin : public IObject
{
public:
/**
* Gets called if Server->ReloadPlugin() is executed
**/
virtual bool Reload(void){ return true; }
/**
* Only for PerThread Plugins. Gets called before the Plugin Instance is returned.
**/
virtual void Reset(void){}
};
#endif //INTERFACE_PLUGIN_H

10
Interface/PluginMgr.h Normal file
View File

@ -0,0 +1,10 @@
#include "Types.h"
#include "Plugin.h"
#include "Object.h"
class IPluginMgr : public IObject
{
public:
virtual IPlugin *createPluginInstance(str_map &params)=0;
virtual void destroyPluginInstance(IPlugin *plugin)=0;
};

29
Interface/Query.h Normal file
View File

@ -0,0 +1,29 @@
#ifndef QUERY_H
#define QUERY_H
#include "Types.h"
class IQuery
{
public:
virtual void Bind(const std::string &str)=0;
virtual void Bind(const std::wstring &str)=0;
virtual void Bind(unsigned int p)=0;
virtual void Bind(int p)=0;
virtual void Bind(double p)=0;
virtual void Bind(int64 p)=0;
#ifdef _WIN64
virtual void Bind(size_t p)=0;
#endif
virtual void Bind(const char* buffer, _u32 bsize)=0;
virtual void Reset(void)=0;
virtual bool Write(void)=0;
virtual db_nresults ReadN(void)=0;
virtual db_results Read(void)=0;
};
#endif

140
Interface/Server.h Normal file
View File

@ -0,0 +1,140 @@
#ifndef INTERFACE_SERVER_H
#define INTERFACE_SERVER_H
#include <string>
#include "Types.h"
#define LL_DEBUG -1
#define LL_INFO 0
#define LL_WARNING 1
#define LL_ERROR 2
class IAction;
class ITemplate;
class IObject;
class IDatabase;
class ISessionMgr;
class IService;
class IPluginMgr;
class IPlugin;
class IMutex;
class IThread;
class ISettingsReader;
class IPipe;
class IFile;
class IOutputStream;
class IThreadPool;
class ICondition;
class IScopedLock;
struct SPostfile
{
SPostfile(IFile *f, std::wstring n, std::wstring ct){ file=f; name=n; contenttype=ct; }
SPostfile(){ file=NULL; }
IFile *file;
std::wstring name;
std::wstring contenttype;
};
class IServer
{
public:
virtual void setLogLevel(int LogLevel)=0;
virtual void setLogFile(const std::string &plf)=0;
virtual void Log(const std::string &pStr, int LogLevel=LL_INFO)=0;
virtual void Log(const std::wstring &pStr, int LogLevel=LL_INFO)=0;
virtual void Write(THREAD_ID tid, const std::string &str, bool cached=true)=0;
virtual void WriteRaw(THREAD_ID tid, const char *buf, size_t bsize, bool cached=true)=0;
virtual std::string getServerParameter(const std::string &key)=0;
virtual std::string getServerParameter(const std::string &key, const std::string &def)=0;
virtual void setServerParameter(const std::string &key, const std::string &value)=0;
virtual void setContentType(THREAD_ID tid, const std::string &str)=0;
virtual void addHeader(THREAD_ID tid, const std::string &str)=0;
virtual THREAD_ID Execute(const std::wstring &action, const std::wstring &context, str_map &GET, str_map &POST, str_nmap &PARAMS, IOutputStream *req)=0;
virtual std::string Execute(const std::wstring &action, const std::wstring &context, str_map &GET, str_map &POST, str_nmap &PARAMS)=0;
virtual void AddAction(IAction *action)=0;
virtual bool RemoveAction(IAction *action)=0;
virtual void setActionContext(std::wstring context)=0;
virtual void resetActionContext(void)=0;
virtual unsigned int getTimeSeconds(void)=0;
virtual unsigned int getTimeMS(void)=0;
virtual bool LoadDLL(const std::string &name)=0;
virtual bool UnloadDLL(const std::string &name)=0;
virtual void destroy(IObject *obj)=0;
virtual void wait(unsigned int ms)=0;
virtual ITemplate* createTemplate(std::string pFile)=0;
virtual IMutex* createMutex(void)=0;
virtual ICondition* createCondition(void)=0;
virtual void createThread(IThread *thread)=0;
virtual IPipe *createMemoryPipe(void)=0;
virtual IThreadPool *getThreadPool(void)=0;
virtual ISettingsReader* createFileSettingsReader(std::string pFile)=0;
virtual ISettingsReader* createDBSettingsReader(THREAD_ID tid, DATABASE_ID pIdentifier, const std::string &pTable, const std::string &pSQL="")=0;
virtual ISettingsReader* createDBSettingsReader(IDatabase *db, const std::string &pTable, const std::string &pSQL="")=0;
virtual ISettingsReader* createMemorySettingsReader(const std::string &pData)=0;
virtual bool openDatabase(std::string pFile, DATABASE_ID pIdentifier)=0;
virtual IDatabase* getDatabase(THREAD_ID tid, DATABASE_ID pIdentifier)=0;
virtual void destroyAllDatabases(void)=0;
virtual ISessionMgr *getSessionMgr(void)=0;
virtual IPlugin* getPlugin(THREAD_ID tid, PLUGIN_ID pIdentifier)=0;
virtual THREAD_ID getThreadID(void)=0;
virtual std::string ConvertToUTF8(const std::wstring &input)=0;
virtual std::wstring ConvertToUnicode(const std::string &input)=0;
virtual std::string ConvertToUTF16(const std::wstring &input)=0;
virtual std::string ConvertToUTF32(const std::wstring &input)=0;
virtual std::wstring ConvertFromUTF16(const std::string &input)=0;
virtual std::wstring ConvertFromUTF32(const std::string &input)=0;
virtual std::string GenerateHexMD5(const std::wstring &input)=0;
virtual std::string GenerateBinaryMD5(const std::wstring &input)=0;
virtual std::string GenerateHexMD5(const std::string &input)=0;
virtual std::string GenerateBinaryMD5(const std::string &input)=0;
virtual void StartCustomStreamService(IService *pService, std::string pServiceName, unsigned short pPort)=0;
virtual IPipe* ConnectStream(std::string pServer, unsigned short pPort, unsigned int pTimeoutms=0)=0;
virtual void DisconnectStream(IPipe *pipe)=0;
virtual bool RegisterPluginPerThreadModel(IPluginMgr *pPluginMgr, std::string pName)=0;
virtual bool RegisterPluginThreadsafeModel(IPluginMgr *pPluginMgr, std::string pName)=0;
virtual PLUGIN_ID StartPlugin(std::string pName, str_map &params)=0;
virtual bool RestartPlugin(PLUGIN_ID pIdentifier)=0;
virtual unsigned int getNumRequests(void)=0;
virtual void addRequest(void)=0;
virtual IFile* openFile(std::string pFilename, int pMode=0)=0;
virtual IFile* openFile(std::wstring pFilename, int pMode=0)=0;
virtual IFile* openTemporaryFile(void)=0;
virtual IFile* openMemoryFile(void)=0;
virtual bool deleteFile(std::string pFilename)=0;
virtual bool deleteFile(std::wstring pFilename)=0;
virtual POSTFILE_KEY getPostFileKey()=0;
virtual void addPostFile(POSTFILE_KEY pfkey, const std::string &name, const SPostfile &pf)=0;
virtual SPostfile getPostFile(POSTFILE_KEY pfkey, const std::string &name)=0;
virtual void clearPostFiles(POSTFILE_KEY pfkey)=0;
virtual std::wstring getServerWorkingDir(void)=0;
};
#ifndef NO_INTERFACE
#ifndef DEF_SERVER
extern IServer* Server;
#endif
#endif
#endif //INTERFACE_SERVER_H

8
Interface/Service.h Normal file
View File

@ -0,0 +1,8 @@
#include "CustomClient.h"
class IService
{
public:
virtual ICustomClient* createClient()=0;
virtual void destroyClient( ICustomClient * pClient)=0;
};

14
Interface/SessionMgr.h Normal file
View File

@ -0,0 +1,14 @@
#include <string>
#include "User.h"
class ISessionMgr
{
public:
virtual std::wstring GenerateSessionIDWithUser(const std::wstring &pUsername, const std::wstring &pIdentData, bool update_user=false)=0;
virtual SUser *getUser(const std::wstring &pSID, const std::wstring &pIdentData, bool update=true)=0;
virtual void releaseUser(SUser *user)=0;
virtual bool RemoveSession(const std::wstring &pSID)=0;
};

View File

@ -0,0 +1,24 @@
#ifndef INTERFACE_SETTINGSREADER_H
#define INTERFACE_SETTINGSREADER_H
#include <string>
#include "Object.h"
class ISettingsReader : public IObject
{
public:
virtual bool getValue(std::string key, std::string *value)=0;
virtual bool getValue(std::wstring key, std::wstring *value)=0;
virtual std::string getValue(std::string key,std::string def)=0;
virtual std::string getValue(std::string key)=0;
virtual int getValue(std::string key, int def)=0;
virtual float getValue(std::string key, float def)=0;
virtual std::wstring getValue(std::wstring key,std::wstring def)=0;
virtual std::wstring getValue(std::wstring key)=0;
virtual int getValue(std::wstring key, int def)=0;
virtual float getValue(std::wstring key, float def)=0;
};
#endif //INTERFACE_SETTINGSREADER_H

18
Interface/Table.h Normal file
View File

@ -0,0 +1,18 @@
#ifndef ITABLE_H
#define ITABLE_H
#include <string>
#include "Object.h"
class ITable : public IObject
{
public:
virtual void addObject(std::wstring key, ITable *tab)=0;
virtual ITable* getObject(size_t n)=0;
virtual ITable* getObject(std::wstring key)=0;
virtual std::wstring getValue()=0;
virtual size_t getSize()=0;
virtual void addString(std::wstring key, std::wstring str)=0;
};
#endif //ITABLE_H

16
Interface/Template.h Normal file
View File

@ -0,0 +1,16 @@
#include "Object.h"
class IDatabase;
class ITable;
class ITemplate : public IObject
{
public:
virtual void Reset(void)=0;
virtual void setValue(std::wstring key, std::wstring value)=0;
virtual ITable* getTable(std::wstring key)=0;
virtual std::string getData(void)=0;
virtual void addValueTable( IDatabase* db, const std::string &table)=0;
};

10
Interface/Thread.h Normal file
View File

@ -0,0 +1,10 @@
#ifndef INTERFACE_THREAD_H
#define INTERFACE_THREAD_H
class IThread
{
public:
virtual void operator()(void)=0;
};
#endif //INTERFACE_THREAD_H

17
Interface/ThreadPool.h Normal file
View File

@ -0,0 +1,17 @@
#ifndef ITHREADPOOL_H_
#define ITHREADPOOL_H_
#include "Types.h"
class IThread;
class IThreadPool
{
public:
virtual THREADPOOL_TICKET execute(IThread *runnable)=0;
virtual bool isRunning(THREADPOOL_TICKET ticket)=0;
virtual void waitFor(std::vector<THREADPOOL_TICKET> tickets)=0;
virtual void waitFor(THREADPOOL_TICKET ticket)=0;
};
#endif //ITHREADPOOL_H_

78
Interface/Types.h Normal file
View File

@ -0,0 +1,78 @@
#ifndef TYPES_H
#define TYPES_H
#include <string>
#include <map>
#include <vector>
typedef int THREAD_ID;
typedef int DATABASE_ID;
typedef int PLUGIN_ID;
typedef unsigned int THREADPOOL_TICKET;
typedef int POSTFILE_KEY;
#ifdef LINUX
typedef long long int __int64;
typedef unsigned long long int uint64;
#endif
#ifndef NULL
#define NULL 0
#endif
typedef __int64 int64;
#ifndef LINUX
typedef unsigned __int64 uint64;
#endif
typedef unsigned char uchar;
typedef int _i32;
typedef __int64 _i64;
typedef unsigned int _u32;
typedef unsigned short _u16;
typedef short _i16;
const THREAD_ID ILLEGAL_THREAD_ID=-1;
const PLUGIN_ID ILLEGAL_PLUGIN_ID=-1;
const THREADPOOL_TICKET ILLEGAL_THREADPOOL_TICKET=0;
typedef std::map<std::wstring,std::wstring> str_map;
typedef std::map<std::wstring,float> float_map;
typedef std::map<std::wstring,int> int_map;
typedef std::map<std::string,std::string> str_nmap;
typedef std::map<std::string,float> float_nmap;
typedef std::map<std::string,int> int_nmap;
typedef std::map<std::string, std::string> db_nsingle_result;
typedef std::vector< db_nsingle_result > db_nresults;
typedef std::map<std::wstring, std::wstring> db_single_result;
typedef std::vector< db_single_result > db_results;
#ifdef _WIN32
#if _MSC_VER<1600
const class
{
public:
template<class T> operator T*() const {return 0;}
template<class C, class T> operator T C::*() const {return 0;}
private:
void operator&() const;
}
nullptr = {};
#endif
#else
const class
{
public:
template<class T> operator T*() const {return 0;}
template<class C, class T> operator T C::*() const {return 0;}
private:
void operator&() const;
}
nullptr = {};
#endif
#endif

38
Interface/User.h Normal file
View File

@ -0,0 +1,38 @@
#ifndef IUSER_H
#define IUSER_H
#include <map>
#include <string>
#include "Object.h"
#include "Types.h"
struct SUser
{
std::wstring username;
std::wstring session;
std::wstring ident_data;
int id;
str_map mStr;
int_map mInt;
float_map mFloat;
std::map<std::string, IObject* > mCustom;
unsigned int lastused;
void* getCustomPtr(std::string str)
{
std::map<std::string, IObject* >::iterator iter=mCustom.find(str);
if( iter!=mCustom.end() )
{
return iter->second;
}
else
return NULL;
}
//private
void *mutex;
void *lock;
};
#endif //IUSER_H

117
LoadbalancerClient.cpp Normal file
View File

@ -0,0 +1,117 @@
/*************************************************************************
* UrBackup - Client/Server backup system
* Copyright (C) 2011 Martin Raiber
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
**************************************************************************/
#include "LoadbalancerClient.h"
#include "Server.h"
#include "socket_header.h"
#include <memory.h>
in_addr getIP(std::string ip)
{
const char* host=ip.c_str();
in_addr dest;
unsigned int addr = inet_addr(host);
if (addr != INADDR_NONE)
{
dest.s_addr = addr;
return dest;
}
else
{
hostent* hp = gethostbyname(host);
if (hp != 0)
{
memcpy(&(dest), hp->h_addr, hp->h_length);
}
else
{
memset(&dest,0,sizeof(in_addr) );
return dest;
}
}
return dest;
}
CLoadbalancerClient::CLoadbalancerClient(std::string pLB, unsigned short pLBPort, int pWeight, unsigned short pServerport)
{
lb=pLB;
lbport=pLBPort;
weight=pWeight;
serverport=pServerport;
}
void CLoadbalancerClient::operator ()(void)
{
int rc;
#ifdef _WIN32
WSADATA wsadata;
rc = WSAStartup(MAKEWORD(2,0), &wsadata);
if(rc == SOCKET_ERROR) return;
#endif
SOCKET s=socket(AF_INET,SOCK_STREAM,0);
if(s<1)
{
Server->Log("Creating SOCKET failed (LB)",LL_ERROR);
return;
}
sockaddr_in addr;
memset(&addr, 0, sizeof(sockaddr_in));
addr.sin_family=AF_INET;
addr.sin_port=htons(lbport);
addr.sin_addr=getIP(lb);
int err=connect(s, (sockaddr*)&addr, sizeof( sockaddr_in ) );
if( err==-1 )
{
Server->Log("Could not connect to LoadBalancer", LL_ERROR );
return;
}
Server->Log("Connected successfully to LoadBalancer", LL_INFO);
char msg[1+sizeof(int)+sizeof(unsigned short)];
msg[0]=2;
memcpy( &msg[1], &weight, sizeof(int) );
memcpy( &msg[1+sizeof(int)], &serverport, sizeof(unsigned short));
send( s, msg, 1+sizeof(int)+sizeof(unsigned short), MSG_NOSIGNAL);
while(true)
{
char buffer[100];
int rc=recv(s, buffer, 100, 0);
if( rc>0 )
{
if( buffer[0]==32 )
{
Server->Log("PONG", LL_INFO);
send( s, buffer, rc, MSG_NOSIGNAL);
}
}
else
{
closesocket(s);
Sleep(50);
this->operator()();
}
}
}

15
LoadbalancerClient.h Normal file
View File

@ -0,0 +1,15 @@
#include <string>
#include "Interface/Thread.h"
class CLoadbalancerClient : public IThread
{
public:
CLoadbalancerClient(std::string pLB, unsigned short pLBPort, int pWeight, unsigned short pServerport);
void operator()(void);
private:
std::string lb;
unsigned short lbport;
int weight;
unsigned short serverport;
};

50
LookupService.cpp Normal file
View File

@ -0,0 +1,50 @@
/*************************************************************************
* UrBackup - Client/Server backup system
* Copyright (C) 2011 Martin Raiber
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
**************************************************************************/
#include "socket_header.h"
#include <string>
#ifndef _WIN32
#include <memory.h>
#endif
bool LookupBlocking(std::string pServer, in_addr *dest)
{
const char* host=pServer.c_str();
unsigned int addr = inet_addr(host);
if (addr != INADDR_NONE)
{
dest->s_addr = addr;
}
else
{
hostent* hp = gethostbyname(host);
if (hp != 0)
{
memcpy(dest, hp->h_addr, hp->h_length);
}
else
{
return false;
}
}
return true;
}

4
LookupService.h Normal file
View File

@ -0,0 +1,4 @@
#include "socket_header.h"
#include <string>
bool LookupBlocking(std::string pServer, in_addr *dest);

9
Makefile.am Normal file
View File

@ -0,0 +1,9 @@
ACLOCAL_AMFLAGS = -I m4
bin_PROGRAMS = cserver
cserver_SOURCES = AcceptThread.cpp Client.cpp Database.cpp Query.cpp SelectThread.cpp Server.cpp ServerLinux.cpp ServiceAcceptor.cpp ServiceWorker.cpp SessionMgr.cpp StreamPipe.cpp Template.cpp WorkerThread.cpp main.cpp md5.cpp stringtools.cpp libfastcgi/fastcgi.cpp Mutex_lin.cpp LoadbalancerClient.cpp DBSettingsReader.cpp file_common.cpp file_fstream.cpp file_linux.cpp FileSettingsReader.cpp LookupService.cpp SettingsReader.cpp Table.cpp OutputStream.cpp ThreadPool.cpp MemoryPipe.cpp Condition_lin.cpp MemorySettingsReader.cpp sqlite/sqlite3.c
cserver_LDADD =
AM_CXXFLAGS = $(PTHREAD_CFLAGS) -DLINUX
#-DTHREAD_BOOST $(BOOST_CPPFLAGS)
AM_CFLAGS = -DSQLITE_ENABLE_UNLOCK_NOTIFY
AM_LDFLAGS = $(PTHREAD_LIBS) -ldl
#$(BOOST_LDFLAGS) $(BOOST_THREAD_LIB)

186
MemoryPipe.cpp Normal file
View File

@ -0,0 +1,186 @@
/*************************************************************************
* UrBackup - Client/Server backup system
* Copyright (C) 2011 Martin Raiber
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
**************************************************************************/
#include "MemoryPipe.h"
#include "Server.h"
#ifndef _WIN32
#include <memory.h>
#endif
CMemoryPipe::CMemoryPipe(void)
{
mutex=Server->createMutex();
cond=Server->createCondition();
}
CMemoryPipe::~CMemoryPipe(void)
{
Server->destroy(mutex);
Server->destroy(cond);
}
size_t CMemoryPipe::Read(char *buffer, size_t bsize, int timeoutms)
{
IScopedLock lock(mutex);
if( timeoutms>0 )
{
if( queue.size()==0 )
{
cond->wait( &lock, timeoutms );
}
if( queue.size()==0 )
return 0;
}
else if( timeoutms==0 )
{
if( queue.size()==0 )
return 0;
}
else
{
while( queue.size()==0 )
{
cond->wait(&lock);
}
}
std::string *cstr=&queue[0];
size_t psize=cstr->size();
if( psize<=bsize )
{
memcpy( buffer, cstr->c_str(), psize );
queue.erase( queue.begin() );
return psize;
}
else
{
memcpy( buffer, cstr->c_str(), bsize );
cstr->erase(0, bsize );
return bsize;
}
}
bool CMemoryPipe::Write(const char *buffer, size_t bsize, int timeoutms)
{
IScopedLock lock(mutex);
queue.push_back("");
std::deque<std::string>::iterator iter=queue.end();
--iter;
std::string *nstr=&(*iter);
nstr->resize( bsize );
memcpy( (char*)nstr->c_str(), buffer, bsize );
cond->notify_one();
return true;
}
size_t CMemoryPipe::Read(std::string *str, int timeoutms )
{
IScopedLock lock(mutex);
if( timeoutms>0 )
{
if( queue.size()==0 )
{
cond->wait( &lock, timeoutms );
}
if( queue.size()==0 )
return 0;
}
else if( timeoutms==0 )
{
if( queue.size()==0 )
return 0;
}
else
{
while( queue.size()==0 )
{
cond->wait(&lock);
}
}
std::string *fs=&queue[0];
size_t fsize=fs->size();
str->resize( fsize );
memcpy( (char*) str->c_str(), fs->c_str(), fsize );
queue.erase( queue.begin() );
return fsize;
}
bool CMemoryPipe::Write(const std::string &str, int timeoutms)
{
IScopedLock lock(mutex);
queue.push_back( str );
cond->notify_one();
return true;
}
bool CMemoryPipe::isWritable(int timeoutms)
{
return true;
}
bool CMemoryPipe::isReadable(int timeoutms)
{
IScopedLock lock(mutex);
if( queue.size()>0 )
return true;
if(timeoutms>0)
cond->wait( &lock, timeoutms );
else if(timeoutms<0)
cond->wait(&lock);
if( queue.size()>0 )
return true;
else
return false;
}
bool CMemoryPipe::hasError(void)
{
return false;
}
size_t CMemoryPipe::getNumElements(void)
{
IScopedLock lock(mutex);
return queue.size();
}
void CMemoryPipe::shutdown(void)
{
}

37
MemoryPipe.h Normal file
View File

@ -0,0 +1,37 @@
#ifndef MEMPIPE_H_
#define MEMPIPE_H_
#include "Interface/Pipe.h"
#include <deque>
#include <string>
#include "Interface/Mutex.h"
#include "Interface/Condition.h"
class CMemoryPipe : public IPipe
{
public:
CMemoryPipe(void);
~CMemoryPipe(void);
virtual size_t Read(char *buffer, size_t bsize, int timeoutms);
virtual bool Write(const char *buffer, size_t bsize, int timeoutms);
virtual size_t Read(std::string *ret, int timeoutms);
virtual bool Write(const std::string &str, int timeoutms);
virtual bool isWritable(int timeoutms);
virtual bool isReadable(int timeoutms);
virtual bool hasError(void);
virtual void shutdown(void);
virtual size_t getNumElements(void);
private:
std::deque<std::string> queue;
IMutex *mutex;
ICondition *cond;
};
#endif /*MEMPIPE_H_*/

73
MemorySettingsReader.cpp Normal file
View File

@ -0,0 +1,73 @@
/*************************************************************************
* UrBackup - Client/Server backup system
* Copyright (C) 2011 Martin Raiber
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
**************************************************************************/
#include "MemorySettingsReader.h"
#include "Server.h"
#include "stringtools.h"
CMemorySettingsReader::CMemorySettingsReader(const std::string &pData)
{
int num_lines=linecount(pData);
for(int i=0;i<num_lines;++i)
{
std::string line=getline(i,pData);
if(line.size()<2 || line[0]=='#' )
continue;
std::string key=getuntil("=",line);
std::string value;
if(key=="")
value=line;
else
{
line.erase(0,key.size()+1);
value=line;
}
mSettingsMap.insert(std::pair<std::wstring,std::wstring>(Server->ConvertToUnicode(key), Server->ConvertToUnicode(value)) );
}
}
bool CMemorySettingsReader::getValue(std::string key, std::string *value)
{
std::wstring s_value;
bool b=getValue( widen(key), &s_value);
if(b==true)
{
std::string nvalue=wnarrow(s_value);
*value=nvalue;
return true;
}
return false;
}
bool CMemorySettingsReader::getValue(std::wstring key, std::wstring *value)
{
std::map<std::wstring,std::wstring>::iterator i=mSettingsMap.find(key);
if( i!=mSettingsMap.end() )
{
*value=i->second;
return true;
}
return false;
}

15
MemorySettingsReader.h Normal file
View File

@ -0,0 +1,15 @@
#include <vector>
#include <map>
#include "SettingsReader.h"
class CMemorySettingsReader : public CSettingsReader
{
public:
CMemorySettingsReader(const std::string &pData);
virtual bool getValue(std::string key, std::string *value);
virtual bool getValue(std::wstring key, std::wstring *value);
private:
std::map<std::wstring,std::wstring> mSettingsMap;
};

73
Mutex_boost.cpp Normal file
View File

@ -0,0 +1,73 @@
/*************************************************************************
* UrBackup - Client/Server backup system
* Copyright (C) 2011 Martin Raiber
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
**************************************************************************/
#include "Mutex_boost.h"
CMutex::CMutex(void)
{
lock=NULL;
}
CMutex::~CMutex(void)
{
}
void CMutex::Lock(void)
{
boost::recursive_mutex::scoped_lock *n_lock=new boost::recursive_mutex::scoped_lock(mutex);
lock=n_lock;
}
bool CMutex::TryLock(void)
{
boost::recursive_mutex::scoped_try_lock *n_lock=new boost::recursive_mutex::scoped_try_lock(mutex);
if(n_lock->owns_lock())
{
lock=(boost::recursive_mutex::scoped_lock*)n_lock;
return true;
}
else
{
return false;
}
}
ILock* CMutex::Lock2(void)
{
return new CLock(new boost::recursive_mutex::scoped_lock(mutex));
}
void CMutex::Unlock(void)
{
delete lock;
}
CLock::CLock(boost::recursive_mutex::scoped_lock *pLock)
{
lock=pLock;
}
CLock::~CLock()
{
delete lock;
}
boost::recursive_mutex::scoped_lock * CLock::getLock()
{
return lock;
}

29
Mutex_boost.h Normal file
View File

@ -0,0 +1,29 @@
#include "Interface/Mutex.h"
#include <boost/thread/recursive_mutex.hpp>
class CMutex : public IMutex
{
public:
CMutex(void);
~CMutex(void);
virtual void Lock(void);
virtual ILock * Lock2(void);
virtual void Unlock(void);
virtual bool TryLock(void);
private:
boost::recursive_mutex mutex;
boost::recursive_mutex::scoped_lock *lock;
};
class CLock : public ILock
{
public:
CLock(boost::recursive_mutex::scoped_lock *pLock);
~CLock();
boost::recursive_mutex::scoped_lock * getLock();
private:
boost::recursive_mutex::scoped_lock * lock;
};

98
Mutex_lin.cpp Normal file
View File

@ -0,0 +1,98 @@
/*************************************************************************
* UrBackup - Client/Server backup system
* Copyright (C) 2011 Martin Raiber
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
**************************************************************************/
#include "Mutex_lin.h"
#include "Server.h"
CMutex::CMutex(void)
{
pthread_mutexattr_t attr;
if(pthread_mutexattr_init(&attr)!=0)
{
Server->Log("Error initializing mutexattr", LL_ERROR);
}
if(pthread_mutexattr_settype (&attr, PTHREAD_MUTEX_RECURSIVE)!=0)
{
Server->Log("Error setting PTHREAD_MUTEX_RECURSIVE", LL_ERROR);
}
if(pthread_mutex_init(&ptmutex, &attr)!=0)
{
Server->Log("Error initializing mutex", LL_ERROR);
}
if(pthread_mutexattr_destroy(&attr)!=0)
{
Server->Log("Error destroing mutexattr", LL_ERROR);
}
}
CMutex::~CMutex(void)
{
if(pthread_mutex_destroy(&ptmutex)!=0)
{
Server->Log("Error destroying mutex", LL_ERROR);
}
}
void CMutex::Lock(void)
{
if(pthread_mutex_lock( &ptmutex )!=0)
{
Server->Log("Error locking mutex", LL_ERROR);
}
}
bool CMutex::TryLock(void)
{
return pthread_mutex_trylock( &ptmutex )==0;
}
ILock * CMutex::Lock2(void)
{
return new CLock(&ptmutex);
}
void CMutex::Unlock(void)
{
if(pthread_mutex_unlock( &ptmutex )!=0)
{
Server->Log("Error unlocking mutex", LL_ERROR);
}
}
CLock::CLock(pthread_mutex_t *ptmutex)
{
if(pthread_mutex_lock(ptmutex)!=0)
{
Server->Log("Error locking mutex -2", LL_ERROR);
}
lock=ptmutex;
}
CLock::~CLock()
{
if(pthread_mutex_unlock(lock)!=0)
{
Server->Log("Error unlocking mutex -2", LL_ERROR);
}
}
pthread_mutex_t * CLock::getLock()
{
return lock;
}

29
Mutex_lin.h Normal file
View File

@ -0,0 +1,29 @@
#include "Interface/Mutex.h"
#include <pthread.h>
class CMutex : public IMutex
{
public:
CMutex(void);
~CMutex(void);
virtual void Lock(void);
virtual ILock * Lock2(void);
virtual void Unlock(void);
virtual bool TryLock(void);
private:
pthread_mutex_t ptmutex;
};
class CLock : public ILock
{
public:
CLock(pthread_mutex_t *ptmutex);
~CLock();
pthread_mutex_t * getLock();
private:
pthread_mutex_t *lock;
};

3
NEWS Normal file
View File

@ -0,0 +1,3 @@
Please see
http://www.urbackup.org
for Changelog

40
OutputStream.cpp Normal file
View File

@ -0,0 +1,40 @@
/*************************************************************************
* UrBackup - Client/Server backup system
* Copyright (C) 2011 Martin Raiber
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
**************************************************************************/
#include "OutputStream.h"
#ifndef _WIN32
#include <memory.h>
#endif
void CStringOutputStream::write(const std::string &tw)
{
data+=tw;
}
std::string CStringOutputStream::getData(void)
{
return data;
}
void CStringOutputStream::write(const char* buf, size_t count, ostream_type_t stream)
{
size_t osize=data.size();
data.resize(osize+count);
memcpy(&data[osize], buf, count);
}

12
OutputStream.h Normal file
View File

@ -0,0 +1,12 @@
#include "Interface/OutputStream.h"
class CStringOutputStream : public IOutputStream
{
public:
virtual void write(const std::string &tw);
virtual void write(const char* buf, size_t count, ostream_type_t stream = STDOUT);
std::string getData(void);
private:
std::string data;
};

296
Query.cpp Normal file
View File

@ -0,0 +1,296 @@
/*************************************************************************
* UrBackup - Client/Server backup system
* Copyright (C) 2011 Martin Raiber
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
**************************************************************************/
#include "vld.h"
#include "Query.h"
#include "Server.h"
#include "sqlite/sqlite3.h"
#include "stringtools.h"
#include "utf8/utf8.h"
#include <memory.h>
CQuery::CQuery(const std::string &pStmt_str, sqlite3_stmt *prepared_statement, CDatabase *pDB) : stmt_str(pStmt_str)
{
ps=prepared_statement;
curr_idx=1;
db=pDB;
}
CQuery::~CQuery()
{
int err=sqlite3_finalize(ps);
if( err!=SQLITE_OK )
Server->Log("SQL: "+(std::string)sqlite3_errmsg(db->getDatabase())+ " Stmt: ["+stmt_str+"]", LL_ERROR);
}
void CQuery::Bind(const std::string &str)
{
int err=sqlite3_bind_text(ps, curr_idx, str.c_str(), (int)str.size(), SQLITE_TRANSIENT);
if( err!=SQLITE_OK )
Server->Log("Error binding text to Query Stmt: ["+stmt_str+"]", LL_ERROR);
++curr_idx;
}
void CQuery::Bind(const std::wstring &str)
{
int err;
if( sizeof(wchar_t)==2 )
{
err=sqlite3_bind_text16(ps, curr_idx, str.c_str(), (int)str.size()*2, SQLITE_TRANSIENT);
}
else
{
unsigned short *tmp=new unsigned short[str.size()];
for(size_t i=0,l=str.size();i<l;++i)
{
tmp[i]=str[i];
}
err=sqlite3_bind_text16(ps, curr_idx, tmp, (int)str.size()*2, SQLITE_TRANSIENT);
delete []tmp;
}
if( err!=SQLITE_OK )
Server->Log("Error binding text to Query Stmt: ["+stmt_str+"]", LL_ERROR);
++curr_idx;
}
void CQuery::Bind(const char* buffer, _u32 bsize)
{
int err=sqlite3_bind_blob(ps, curr_idx, buffer, bsize, SQLITE_TRANSIENT);
if( err!=SQLITE_OK )
Server->Log("Error binding blob to Query Stmt: ["+stmt_str+"]", LL_ERROR);
++curr_idx;
}
void CQuery::Bind(int p)
{
int err=sqlite3_bind_int(ps, curr_idx, p);
if( err!=SQLITE_OK )
Server->Log("Error binding int to Query Stmt: ["+stmt_str+"]", LL_ERROR);
++curr_idx;
}
void CQuery::Bind(unsigned int p)
{
Bind((int64)p);
}
void CQuery::Bind(double p)
{
int err=sqlite3_bind_double(ps, curr_idx, p);
if( err!=SQLITE_OK )
Server->Log("Error binding double to Query Stmt: ["+stmt_str+"]", LL_ERROR);
++curr_idx;
}
void CQuery::Bind(int64 p)
{
int err=sqlite3_bind_int64(ps, curr_idx, p);
if( err!=SQLITE_OK )
Server->Log("Error binding int64 to Query Stmt: ["+stmt_str+"]", LL_ERROR);
++curr_idx;
}
#ifdef _WIN64
void CQuery::Bind(size_t p)
{
Bind((int64)p);
}
#endif
void CQuery::Reset(void)
{
sqlite3_reset(ps);
//sqlite3_clear_bindings(ps);
curr_idx=1;
}
bool CQuery::Write(void)
{
return Execute();
}
bool CQuery::Execute(void)
{
bool transaction_lock=false;
int tries=60; //10min
int err=sqlite3_step(ps);
while( err==SQLITE_BUSY || err==SQLITE_ROW || err==SQLITE_LOCKED )
{
if(err==SQLITE_BUSY)
{
if(transaction_lock==false)
{
if(db->LockForTransaction())
{
transaction_lock=true;
}
sqlite3_busy_timeout(db->getDatabase(), 10000);
}
else
{
--tries;
if(tries<0)
{
Server->Log("SQLITE: Giving up waiting for query Stmt: ["+stmt_str+"]");
break;
}
Server->Log("SQLITE_BUSY in CQuery::Execute Stmt: ["+stmt_str+"]", LL_ERROR);
}
}
else if(err==SQLITE_LOCKED)
{
if(db->LockForTransaction())
{
transaction_lock=true;
}
if(!db->WaitForUnlock())
{
Server->Log("DEADLOCK in CQuery::Execute Stmt: ["+stmt_str+"]", LL_ERROR);
Server->wait(1000);
}
}
err=sqlite3_step(ps);
}
if(transaction_lock)
{
sqlite3_busy_timeout(db->getDatabase(), 50);
db->UnlockForTransaction();
}
if( err!=SQLITE_DONE )
{
Server->Log("Error in CQuery::Execute - "+(std::string)sqlite3_errmsg(db->getDatabase()) +" Stmt: ["+stmt_str+"]", LL_ERROR);
return false;
}
return true;
}
db_nresults CQuery::ReadN(void)
{
int err;
db_nresults rows;
while( (err=sqlite3_step(ps))==SQLITE_BUSY || err==SQLITE_ROW)
{
if( err==SQLITE_ROW )
{
db_nsingle_result res;
int column=0;
const char *column_name;
while( (column_name=sqlite3_column_name(ps, column) )!=NULL )
{
std::string data;
const void *blob=sqlite3_column_blob(ps, column);
int blob_size=sqlite3_column_bytes(ps, column);
data.resize(blob_size);
memcpy(&data[0], blob, blob_size);
res.insert( std::pair<std::string, std::string>(column_name, data) );
++column;
}
rows.push_back( res );
}
}
return rows;
}
db_results CQuery::Read(void)
{
int err;
db_results rows;
while( (err=sqlite3_step(ps))==SQLITE_BUSY || err==SQLITE_ROW)
{
if( err==SQLITE_ROW )
{
db_single_result res;
int column=0;
const unsigned short *c_name;
while( (c_name=(const unsigned short*)sqlite3_column_name16(ps, column) )!=NULL )
{
std::wstring column_name;
if( sizeof(wchar_t)!=2 )
{
size_t len=0;
while(c_name[len]!=0)
++len;
column_name.resize(len);
for(size_t i=0;i<len;++i)
{
column_name[i]=c_name[i];
}
}
else
{
column_name=(wchar_t*)c_name;
}
std::wstring data;
int blob_size=sqlite3_column_bytes16(ps, column);
const void *blob=sqlite3_column_blob(ps, column);
//int blob_size2=sqlite3_column_bytes(ps, column);
if(blob_size>0)
{
if( sizeof(wchar_t)==2 )
{
data.resize(blob_size/2+blob_size%2);
memcpy(&data[0], blob, blob_size);
}
else
{
if( SQLITE_BLOB==sqlite3_column_type(ps, column) )
{
size_t size=(size_t)(blob_size/sizeof(wchar_t))+((blob_size%sizeof(wchar_t))>0?1:0);
data.resize(size);
char* ptr=(char*)data.c_str();
memcpy(ptr, blob, blob_size);
if( blob_size%sizeof(wchar_t)>0 )
{
memset(ptr+blob_size, 0, sizeof(wchar_t)-blob_size%sizeof(wchar_t) );
}
}
else
{
data.resize(blob_size/sizeof(unsigned short));
unsigned short *ip=(unsigned short*)blob;
for(int i=0,l=blob_size/sizeof(unsigned short);i<l;++i)
{
data[i]=*ip;
++ip;
}
}
}
}
res.insert( std::pair<std::wstring, std::wstring>(column_name, data) );
++column;
}
rows.push_back( res );
}
else
{
Server->wait(1000);
}
}
return rows;
}

38
Query.h Normal file
View File

@ -0,0 +1,38 @@
#include "Interface/Query.h"
struct sqlite3_stmt;
struct sqlite3;
class CDatabase;
class CQuery : public IQuery
{
public:
CQuery(const std::string &pStmt_str, sqlite3_stmt *prepared_statement, CDatabase *pDB);
~CQuery();
virtual void Bind(const std::string &str);
virtual void Bind(const std::wstring &str);
virtual void Bind(int p);
virtual void Bind(unsigned int p);
virtual void Bind(double p);
virtual void Bind(int64 p);
#ifdef _WIN64
virtual void Bind(size_t p);
#endif
virtual void Bind(const char* buffer, _u32 bsize);
virtual void Reset(void);
virtual bool Write(void);
db_results Read(void);
db_nresults ReadN(void);
private:
bool Execute(void);
sqlite3_stmt *ps;
std::string stmt_str;
CDatabase *db;
int curr_idx;
};

0
README Normal file
View File

249
SelectThread.cpp Normal file
View File

@ -0,0 +1,249 @@
/*************************************************************************
* UrBackup - Client/Server backup system
* Copyright (C) 2011 Martin Raiber
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
**************************************************************************/
#include "vld.h"
#include <deque>
#include <vector>
#include "SelectThread.h"
#include "Client.h"
#include "WorkerThread.h"
#include "Server.h"
#include "stringtools.h"
#include <errno.h>
std::vector<CWorkerThread*> workers;
IMutex* workers_mutex=NULL;
std::deque<CClient*> client_queue;
IMutex* clients_mutex=NULL;
ICondition* clients_cond=NULL;
void init_mutex_selthread(void)
{
workers_mutex=Server->createMutex();
clients_mutex=Server->createMutex();
clients_cond=Server->createCondition();
}
void destroy_mutex_selthread(void)
{
Server->destroy(workers_mutex);
Server->destroy(clients_mutex);
Server->destroy(clients_cond);
}
CSelectThread::CSelectThread(_u32 pWorkerThreadsPerMaster)
{
mutex=Server->createMutex();
stop_mutex=Server->createMutex();
cond=Server->createCondition();
stop_cond=Server->createCondition();
IScopedLock lock(workers_mutex);
if( workers.size()==0 )
{
for(size_t i=0;i<pWorkerThreadsPerMaster;++i)
{
CWorkerThread *wt=new CWorkerThread(this);
workers.push_back( wt );
Server->createThread(wt);
}
}
run=true;
}
CSelectThread::~CSelectThread()
{
Server->Log("waiting for selectthread...");
{
IScopedLock slock(stop_mutex);
run=false;
WakeUp();
stop_cond->wait(&slock);
Server->Log("deleting workers");
IScopedLock lock(workers_mutex);
for(size_t i=0;i<workers.size();++i)
{
Server->Log("worker: "+nconvert(i));
delete workers[i];
}
workers.clear();
}
Server->destroy(mutex);
Server->destroy(stop_mutex);
Server->destroy(cond);
Server->destroy(stop_cond);
}
void CSelectThread::operator()()
{
_i32 max;
fd_set fdset;
while(run)
{
{
IScopedLock lock(mutex);
while( clients.size()==0 )
{
cond->wait(&lock);
if(!run)
{
IScopedLock slock(stop_mutex);
stop_cond->notify_one();
return;
}
}
bool np=true;
while(np==true )
{
for(size_t i=0;i<clients.size();++i)
{
if( clients[i]->isProcessing()==false )
{
np=false;
}
}
if( np==true )
{
cond->wait(&lock);
if(!run)
{
IScopedLock slock(stop_mutex);
stop_cond->notify_one();
return;
}
}
}
Server->Log("SelectThread woke up...");
FD_ZERO(&fdset);
max=0;
for(size_t i=0;i<clients.size();++i)
{
if( clients[i]->isProcessing()==false )
{
SOCKET s=clients[i]->getSocket();
if((_i32)s>max)
max=(_i32)s;
FD_SET(s, &fdset);
}
}
}
timeval lon;
lon.tv_sec=0;
lon.tv_usec=10000;
_i32 rc = select(max+1, &fdset, 0, 0, &lon);
if( rc>0)
{
IScopedLock lock(mutex);
for(size_t i=0;i<clients.size();++i)
{
if( clients[i]->isProcessing()==false )
{
SOCKET s=clients[i]->getSocket();
if( FD_ISSET(s,&fdset) )
{
FindWorker(clients[i]);
}
}
}
}
else if(rc==-1)
{
if( errno==EBADF )
{
Server->Log("Select error: EBADF",LL_ERROR);
}
else if( errno==EINTR )
{
Server->Log("Select error: EINTR", LL_ERROR);
}
else if( errno==ENOMEM )
{
Server->Log("Select error: ENOMEM", LL_ERROR);
}
else
{
Server->Log("Select error: "+nconvert(errno),LL_ERROR);
}
}
}
IScopedLock slock(stop_mutex);
stop_cond->notify_one();
}
bool CSelectThread::AddClient(CClient *client)
{
if( FreeClients()>0 )
{
IScopedLock lock(mutex);
clients.push_back(client);
WakeUp();
return true;
}
return false;
}
size_t CSelectThread::FreeClients(void)
{
IScopedLock lock(mutex);
return max_clients-clients.size();
}
bool CSelectThread::RemoveClient(CClient *client)
{
IScopedLock lock(mutex);
for(size_t i=0;i<clients.size();++i)
{
if( clients[i]==client )
{
clients.erase( clients.begin()+i );
client->remove();
delete client;
return true;
}
}
return false;
}
void CSelectThread::FindWorker(CClient *client)
{
Server->Log("Notifying worker...");
if( client->setProcessing(true) == false )
{
IScopedLock lock(clients_mutex);
client_queue.push_back( client );
clients_cond->notify_one();
}
}
void CSelectThread::WakeUp(void)
{
cond->notify_one();
}

39
SelectThread.h Normal file
View File

@ -0,0 +1,39 @@
#include "Interface/Thread.h"
#include "Interface/Mutex.h"
#include "Interface/Condition.h"
#include <deque>
#include <vector>
#include "types.h"
class CClient;
class CWorkerThread;
const size_t max_clients=60;
class CSelectThread : public IThread
{
public:
CSelectThread(_u32 pWorkerThreadsPerMaster);
~CSelectThread();
void operator()();
bool AddClient(CClient *client);
bool RemoveClient(CClient *client);
size_t FreeClients(void);
void WakeUp(void);
private:
void FindWorker(CClient *client);
std::deque<CClient*> clients;
IMutex *mutex;
ICondition* cond;
IMutex *stop_mutex;
ICondition *stop_cond;
bool run;
};

1331
Server.cpp Normal file

File diff suppressed because it is too large Load Diff

207
Server.h Normal file
View File

@ -0,0 +1,207 @@
#define NO_INTERFACE
#ifdef THREAD_BOOST
# include <boost/thread/thread.hpp>
#else
#ifdef _WIN32
#else
# include <pthread.h>
#endif
#endif
#include "Interface/Server.h"
#include "Interface/Action.h"
#include "Database.h"
#include <vector>
#include <fstream>
typedef void(*LOADACTIONS)(IServer*);
typedef void(*UNLOADACTIONS)(void);
#ifdef _WIN32
#include <windows.h>
#else
typedef void *HMODULE;
#endif
class FCGIRequest;
class CDatabase;
class CSessionMgr;
class CServiceAcceptor;
class CThreadPool;
class IOutputStream;
class CServer : public IServer
{
public:
CServer();
~CServer();
void setup(void);
void setServerParameters(const str_nmap &pServerParams);
virtual std::string getServerParameter(const std::string &key);
virtual std::string getServerParameter(const std::string &key, const std::string &def);
virtual void setServerParameter(const std::string &key, const std::string &value);
virtual void setLogLevel(int LogLevel);
virtual void setLogFile(const std::string &plf);
virtual void Log(const std::string &pStr, int LogLevel=LL_INFO);
virtual void Log(const std::wstring &pStr, int LogLevel=LL_INFO);
virtual void Write(THREAD_ID tid, const std::string &str, bool cached=true);
virtual void WriteRaw(THREAD_ID tid, const char *buf, size_t bsize, bool cached=true);
virtual void setContentType(THREAD_ID tid, const std::string &str);
virtual void addHeader(THREAD_ID tid, const std::string &str);
THREAD_ID Execute(const std::wstring &action, const std::wstring &context, str_map &GET, str_map &POST, str_nmap &PARAMS, IOutputStream *req);
std::string Execute(const std::wstring &action, const std::wstring &context, str_map &GET, str_map &POST, str_nmap &PARAMS);
virtual void AddAction(IAction *action);
virtual bool RemoveAction(IAction *action);
virtual void setActionContext(std::wstring context);
virtual void resetActionContext(void);
virtual unsigned int getTimeSeconds(void);
virtual unsigned int getTimeMS(void);
virtual bool LoadDLL(const std::string &name);
virtual bool UnloadDLL(const std::string &name);
virtual void destroy(IObject *obj);
virtual void wait(unsigned int ms);
virtual ITemplate* createTemplate(std::string pFile);
virtual IMutex* createMutex(void);
virtual ICondition* createCondition(void);
virtual IPipe *createMemoryPipe(void);
virtual void createThread(IThread *thread);
virtual IThreadPool *getThreadPool(void);
virtual ISettingsReader* createFileSettingsReader(std::string pFile);
virtual ISettingsReader* createDBSettingsReader(THREAD_ID tid, DATABASE_ID pIdentifier, const std::string &pTable, const std::string &pSQL="");
virtual ISettingsReader* createDBSettingsReader(IDatabase *db, const std::string &pTable, const std::string &pSQL="");
virtual ISettingsReader* createMemorySettingsReader(const std::string &pData);
virtual bool openDatabase(std::string pFile, DATABASE_ID pIdentifier);
virtual IDatabase* getDatabase(THREAD_ID tid, DATABASE_ID pIdentifier);
virtual void destroyAllDatabases(void);
virtual ISessionMgr *getSessionMgr(void);
virtual IPlugin* getPlugin(THREAD_ID tid, PLUGIN_ID pIdentifier);
virtual THREAD_ID getThreadID(void);
virtual std::string ConvertToUTF8(const std::wstring &input);
virtual std::wstring ConvertToUnicode(const std::string &input);
virtual std::string ConvertToUTF16(const std::wstring &input);
virtual std::string ConvertToUTF32(const std::wstring &input);
virtual std::wstring ConvertFromUTF16(const std::string &input);
virtual std::wstring ConvertFromUTF32(const std::string &input);
virtual std::string GenerateHexMD5(const std::string &input);
virtual std::string GenerateBinaryMD5(const std::string &input);
virtual std::string GenerateHexMD5(const std::wstring &input);
virtual std::string GenerateBinaryMD5(const std::wstring &input);
virtual void StartCustomStreamService(IService *pService, std::string pServiceName, unsigned short pPort);
virtual IPipe* ConnectStream(std::string pServer, unsigned short pPort, unsigned int pTimeoutms);
virtual void DisconnectStream(IPipe *pipe);
virtual bool RegisterPluginPerThreadModel(IPluginMgr *pPluginMgr, std::string pName);
virtual bool RegisterPluginThreadsafeModel(IPluginMgr *pPluginMgr, std::string pName);
virtual PLUGIN_ID StartPlugin(std::string pName, str_map &params);
virtual bool RestartPlugin(PLUGIN_ID pIdentifier);
virtual unsigned int getNumRequests(void);
virtual void addRequest(void);
virtual IFile* openFile(std::string pFilename, int pMode=0);
virtual IFile* openFile(std::wstring pFilename, int pMode=0);
virtual IFile* openTemporaryFile(void);
virtual IFile* openMemoryFile(void);
virtual bool deleteFile(std::string pFilename);
virtual bool deleteFile(std::wstring pFilename);
virtual POSTFILE_KEY getPostFileKey();
virtual void addPostFile(POSTFILE_KEY pfkey, const std::string &name, const SPostfile &pf);
virtual SPostfile getPostFile(POSTFILE_KEY pfkey, const std::string &name);
virtual void clearPostFiles(POSTFILE_KEY pfkey);
virtual std::wstring getServerWorkingDir(void);
void setServerWorkingDir(const std::wstring &wdir);
void ShutdownPlugins(void);
private:
bool UnloadDLLs(void);
void UnloadDLLs2(void);
void ClearDatabases(THREAD_ID tid);
int loglevel;
bool logfile_a;
std::fstream logfile;
IMutex* log_mutex;
IMutex* action_mutex;
IMutex* requests_mutex;
IMutex* outputs_mutex;
IMutex* db_mutex;
IMutex* thread_mutex;
IMutex* plugin_mutex;
IMutex* rps_mutex;
IMutex* postfiles_mutex;
IMutex* param_mutex;
std::map< std::wstring, std::map<std::wstring, IAction*> > actions;
std::map<std::string, UNLOADACTIONS> unload_functs;
std::vector<HMODULE> unload_handles;
std::map<THREAD_ID, IOutputStream*> current_requests;
std::map<THREAD_ID, std::pair<bool, std::string> > current_outputs;
THREAD_ID curr_thread_id;
#ifdef THREAD_BOOST
std::map<boost::thread::id, THREAD_ID> threads;
#else
#ifdef _WIN32
#else
std::map<pthread_t, THREAD_ID> threads;
#endif
#endif
std::map<DATABASE_ID, std::pair<std::string, std::map<THREAD_ID, CDatabase*> > > databases;
CSessionMgr *sessmgr;
std::vector<CServiceAcceptor*> stream_services;
std::map<PLUGIN_ID, std::map<THREAD_ID, IPlugin*> > perthread_plugins;
std::map<std::string, IPluginMgr*> perthread_pluginmgrs;
std::map<PLUGIN_ID, std::pair<IPluginMgr*,str_map> > perthread_pluginparams;
std::map<std::string, IPluginMgr*> threadsafe_pluginmgrs;
std::map<PLUGIN_ID, IPlugin*> threadsafe_plugins;
std::map<POSTFILE_KEY, std::map<std::string, SPostfile > > postfiles;
POSTFILE_KEY curr_postfilekey;
str_nmap server_params;
PLUGIN_ID curr_pluginid;
unsigned int num_requests;
CThreadPool* threadpool;
std::wstring action_context;
std::wstring workingdir;
};
#ifndef DEF_SERVER
extern CServer *Server;
#endif

55
ServerLinux.cpp Normal file
View File

@ -0,0 +1,55 @@
/*************************************************************************
* UrBackup - Client/Server backup system
* Copyright (C) 2011 Martin Raiber
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
**************************************************************************/
#include "vld.h"
#include "Server.h"
#include <dlfcn.h>
bool CServer::LoadDLL(const std::string &name)
{
HMODULE dll = dlopen( name.c_str(), RTLD_LAZY | RTLD_GLOBAL);
if(dll==NULL)
{
Server->Log("DLL not found: "+(std::string)dlerror(), LL_ERROR);
return false;
}
unload_handles.push_back( dll );
LOADACTIONS load_func=NULL;
load_func=(LOADACTIONS)dlsym(dll,"LoadActions");
unload_functs.insert(std::pair<std::string, UNLOADACTIONS>(name, (UNLOADACTIONS) dlsym(dll,"UnloadActions") ) );
if(load_func==NULL)
{
Server->Log("Loading function in DLL not found", LL_ERROR);
return false;
}
load_func(this);
return true;
}
void CServer::UnloadDLLs2(void)
{
for(size_t i=0;i<unload_handles.size();++i)
{
dlclose( unload_handles[i] );
}
}

53
ServerWin32.cpp Normal file
View File

@ -0,0 +1,53 @@
/*************************************************************************
* UrBackup - Client/Server backup system
* Copyright (C) 2011 Martin Raiber
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
**************************************************************************/
#include "vld.h"
#include "Server.h"
#include "stringtools.h"
#include <windows.h>
bool CServer::LoadDLL(const std::string &name)
{
HMODULE dll = LoadLibraryA( name.c_str() );
if(dll==NULL)
{
Server->Log("Loading DLL \""+name+"\" failed. Error Code: "+nconvert((int)GetLastError()));
return false;
}
unload_handles.push_back( dll );
LOADACTIONS load_func=NULL;
load_func=(LOADACTIONS)GetProcAddress(dll,"LoadActions");
unload_functs.insert(std::pair<std::string, UNLOADACTIONS>(name, (UNLOADACTIONS) GetProcAddress(dll,"UnloadActions") ) );
if(load_func==NULL)
return false;
load_func(this);
return true;
}
void CServer::UnloadDLLs2(void)
{
for(size_t i=0;i<unload_handles.size();++i)
{
FreeLibrary( unload_handles[i] );
}
}

152
ServiceAcceptor.cpp Normal file
View File

@ -0,0 +1,152 @@
/*************************************************************************
* UrBackup - Client/Server backup system
* Copyright (C) 2011 Martin Raiber
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
**************************************************************************/
#include "vld.h"
#ifdef _WIN32
#include <winsock2.h>
#endif
#include "ServiceAcceptor.h"
#include "Server.h"
#include "stringtools.h"
#include "ServiceWorker.h"
#include <memory.h>
#include "Interface/Mutex.h"
#include "Interface/Condition.h"
CServiceAcceptor::CServiceAcceptor(IService * pService, std::string pName, unsigned short port)
{
name=pName;
service=pService;
exitpipe=Server->createMemoryPipe();
do_exit=false;
int rc;
#ifdef _WIN32
WSADATA wsadata;
rc = WSAStartup(MAKEWORD(2,0), &wsadata);
if(rc == SOCKET_ERROR) return;
#endif
s=socket(AF_INET,SOCK_STREAM,0);
if(s<1)
{
Server->Log(name+": Creating SOCKET failed",LL_ERROR);
return;
}
sockaddr_in addr;
memset(&addr, 0, sizeof(sockaddr_in));
addr.sin_family=AF_INET;
addr.sin_port=htons(port);
addr.sin_addr.s_addr=INADDR_ANY;
rc=bind(s,(sockaddr*)&addr,sizeof(addr));
if(rc==SOCKET_ERROR)
{
Server->Log(name+": Failed binding SOCKET to Port "+nconvert(port),LL_ERROR);
return;
}
listen(s, 10000);
Server->Log(name+": Server started up sucessfully!",LL_INFO);
}
CServiceAcceptor::~CServiceAcceptor()
{
do_exit=true;
closesocket(s);
for(size_t i=0;i<workers.size();++i)
{
workers[i]->stop();
}
size_t c=0;
while(c<workers.size()+1)
{
std::string r;
exitpipe->Read(&r);
if(r=="ok")
++c;
}
Server->destroy(exitpipe);
for(size_t i=0;i<workers.size();++i)
{
delete workers[i];
}
}
void CServiceAcceptor::operator()(void)
{
while(do_exit==false)
{
fd_set fdset;
socklen_t addrsize=sizeof(sockaddr_in);
FD_ZERO(&fdset);
FD_SET(s, &fdset);
timeval lon;
lon.tv_sec=100;
lon.tv_usec=0;
_i32 rc=select((int)s+1, &fdset, 0, 0, &lon);
if( FD_ISSET(s,&fdset) && do_exit==false)
{
sockaddr_in naddr;
SOCKET ns=accept(s, (sockaddr*)&naddr, &addrsize);
if(ns>0)
{
Server->Log(name+": New Connection incomming "+nconvert(Server->getTimeMS())+" s: "+nconvert((int)ns), LL_DEBUG);
#ifdef _WIN32
int window_size=512*1024;
setsockopt(ns, SOL_SOCKET, SO_SNDBUF, (char *) &window_size, sizeof(window_size));
setsockopt(ns, SOL_SOCKET, SO_RCVBUF, (char *) &window_size, sizeof(window_size));
#endif
AddToWorker(ns);
}
}
}
exitpipe->Write("ok");
}
void CServiceAcceptor::AddToWorker(SOCKET pSocket)
{
for(size_t i=0;i<workers.size();++i)
{
if( workers[i]->getAvailableSlots()>0 )
{
workers[i]->AddClient(pSocket);
return;
}
}
Server->Log(name+": No available slots... starting new Worker", LL_DEBUG);
CServiceWorker *nw=new CServiceWorker(service, name, exitpipe);
workers.push_back(nw);
Server->createThread(nw);
nw->AddClient( pSocket );
}

175
ServiceWorker.cpp Normal file
View File

@ -0,0 +1,175 @@
/*************************************************************************
* UrBackup - Client/Server backup system
* Copyright (C) 2011 Martin Raiber
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
**************************************************************************/
#include "vld.h"
#include "Interface/Service.h"
#include "ServiceWorker.h"
#include "StreamPipe.h"
#include "Server.h"
#include "stringtools.h"
#include <stdlib.h>
CServiceWorker::CServiceWorker(IService *pService, std::string pName, IPipe * pExit) : exit(pExit)
{
mutex=Server->createMutex();
nc_mutex=Server->createMutex();
cond=Server->createCondition();
name=pName;
service=pService;
nClients=0;
do_stop=false;
std::string s_max_clients;
if((s_max_clients=Server->getServerParameter("max_worker_clients"))!="")
{
max_clients=atoi(s_max_clients.c_str());
}
else
{
max_clients=MAX_CLIENTS;
}
}
CServiceWorker::~CServiceWorker()
{
for(size_t i=0;i<clients.size();++i)
{
service->destroyClient( clients[i].first );
delete clients[i].second;
}
clients.clear();
}
void CServiceWorker::stop(void)
{
do_stop=true;
cond->notify_all();
}
void CServiceWorker::addNewClients(void)
{
for(size_t i=0;i<new_clients.size();++i)
{
CStreamPipe *pipe=new CStreamPipe(new_clients[i]);
ICustomClient *nc=service->createClient();
nc->Init(tid, pipe);
clients.push_back( std::pair<ICustomClient*, CStreamPipe*>(nc, pipe) );
}
new_clients.clear();
}
void CServiceWorker::operator()(void)
{
tid=Server->getThreadID();
fd_set fdset;
int max;
while(!do_stop)
{
{
IScopedLock lock(mutex);
addNewClients();
}
{
{
if( clients.empty() )
{
IScopedLock lock(mutex);
if(new_clients.empty())
{
Server->Log(name+": Sleeping..."+nconvert(Server->getTimeMS()), LL_DEBUG);
cond->wait(&lock);
Server->Log(name+": Waking up..."+nconvert(Server->getTimeMS()), LL_DEBUG);
continue;
}
else
{
continue;
}
}
}
for(size_t i=0;i<clients.size();++i)
{
bool b=clients[i].first->Run();
if( b==false )
{
IScopedLock lock(mutex);
Server->Log(name+": Removing user"+nconvert(Server->getTimeMS()), LL_DEBUG);
service->destroyClient( clients[i].first );
delete clients[i].second;
clients.erase( clients.begin()+i );
IScopedLock lock2(nc_mutex);
--nClients;
continue;
}
}
FD_ZERO(&fdset);
max=0;
for(size_t i=0;i<clients.size();++i)
{
SOCKET s=clients[i].second->getSocket();
if((_i32)s>max)
max=(_i32)s;
FD_SET(s, &fdset);
}
}
timeval lon;
lon.tv_sec=0;
lon.tv_usec=10000;
_i32 rc = select(max+1, &fdset, 0, 0, &lon);
if( rc>0 )
{
for(size_t i=0;i<clients.size();++i)
{
SOCKET s=clients[i].second->getSocket();
if( FD_ISSET(s,&fdset) )
{
Server->Log("Incoming data for client..", LL_DEBUG);
clients[i].first->ReceivePackets();
}
}
}
}
exit->Write("ok");
}
int CServiceWorker::getAvailableSlots(void)
{
IScopedLock lock(nc_mutex);
return max_clients-nClients;
}
void CServiceWorker::AddClient(SOCKET pSocket)
{
IScopedLock lock(mutex);
new_clients.push_back( pSocket );
cond->notify_all();
IScopedLock lock2(nc_mutex);
++nClients;
}

50
ServiceWorker.h Normal file
View File

@ -0,0 +1,50 @@
#include <vector>
#include <utility>
#include "Interface/Thread.h"
#include "Interface/Mutex.h"
#include "Interface/Condition.h"
#include "Interface/Pipe.h"
#include "socket_header.h"
#include "Interface/CustomClient.h"
const int MAX_CLIENTS=20;
class IService;
class CStreamPipe;
class CServiceWorker : public IThread
{
public:
CServiceWorker(IService *pService, std::string pName, IPipe * pExit);
~CServiceWorker();
void operator ()(void);
int getAvailableSlots(void);
void AddClient(SOCKET pSocket);
void stop(void);
private:
void addNewClients(void);
std::vector<std::pair<ICustomClient*, CStreamPipe*> > clients;
std::vector<SOCKET> new_clients;
IMutex* mutex;
IMutex* nc_mutex;
ICondition* cond;
IPipe *exit;
int nClients;
int max_clients;
THREAD_ID tid;
std::string name;
IService *service;
bool do_stop;
};

217
SessionMgr.cpp Normal file
View File

@ -0,0 +1,217 @@
/*************************************************************************
* UrBackup - Client/Server backup system
* Copyright (C) 2011 Martin Raiber
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
**************************************************************************/
#include "vld.h"
#include <stdlib.h>
#include "SessionMgr.h"
#include "Server.h"
#include "stringtools.h"
CSessionMgr::CSessionMgr(void)
{
sess_mutex=Server->createMutex();
wait_cond=Server->createCondition();
wait_mutex=Server->createMutex();
stop_mutex=Server->createMutex();
stop_cond=Server->createCondition();
SESSIONID_LEN=30;//Server->Settings->getValue("SESSIONID_LEN",15);
SESSION_TIMEOUT_S=1800;//Server->Settings->getValue("SESSION_TIMEOUT_S",600);
for(unsigned char i=48;i<58;++i)
Pool.push_back(i);
for(unsigned char i=65;i<91;++i)
Pool.push_back(i);
for(unsigned char i=97;i<122;++i)
Pool.push_back(i);
run=false;
}
CSessionMgr::~CSessionMgr()
{
{
IScopedLock lock( sess_mutex );
Server->Log("removing sessions...");
if(!mSessions.empty() )
{
std::vector<std::wstring> sesids;
for(std::map<std::wstring, SUser*>::iterator i=mSessions.begin();i!=mSessions.end();++i)
{
sesids.push_back(i->first);
}
for(size_t i=0;i<sesids.size();++i)
{
RemoveSession(sesids[i]);
}
}
Server->Log("done.");
}
if(run)
{
IScopedLock slock(stop_mutex);
Server->Log("waiting for sessionmgr...");
run=false;
wait_cond->notify_all();
stop_cond->wait(&slock);
Server->Log("done.");
}
Server->destroy(sess_mutex);
Server->destroy(wait_mutex);
Server->destroy(stop_mutex);
Server->destroy(wait_cond);
Server->destroy(stop_cond);
}
void CSessionMgr::startTimeoutSessionThread()
{
run=true;
Server->createThread(this);
}
std::wstring CSessionMgr::GenerateSessionIDWithUser(const std::wstring &pUsername, const std::wstring &pIdentData, bool update_user)
{
std::wstring ret;
ret.resize(SESSIONID_LEN);
for(int i=0;i<SESSIONID_LEN;++i)
ret[i]+=Pool[rand()%Pool.size()];
IScopedLock lock( sess_mutex );
if(update_user)
{
bool changed=true;
while(changed==true)
{
changed=false;
for(std::map<std::wstring, SUser*>::iterator i=mSessions.begin();i!=mSessions.end();++i)
{
if( i->second->username==pUsername )
{
changed=true;
RemoveSession(i->first);
break;
}
}
}
}
SUser *user=new SUser;
user->username=pUsername;
user->session=ret;
user->mutex=Server->createMutex();
user->lock=NULL;
user->ident_data=pIdentData;
user->id=-1;
user->lastused=Server->getTimeMS();
mSessions.insert(std::pair<std::wstring, SUser*>(ret, user) );
return ret;
}
SUser *CSessionMgr::getUser(const std::wstring &pSID, const std::wstring &pIdentData, bool update)
{
IScopedLock lock( sess_mutex );
std::map<std::wstring, SUser*>::iterator i=mSessions.find(pSID);
if( i!=mSessions.end() )
{
if( i->second->ident_data!=pIdentData )
return NULL;
ILock *lock=((IMutex*)i->second->mutex)->Lock2();
i->second->lock=lock;
if( update==true )
i->second->lastused=Server->getTimeMS();
return i->second;
}
else
return NULL;
}
void CSessionMgr::releaseUser(SUser *user)
{
if( user!=NULL )
{
((ILock*)user->lock)->Remove();
}
}
bool CSessionMgr::RemoveSession(const std::wstring &pSID)
{
IScopedLock lock( sess_mutex );
std::map<std::wstring, SUser*>::iterator i=mSessions.find(pSID);
if( i!=mSessions.end() )
{
IScopedLock *lock=new IScopedLock(((IMutex*)i->second->mutex));
delete lock;
Server->destroy((IMutex*)i->second->mutex);
for(std::map<std::string, IObject* >::iterator iter=i->second->mCustom.begin();
iter!=i->second->mCustom.end();++iter)
{
iter->second->Remove();
}
mSessions.erase(i);
return true;
}
else
return false;
}
unsigned int CSessionMgr::TimeoutSessions(void)
{
if(Server!=NULL)
Server->Log("Looking for old Sessions... "+nconvert(mSessions.size())+" sessions", LL_INFO);
unsigned int ret=0;
IScopedLock lock( sess_mutex );
unsigned int ttime=Server->getTimeMS();
for(std::map<std::wstring, SUser*>::iterator i=mSessions.begin();i!=mSessions.end();++i)
{
unsigned int diff=ttime-i->second->lastused;
if( diff > (unsigned int)(SESSION_TIMEOUT_S)*1000 )
{
Server->Log(L"Session timeout: Session "+i->first, LL_INFO);
RemoveSession(i->first);
return 0;
}
else
{
ret=(std::max)(diff, ret);
}
}
return (unsigned int)((SESSION_TIMEOUT_S)*1000)-ret+10;
}
void CSessionMgr::operator()(void)
{
{
IScopedLock lock( wait_mutex );
while(run)
{
unsigned int wtime=TimeoutSessions();
wait_cond->wait(&lock, wtime);
}
}
IScopedLock slock(stop_mutex);
stop_cond->notify_one();
}

41
SessionMgr.h Normal file
View File

@ -0,0 +1,41 @@
#include <map>
#include <vector>
#include "Interface/SessionMgr.h"
#include "Interface/Mutex.h"
#include "Interface/Condition.h"
#include "Interface/Thread.h"
class CSessionMgr : public ISessionMgr, public IThread
{
public:
CSessionMgr(void);
~CSessionMgr();
virtual std::wstring GenerateSessionIDWithUser(const std::wstring &pUsername, const std::wstring &pIdentData, bool update_user=false);
virtual SUser *getUser(const std::wstring &pSID, const std::wstring &pIdentData, bool update=true);
virtual void releaseUser(SUser *user);
virtual bool RemoveSession(const std::wstring &pSID);
void startTimeoutSessionThread();
void operator()(void);
private:
unsigned int TimeoutSessions();
int SESSIONID_LEN;
int SESSION_TIMEOUT_S;
std::vector<wchar_t> Pool;
std::map<std::wstring, SUser*> mSessions;
IMutex* sess_mutex;
ICondition *wait_cond;
IMutex *wait_mutex;
IMutex *stop_mutex;
ICondition *stop_cond;
bool run;
};

103
SettingsReader.cpp Normal file
View File

@ -0,0 +1,103 @@
/*************************************************************************
* UrBackup - Client/Server backup system
* Copyright (C) 2011 Martin Raiber
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
**************************************************************************/
#include "SettingsReader.h"
#include "stringtools.h"
#ifndef _WIN32
#include <stdlib.h>
#endif
std::string CSettingsReader::getValue(std::string key,std::string def)
{
std::string value;
bool b=getValue(key,&value);
if(b==false)
return def;
else
return value;
}
std::string CSettingsReader::getValue(std::string key)
{
std::string value;
bool b=getValue(key,&value);
if(b==false)
return "";
else
return value;
}
int CSettingsReader::getValue(std::string key, int def)
{
std::string value;
bool b=getValue(key,&value);
if(b==false)
return def;
else
return atoi(value.c_str());
}
float CSettingsReader::getValue(std::string key, float def)
{
std::string value;
bool b=getValue(key,&value);
if(b==false)
return def;
else
return (float)atof(value.c_str());
}
std::wstring CSettingsReader::getValue(std::wstring key,std::wstring def)
{
std::wstring value;
bool b=getValue(key,&value);
if(b==false)
return def;
else
return value;
}
std::wstring CSettingsReader::getValue(std::wstring key)
{
std::wstring value;
bool b=getValue(key,&value);
if(b==false)
return L"";
else
return value;
}
int CSettingsReader::getValue(std::wstring key, int def)
{
std::wstring value;
bool b=getValue(key,&value);
if(b==false)
return def;
else
return atoi(wnarrow(value).c_str());
}
float CSettingsReader::getValue(std::wstring key, float def)
{
std::wstring value;
bool b=getValue(key,&value);
if(b==false)
return def;
else
return (float)atof(wnarrow(value).c_str());
}

24
SettingsReader.h Normal file
View File

@ -0,0 +1,24 @@
#ifndef CSETTINGSREADER_H
#define CSETTINGSREADER_H
#include "Interface/SettingsReader.h"
class CSettingsReader : public ISettingsReader
{
public:
virtual bool getValue(std::string key, std::string *value)=0;
virtual bool getValue(std::wstring key, std::wstring *value)=0;
std::string getValue(std::string key,std::string def);
std::string getValue(std::string key);
int getValue(std::string key, int def);
float getValue(std::string key, float def);
std::wstring getValue(std::wstring key,std::wstring def);
std::wstring getValue(std::wstring key);
int getValue(std::wstring key, int def);
float getValue(std::wstring key, float def);
};
#endif //CSETTINGSREADER_H

205
StreamPipe.cpp Normal file
View File

@ -0,0 +1,205 @@
/*************************************************************************
* UrBackup - Client/Server backup system
* Copyright (C) 2011 Martin Raiber
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
**************************************************************************/
#ifdef _WIN32
#include <winsock2.h>
#endif
#include "StreamPipe.h"
#ifndef _WIN32
#include <memory.h>
#endif
CStreamPipe::CStreamPipe( SOCKET pSocket)
{
s=pSocket;
has_error=false;
}
CStreamPipe::~CStreamPipe()
{
closesocket(s);
}
size_t CStreamPipe::Read(char *buffer, size_t bsize, int timeoutms)
{
fd_set conn;
FD_ZERO(&conn);
FD_SET(s, &conn);
timeval *tv=NULL;
timeval to;
if( timeoutms>=0 )
{
to.tv_sec=(long)(timeoutms/1000);
to.tv_usec=(long)(timeoutms%1000)*1000;
tv=&to;
}
int rc=select((int)s+1,&conn,NULL,NULL,tv);
if( rc>0 )
{
rc=recv(s, buffer, (int)bsize, MSG_NOSIGNAL);
}
if( rc>0 )
return rc;
else
{
has_error=true;
return 0;
}
}
bool CStreamPipe::Write(const char *buffer, size_t bsize, int timeoutms)
{
fd_set conn;
FD_ZERO(&conn);
FD_SET(s, &conn);
timeval *tv=NULL;
timeval to;
if( timeoutms>=0 )
{
to.tv_sec=(long)(timeoutms/1000);
to.tv_usec=(long)(timeoutms%1000)*1000;
tv=&to;
}
int rc=select((int)s+1,NULL,&conn,NULL,tv);
size_t written=0;
if(rc>0 )
{
rc=send(s, buffer,(int)bsize, MSG_NOSIGNAL);
if(rc>=0)
{
written+=rc;
if( written<bsize )
{
return Write(buffer+written, bsize-written, timeoutms);
}
}
else
{
has_error=true;
return false;
}
}
else
{
has_error=true;
return false;
}
if( rc!=SOCKET_ERROR)
return true;
else
{
has_error=true;
return false;
}
}
bool CStreamPipe::Write(const std::string &str, int timeoutms)
{
return Write(&str[0], str.size(), timeoutms);
}
size_t CStreamPipe::Read(std::string *ret, int timeoutms)
{
char buffer[2000];
size_t l=Read(buffer, 2000, timeoutms);
if( l>0 )
{
ret->resize(l);
memcpy((char*)ret->c_str(), buffer, l);
}
else
{
return 0;
}
return l;
}
bool CStreamPipe::isWritable(int timeoutms)
{
fd_set fdset;
FD_ZERO(&fdset);
FD_SET(s, &fdset);
timeval *tv=NULL;
timeval to;
if( timeoutms>=0 )
{
to.tv_sec=(long)(timeoutms/1000);
to.tv_usec=(long)(timeoutms%1000)*1000;
tv=&to;
}
int rc=select((int)s+1, 0, &fdset, 0, tv);
if( rc>0 )
return true;
else
{
has_error=true;
return false;
}
}
bool CStreamPipe::isReadable(int timeoutms)
{
fd_set fdset;
FD_ZERO(&fdset);
FD_SET(s, &fdset);
timeval *tv=NULL;
timeval to;
if( timeoutms>=0 )
{
to.tv_sec=(long)(timeoutms/1000);
to.tv_usec=(long)(timeoutms%1000)*1000;
tv=&to;
}
int rc=select((int)s+1, &fdset, 0, 0, tv);
if( rc>0 )
return true;
else
{
has_error=true;
return false;
}
}
bool CStreamPipe::hasError(void)
{
return has_error;
}
SOCKET CStreamPipe::getSocket(void)
{
return s;
}
void CStreamPipe::shutdown(void)
{
#ifdef _WIN32
::shutdown(s, SD_BOTH);
#else
::shutdown(s, SHUT_RDWR);
#endif
}

30
StreamPipe.h Normal file
View File

@ -0,0 +1,30 @@
#include "Interface/Pipe.h"
#include "socket_header.h"
class CStreamPipe : public IPipe
{
public:
CStreamPipe( SOCKET pSocket);
~CStreamPipe();
virtual size_t Read(char *buffer, size_t bsize, int timeoutms);
virtual bool Write(const char *buffer, size_t bsize, int timeoutms);
virtual size_t Read(std::string *ret, int timeoutms);
virtual bool Write(const std::string &str, int timeoutms);
virtual bool isWritable(int timeoutms);
virtual bool isReadable(int timeoutms);
virtual bool hasError(void);
virtual void shutdown(void);
virtual size_t getNumElements(void){ return 0;};
SOCKET getSocket(void);
private:
SOCKET s;
bool has_error;
};

147
Table.cpp Normal file
View File

@ -0,0 +1,147 @@
/*************************************************************************
* UrBackup - Client/Server backup system
* Copyright (C) 2011 Martin Raiber
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
**************************************************************************/
#include "Table.h"
CRATable::~CRATable()
{
for(size_t i=0;i<tables.size();++i)
{
delete tables[i];
}
}
void CRATable::addObject(std::wstring key, ITable *tab)
{
table_map[key]=tab;
tables.push_back(tab);
}
ITable* CRATable::getObject(size_t n)
{
if( n<tables.size() )
return tables[n];
else
return NULL;
}
ITable* CRATable::getObject(std::wstring str)
{
std::map<std::wstring, ITable*>::iterator iter=table_map.find(str);
if( iter!= table_map.end() )
{
return iter->second;
}
else
return NULL;
}
std::wstring CRATable::getValue()
{
return L"";
}
size_t CRATable::getSize()
{
return tables.size();
}
void CRATable::addString(std::wstring key, std::wstring str)
{
CTablestring *ts=new CTablestring(str);
this->addObject(key, ts);
}
//-------------------------
CTable::~CTable()
{
for(std::map<std::wstring, ITable*>::iterator i=table_map.begin();i!=table_map.end();++i)
{
delete i->second;
}
}
void CTable::addObject(std::wstring key, ITable *tab)
{
table_map[key]=tab;
}
ITable* CTable::getObject(size_t n)
{
return NULL;
}
ITable* CTable::getObject(std::wstring str)
{
std::map<std::wstring, ITable*>::iterator iter=table_map.find(str);
if( iter!= table_map.end() )
{
return iter->second;
}
else
return NULL;
}
std::wstring CTable::getValue()
{
return L"";
}
size_t CTable::getSize()
{
return table_map.size();
}
void CTable::addString(std::wstring key, std::wstring str)
{
CTablestring *ts=new CTablestring(str);
this->addObject(key, ts);
}
//------------------------
CTablestring::CTablestring(std::wstring pStr)
{
str=pStr;
}
void CTablestring::addObject(std::wstring key, ITable *tab)
{
}
ITable* CTablestring::getObject(size_t n)
{
return NULL;
}
ITable* CTablestring::getObject(std::wstring key)
{
return NULL;
}
std::wstring CTablestring::getValue()
{
return str;
}
size_t CTablestring::getSize()
{
return 1;
}
void CTablestring::addString(std::wstring key, std::wstring str)
{
}

55
Table.h Normal file
View File

@ -0,0 +1,55 @@
#include <map>
#include <vector>
#include <string>
#include "Interface/Table.h"
class CRATable : public ITable
{
public:
~CRATable();
virtual void addObject(std::wstring key, ITable *tab);
virtual ITable* getObject(size_t n);
virtual ITable* getObject(std::wstring key);
virtual std::wstring getValue();
virtual size_t getSize();
virtual void addString(std::wstring key, std::wstring str);
private:
std::map<std::wstring, ITable*> table_map;
std::vector<ITable*> tables;
};
class CTable : public ITable
{
public:
~CTable();
virtual void addObject(std::wstring key, ITable *tab);
virtual ITable* getObject(size_t n);
virtual ITable* getObject(std::wstring key);
virtual std::wstring getValue();
virtual size_t getSize();
virtual void addString(std::wstring key, std::wstring str);
private:
std::map<std::wstring, ITable*> table_map;
};
class CTablestring : public ITable
{
public:
CTablestring(std::wstring pStr);
virtual void addObject(std::wstring key, ITable *tab);
virtual ITable* getObject(size_t n);
virtual ITable* getObject(std::wstring key);
virtual std::wstring getValue();
virtual size_t getSize();
virtual void addString(std::wstring key, std::wstring str);
private:
std::wstring str;
};

540
Template.cpp Normal file
View File

@ -0,0 +1,540 @@
/*************************************************************************
* UrBackup - Client/Server backup system
* Copyright (C) 2011 Martin Raiber
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
**************************************************************************/
#include "vld.h"
#include "Template.h"
#include "stringtools.h"
#include "Table.h"
#include "utf8/utf8.h"
#include "Server.h"
#include "Interface/Database.h"
CTemplate::CTemplate(std::string pFile)
{
file=pFile;
std::string tdata=getFile(pFile);
//if( utf8::is_bom(tdata.begin()) )
{
try
{
utf8::utf8to16(tdata.begin(), tdata.end(), back_inserter(data) );
}
catch(...)
{
data=L"Invalid UTF-8";
}
}
/*else
{
data=widen(tdata);
}*/
mCurrValues=new CTable();
mValuesRoot=mCurrValues;
AddDefaultReplacements();
}
CTemplate::~CTemplate()
{
delete mValuesRoot;
for(size_t i=0;i<mTables.size();++i)
{
mTables[i].first->destroyQuery( mTables[i].second );
}
}
void CTemplate::AddDefaultReplacements(void)
{
#define ADD_REPLACEMENT(key,value) mReplacements.push_back( std::pair<std::string, std::string>(key,value) )
#define ADD_REPLACEMENT_CODE(key,value) {unsigned char ch=key; std::string tmp;tmp+=ch; mReplacements.push_back( std::pair<std::string, std::string>(tmp,value) );}
/*ADD_REPLACEMENT(L"ä",L"\\xE4");
ADD_REPLACEMENT(L"ö",L"\\xF6");
ADD_REPLACEMENT(L"ü",L"\\xFC");
ADD_REPLACEMENT(L"Ä",L"\\xC4");
ADD_REPLACEMENT(L"Ö",L"\\xFC");
ADD_REPLACEMENT(L"Ü",L"\\xD6");
ADD_REPLACEMENT(L"ß",L"\\xDF");
ADD_REPLACEMENT_CODE(246, "\\xF6");
ADD_REPLACEMENT_CODE(228, "\\xE4");
ADD_REPLACEMENT_CODE(252, "\\xFC");
ADD_REPLACEMENT_CODE(196, "\\xC4");
ADD_REPLACEMENT_CODE(214, "\\xD6");
ADD_REPLACEMENT_CODE(220, "\\xDC");
ADD_REPLACEMENT_CODE(223, "\\xDF");*/
}
ITable* CTemplate::createTableRecursive(std::wstring key)
{
std::vector<std::wstring> toks;
Tokenize(key, toks, L".");
ITable *ct=mCurrValues;
for(size_t i=0;i<toks.size();++i)
{
ITable *nt=ct->getObject(toks[i]);
if( nt==NULL )
{
nt=new CRATable();
ct->addObject(toks[i], nt);
}
ct=nt;
}
return ct;
}
ITable* CTemplate::getTable(std::wstring key)
{
ITable *ret;
if( (ret=findTable(key))!=NULL )
return ret;
else
return createTableRecursive(key);
}
void CTemplate::setValue(std::wstring key, std::wstring value)
{
std::vector<std::wstring> toks;
Tokenize(key, toks, L".");
ITable *ct=mCurrValues;
if( toks.size()==0 )
return;
if( toks.size()>1 )
{
for(size_t i=0;i<toks.size()-1;++i)
{
ct=ct->getObject(toks[i]);
if( ct==NULL )
break;
}
}
if( ct!=NULL )
ct->addString(toks[toks.size()-1], value);
}
ITable *CTemplate::findTable(std::wstring key)
{
std::vector<std::wstring> toks;
Tokenize(key, toks, L".");
ITable *ct;
if( toks.size()>0 )
{
ct=mCurrValues->getObject(toks[0]);
if( ct==NULL && mValuesRoot!=mCurrValues )
{
ct=mValuesRoot->getObject(toks[0]);
}
for(size_t i=1;i<toks.size() && ct!=NULL;++i)
{
ct=ct->getObject(toks[i]);
}
return ct;
}
return NULL;
}
bool CTemplate::FindValue(const std::wstring &key, std::wstring &value, bool dbs)
{
ITable *val=findTable(key);
if( val!=NULL )
{
value=val->getValue();
return true;
}
else
{
if( dbs==false )
return false;
else
{
for(size_t i=0;i<mTables.size();++i)
{
mTables[i].second->Bind(key);
db_results res=mTables[i].second->Read();
mTables[i].second->Reset();
if( res.size() >0 )
{
db_single_result result=res[0];
db_single_result::iterator iter=result.find(L"value");
if( iter!= result.end() )
{
value=iter->second;
return true;
}
}
}
return false;
}
}
}
std::string CTemplate::getData(void)
{
std::wstring output=data;
transform(output);
std::string ret;
try
{
if( sizeof(wchar_t)==2 )
utf8::utf16to8(output.begin(), output.end(), back_inserter(ret) );
else
utf8::utf32to8(output.begin(), output.end(), back_inserter(ret) );
}
catch(...)
{
Server->Log("Invalid UTF8!", LL_ERROR);
}
return ret;
}
void CTemplate::transform(std::wstring &output)
{
for(size_t i=0;i<output.size();++i)
{
if( output[i]=='\n' && i!=0 && output[i-1]!='\r' )
{
output.insert(i,L"\r");
}
}
bool retry=true;
while(retry==true)
{
retry=false;
for(size_t i=0;i<output.size();++i)
{
// VALUES
if( next(output, i, L"#{")==true )
{
size_t j;
for(j=i+2;j<output.size();++j)
{
if( output[j]=='}' )
break;
}
std::wstring var=output.substr(i+2, (j)-(i+2) );
std::wstring value;
bool b=FindValue( var, value);
if( b==true )
{
output.replace(i, j-i+1, value );
}
else
{
}
}
//PREPROCESSOR
{
if( ((i==0||i==1) && next(output, i, L"#exit" )) || (i!=0 && next(output, i, L"\n#exit")) )
{
output.erase(i);
break;
}
bool foreach1=false,foreach2=false;
if( ((i==0||i==1) && (foreach1=next(output, i, L"#foreach in ")==true)) || (foreach2=next(output, i, L"\r\n#foreach in "))==true)
{
if( foreach2 )
i+=2;
std::wstring var;
for(size_t j=i+12;j<output.size();++j)
{
if( output[j]=='\n' || output[j]=='\r' )
break;
var+=output[j];
}
ITable *tab=findTable(var);
if( tab!=NULL )
{
size_t len=12+var.size();
size_t end=std::string::npos;
int count=0;
for(size_t j=i+len;j<output.size();++j)
{
if( next(output, j, L"\r\n#foreach") )
{
++count;
}
if( next(output, j, L"\r\n#endfor" ) )
{
if( count<=0 )
{
end=j;
break;
}
else
{
--count;
}
}
}
if( foreach2 )
{
len+=2;
i-=2;
}
if( end!=std::string::npos )
{
std::wstring mid=output.substr(i+len, end-(i+len));
std::wstring strend=output.substr(end+9);
output=output.substr(0,i);
ITable *old_values=mCurrValues;
for(size_t k=0;k<tab->getSize();++k)
{
std::wstring tmp=mid;
mCurrValues=tab->getObject(k);
transform(tmp);
output+=tmp;
}
mCurrValues=old_values;
i=output.size()-1;
output+=strend;
}
}
}
bool ifndef1=false,ifndef2=false;
bool next2=false;
if( ((i==0||i==1) && next(output, i, L"#ifdef ")==true) || (next2=next(output, i, L"\r\n#ifdef "))==true
||((i==0||i==1) && (ifndef1=next(output, i, L"#ifndef "))==true) || ((ifndef2=next(output, i, L"\r\n#ifndef "))==true)
)
{
bool ifndef=false;
if( ifndef1 || ifndef2 )
ifndef=true;
if( next2==true||ifndef2==true )
i+=2;
std::wstring var;
int addi=7;
if( ifndef==true )
++addi;
for(size_t j=i+addi;j<output.size();++j)
{
if( output[j]=='\n' || output[j]=='\r' )
break;
var+=output[j];
}
std::wstring value;
bool found=FindValue(var, value);
if( ifndef==true )
found=!found;
if( found==true )
{
if(i!=0)
i-=2;
output.erase(i,addi+var.size()+2 );
size_t j;
size_t todel=std::string::npos;
size_t proc=0;
for(j=i;j<output.size();++j)
{
if( next(output, j , L"\r\n#ifdef") || next(output, j , L"\r\n#ifndef") )
{
++proc;
}
else if( proc==0 && next(output, j, L"\r\n#elseif" ) )
{
if( todel==std::string::npos )
todel=j;
}
else if( proc==0 && next(output, j, L"\r\n#else" ) )
{
if( todel==std::string::npos )
todel=j;
}
else if( next(output, j, L"\r\n#endif" ) )
{
if( proc!=0 )
{
--proc;
}
else
break;
}
}
//Not tested...
if( i>0 )--i;
output.erase(j, 8);
if( todel!=std::string::npos )
output.erase(todel, j-todel);
}
else
{
size_t todel=0;
size_t enterelseif=std::string::npos;
size_t stopelseif=std::string::npos;
size_t proc=0;
for(size_t j=i;j<output.size();++j)
{
if( next(output, j , L"\r\n#ifdef") || next(output, j , L"\r\n#ifndef") )
{
++proc;
}
else if( proc==0 && next(output, j , L"\r\n#elseif" ) )
{
std::wstring key;
for(size_t k=j+10;k<output.size();++k)
{
if( output[k]=='\r' || output[k]=='\n' )
break;
key+=output[k];
}
if( enterelseif==std::string::npos )
{
std::wstring value;
if( FindValue( key, value) )
{
enterelseif=j;
}
}
else if(stopelseif==std::string::npos )
{
stopelseif=j;
}
output.erase(j, 10+key.size() );
}
else if( proc==0 &&next(output, j, L"\r\n#else") )
{
if( enterelseif==std::string::npos )
{
enterelseif=j;
}
else if( stopelseif==std::string::npos )
stopelseif=j;
output.erase(j, 7 );
--j;
if( todel>0 )
todel--;
}
else if( next(output, j, L"\r\n#endif" ) )
{
if( proc!=0 )
--proc;
else
{
if( enterelseif!=std::string::npos )
if( stopelseif==std::string::npos )
stopelseif=j;
break;
}
}
++todel;
}
std::wstring data;
if( enterelseif!=std::string::npos )
data=output.substr(enterelseif, stopelseif-enterelseif);
if( i==0 && data.size()>1 )
data.erase(0,2);
if( i!=0 )
{
i-=2;
todel+=2;
}
output.erase(i, todel+8);
if( data.size()>0 )
{
output.insert(i, data);
}
if( i>0 )
--i;
else
{
retry=true;
break;
}
}
}
if( next(output, i, L"#include \"")==true )
{
std::wstring fn;
bool inside=false;
for(size_t j=i;j<output.size();++j)
{
if( output[j]=='"' && inside==true )
break;
else if(output[j]=='"')
inside=true;
else if( inside==true )
fn+=output[j];
}
output.erase(i,11+fn.size() );
std::wstring ttext=getFileUTF8(ExtractFilePath(file)+"/"+wnarrow(fn) );
transform(ttext);
output.insert(i, ttext );
}
}
//REPLACEMENTS
for( size_t j=0;j<mReplacements.size();++j)
{
if( next(output, i, mReplacements[j].first)==true )
{
output.erase(i, mReplacements[j].first.size() );
output.insert(i, mReplacements[j].second );
i+=mReplacements[j].second.size();
}
}
}
}
}
void CTemplate::Reset(void)
{
delete mValuesRoot;
mCurrValues=new CTable();
mValuesRoot=mCurrValues;
}
void CTemplate::addValueTable( IDatabase* db, const std::string &table)
{
mTables.push_back( std::pair< IDatabase*, IQuery*>(db, db->Prepare("SELECT * FROM "+table+" WHERE key=?",false) ) );
}

39
Template.h Normal file
View File

@ -0,0 +1,39 @@
#include <string>
#include <vector>
#include <map>
#include "Interface/Template.h"
#include "Interface/Table.h"
#include "Interface/Query.h"
class CTemplate : public ITemplate
{
public:
CTemplate(std::string pFile);
~CTemplate();
virtual void Reset(void);
virtual void setValue(std::wstring key, std::wstring value);
virtual ITable* getTable(std::wstring key);
virtual std::string getData(void);
virtual void addValueTable( IDatabase* db, const std::string &table);
private:
void AddDefaultReplacements(void);
bool FindValue(const std::wstring &key, std::wstring &value, bool dbs=false);
ITable *findTable(std::wstring key);
void transform(std::wstring &output);
ITable* createTableRecursive(std::wstring key);
std::wstring data;
std::string file;
std::vector<std::pair<std::wstring, std::wstring> > mReplacements;
ITable* mValuesRoot;
ITable* mCurrValues;
std::vector< std::pair<IDatabase*, IQuery*> > mTables;
};

215
ThreadPool.cpp Normal file
View File

@ -0,0 +1,215 @@
/*************************************************************************
* UrBackup - Client/Server backup system
* Copyright (C) 2011 Martin Raiber
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
**************************************************************************/
#include <boost/bind.hpp>
#include "Interface/Thread.h"
#include "ThreadPool.h"
#include "Server.h"
CPoolThread::CPoolThread(CThreadPool *pMgr)
{
mgr=pMgr;
dexit=false;
}
void CPoolThread::operator()(void)
{
THREADPOOL_TICKET ticket;
IThread *tr=mgr->getRunnable(&ticket, false);
if(tr!=NULL)
(*tr)();
while(dexit==false)
{
IThread *tr=mgr->getRunnable(&ticket, true);
if(tr!=NULL)
(*tr)();
}
mgr->Remove(this);
delete this;
}
void CPoolThread::shutdown(void)
{
dexit=true;
}
IThread * CThreadPool::getRunnable(THREADPOOL_TICKET *todel, bool del)
{
IScopedLock lock(mutex);
if( del==true )
{
--nRunning;
std::map<THREADPOOL_TICKET, ICondition *>::iterator it=running.find(*todel);
if( it!=running.end() )
{
if( it->second!=NULL )
it->second->notify_all();
running.erase(it);
}
}
IThread *ret=NULL;
while(ret==NULL && dexit==false)
{
if( toexecute.size()==0)
cond->wait(&lock);
else
{
ret=toexecute[0].first;
*todel=toexecute[0].second;
toexecute.erase( toexecute.begin() );
}
}
return ret;
}
void CThreadPool::Remove(CPoolThread *pt)
{
IScopedLock lock(mutex);
for(size_t i=0;i<threads.size();++i)
{
if( threads[i]==pt )
{
threads.erase( threads.begin()+i);
return;
}
}
}
CThreadPool::CThreadPool()
{
nRunning=0;
nThreads=0;
currticket=0;
dexit=false;
mutex=Server->createMutex();
cond=Server->createCondition();
}
CThreadPool::~CThreadPool()
{
delete mutex;
delete cond;
}
void CThreadPool::Shutdown(void)
{
IScopedLock lock(mutex);
for(size_t i=0;i<threads.size();++i)
{
threads[i]->shutdown();
}
dexit=true;
unsigned int max=0;
while(threads.size()>0 )
{
lock.relock(NULL);
cond->notify_all();
Server->wait(100);
lock.relock(mutex);
//max 1 sec warten
if( max>=10 )
{
Server->Log("Maximum wait time for thread pool exceeded. Shutting down the hard way", LL_ERROR);
break;
}
++max;
}
}
bool CThreadPool::isRunningInt(THREADPOOL_TICKET ticket)
{
std::map<THREADPOOL_TICKET, ICondition*>::iterator it=running.find(ticket);
if( it!=running.end() )
return true;
else
return false;
}
bool CThreadPool::isRunning(THREADPOOL_TICKET ticket)
{
IScopedLock lock(mutex);
return isRunningInt(ticket);
}
void CThreadPool::waitFor(std::vector<THREADPOOL_TICKET> tickets)
{
IScopedLock lock(mutex);
ICondition *cond=Server->createCondition();
for( size_t i=0;i<tickets.size();++i)
{
std::map<THREADPOOL_TICKET, ICondition*>::iterator it=running.find(tickets[i]);
if( it!=running.end() )
{
it->second=cond;
}
}
while(true)
{
bool r=false;
for(size_t i=0;i<tickets.size();++i)
{
if( isRunningInt(tickets[i])==true )
{
r=true;
break;
}
}
if( r==false )
break;
cond->wait(&lock);
}
Server->destroy(cond);
}
THREADPOOL_TICKET CThreadPool::execute(IThread *runnable)
{
IScopedLock lock(mutex);
if( nThreads-nRunning==0 )
{
CPoolThread *nt=new CPoolThread(this);
Server->createThread(nt);
++nThreads;
threads.push_back(nt);
}
toexecute.push_back(std::pair<IThread*, THREADPOOL_TICKET>(runnable, ++currticket) );
running.insert(std::pair<THREADPOOL_TICKET, ICondition*>(currticket, nullptr) );
++nRunning;
cond->notify_one();
return currticket;
}
void CThreadPool::waitFor(THREADPOOL_TICKET ticket)
{
std::vector<THREADPOOL_TICKET> t;
t.push_back(ticket);
waitFor(t);
}

56
ThreadPool.h Normal file
View File

@ -0,0 +1,56 @@
#include "Interface/Mutex.h"
#include "Interface/Condition.h"
#include "Interface/Thread.h"
#include <deque>
#include "Interface/ThreadPool.h"
class IThread;
class CThreadPool;
class CPoolThread : public IThread
{
public:
CPoolThread(CThreadPool *pMgr);
void operator()(void);
void shutdown(void);
private:
volatile bool dexit;
CThreadPool* mgr;
};
class CThreadPool : public IThreadPool
{
public:
CThreadPool();
~CThreadPool();
THREADPOOL_TICKET execute(IThread *runnable);
bool isRunning(THREADPOOL_TICKET ticket);
void waitFor(std::vector<THREADPOOL_TICKET> tickets);
void waitFor(THREADPOOL_TICKET ticket);
void Remove(CPoolThread *pt);
void Shutdown(void);
IThread * getRunnable(THREADPOOL_TICKET *todel, bool del);
private:
bool isRunningInt(THREADPOOL_TICKET ticket);
unsigned int nThreads;
unsigned int nRunning;
std::vector<CPoolThread*> threads;
std::deque<std::pair<IThread*, THREADPOOL_TICKET> > toexecute;
IMutex* mutex;
ICondition* cond;
std::map<THREADPOOL_TICKET, ICondition*> running;
THREADPOOL_TICKET currticket;
volatile bool dexit;
};

322
WorkerThread.cpp Normal file
View File

@ -0,0 +1,322 @@
/*************************************************************************
* UrBackup - Client/Server backup system
* Copyright (C) 2011 Martin Raiber
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
**************************************************************************/
#include "vld.h"
#include <map>
#include "WorkerThread.h"
#include "Client.h"
#include "Server.h"
#include "libfastcgi/fastcgi.hpp"
#include "SelectThread.h"
#include "stringtools.h"
#include "Interface/File.h"
//#define EXTENSIVE_DEBUGGING
extern std::deque<CClient*> client_queue;
extern IMutex* clients_mutex;
extern ICondition* clients_cond;
CWorkerThread::CWorkerThread(CSelectThread *pMaster)
{
stop_mutex=Server->createMutex();
stop_cond=Server->createCondition();
Master=pMaster;
keep_alive=true;
run=true;
}
CWorkerThread::~CWorkerThread()
{
shutdown();
Server->destroy(stop_cond);
Server->destroy(stop_mutex);
}
void CWorkerThread::shutdown(void)
{
IScopedLock slock(stop_mutex);
Server->Log("waiting for worker...");
run=false;
clients_cond->notify_all();
stop_cond->wait(&slock);
Server->Log("done.");
}
void CWorkerThread::operator()()
{
while(run)
{
size_t nq=0;
IScopedLock lock(clients_mutex);
while(client_queue.size()==0 )
{
clients_cond->wait(&lock);
if(!run)
{
IScopedLock slock(stop_mutex);
stop_cond->notify_one();
return;
}
}
{
while( client_queue.size()>0 )
{
char buffer[WT_BUFFERSIZE];
CClient *client=client_queue[0];
client_queue.erase(client_queue.begin());
SOCKET s=client->getSocket();
clients_mutex->Unlock();
_i32 rc=recv(s, buffer, WT_BUFFERSIZE, MSG_NOSIGNAL);
if( rc<1 )
{
keep_alive=true;
Server->Log("Client disconnected", LL_INFO);
Master->RemoveClient( client );
clients_mutex->Lock();
}
else
{
#ifdef EXTENSIVE_DEBUGGING
std::string lbuf;
for(_i32 i=0;i<rc;++i)
{
if( buffer[i]==0 )
lbuf+='#';
else
lbuf+=buffer[i];
}
Server->Log("Incoming data: "+lbuf, LL_INFO);
#endif
client->lock();
client->getFCGIProtocolDriver()->process_input(buffer, rc);
FCGIRequest* req=client->getFCGIProtocolDriver()->get_request();
client->unlock();
if( req!=NULL )
client->addRequest(req);
while( (req=client->getAndRemoveReadyRequest())!=NULL )
{
Server->addRequest();
client->lock();
ProcessRequest(client, req);
client->unlock();
}
if( keep_alive==false )
{
keep_alive=true;
Server->Log("Client disconnected", LL_INFO);
Master->RemoveClient( client );
}
else
{
client->setProcessing(false);
Master->WakeUp();
}
clients_mutex->Lock();
}
}
}
}
IScopedLock slock(stop_mutex);
stop_cond->notify_one();
}
void CWorkerThread::ProcessRequest(CClient *client, FCGIRequest *req)
{
if( req->keep_connection )
{
keep_alive=true;
}
else
{
keep_alive=false;
}
if( req->role != FCGIRequest::RESPONDER )
{
Server->Log("Role ist not Responder", LL_ERROR);
return;
}
str_map GET,POST;
str_nmap::iterator iter=req->params.find("QUERY_STRING");
if( iter!=req->params.end() )
{
for(size_t i=0,size=iter->second.size();i<size;++i)
{
if( iter->second[i]=='+' )
iter->second[i]=' ';
}
ParseParamStr(iter->second, &GET );
req->params.erase( iter );
}
std::string ct=req->params["CONTENT_TYPE"];
std::string lct=ct;
strlower(lct);
bool postfile=false;
POSTFILE_KEY pfkey;
if(lct.find("multipart/form-data")==std::string::npos)
{
if( req->stdin_stream.size()>0 && req->stdin_stream.size()<1048576 )
{
for(size_t i=0,size=req->stdin_stream.size();i<size;++i)
{
if( req->stdin_stream[i]=='+' )
req->stdin_stream[i]=' ';
}
ParseParamStr(req->stdin_stream, &POST );
}
}
else
{
std::string boundary=getafter("boundary=",ct);
pfkey=ParseMultipartData(req->stdin_stream, boundary);
req->params["POSTFILEKEY"]=nconvert(pfkey);
postfile=true;
}
str_map::iterator iter2=GET.find(L"a");
if( iter2!=GET.end() )
{
int starttime=Server->getTimeMS();
str_map::iterator iter3=GET.find(L"c");
std::wstring context;
if( iter3!=GET.end() )
context=iter3->second;
THREAD_ID tid=Server->Execute(iter2->second, context, GET, POST, req->params, req );
if( tid==0 )
{
std::wstring error=L"Error: Unknown action ["+iter2->second+L"]";
Server->Log(error, LL_WARNING);
req->write("Content-type: text/html; charset=UTF-8\r\n\r\n"+wnarrow(error));
}
starttime=Server->getTimeMS()-starttime;
Server->Log("Execution Time: "+nconvert(starttime)+" ms - time="+nconvert(Server->getTimeMS() ), LL_INFO);
}
else
{
std::string error="Error: Parameter 'action' not given.";
req->write("Content-type: text/html; charset=UTF-8\r\n\r\n"+error);
}
if(postfile)
{
Server->clearPostFiles(pfkey);
}
req->end_request(0, FCGIRequest::REQUEST_COMPLETE);
}
POSTFILE_KEY CWorkerThread::ParseMultipartData(const std::string &data, const std::string &boundary)
{
std::string rboundary="--"+boundary;
int state=0;
std::string key;
std::string value;
std::string filename;
std::string name;
std::string filedata;
std::string contenttype;
size_t start;
POSTFILE_KEY pfilekey=Server->getPostFileKey();
for(size_t i=0;i<data.size();++i)
{
switch(state)
{
case 0:
if(next(data,i,rboundary))
{
i+=rboundary.size()+1;
state=2;
}
break;
case 1:
if(data[i]=='\n' || data[i]=='\r' )
{
if(data[i]=='\n')
{
state=4;
rboundary+="--";
start=i+1;
}
else
break;
}
else
state=1;
case 2:
if(data[i]!=':')
key+=toupper(data[i]);
else
state=3;
break;
case 3:
if(data[i]!='\n' && data[i]!='\r' )
value+=data[i];
else if(data[i]=='\n')
{
if(key=="CONTENT-DISPOSITION")
{
name=getbetween("name=\"","\"", value);
filename=getbetween("filename=\"","\"", value);
}
else if(key=="CONTENT-TYPE")
{
contenttype=value;
}
value.clear();
key.clear();
state=1;
}
break;
case 4:
if(next(data,i,rboundary)==true)
{
IFile *memfile=Server->openMemoryFile();
memfile->Write(data.substr(start,i-start-2) );
memfile->Seek(0);
Server->addPostFile(pfilekey, name, SPostfile(memfile, widen(filename), widen(contenttype)) );
state=0;
rboundary.erase(rboundary.size()-2,2);
i+=rboundary.size()+2;
state=0;
}
}
}
return pfilekey;
}

36
WorkerThread.h Normal file
View File

@ -0,0 +1,36 @@
#include "Interface/Thread.h"
#include "Interface/Mutex.h"
#include "Interface/Condition.h"
#include "types.h"
#include "Interface/Types.h"
#include <deque>
class CClient;
class CSelectThread;
class FCGIRequest;
const _u32 WT_BUFFERSIZE=2000;
class CWorkerThread : public IThread
{
public:
CWorkerThread(CSelectThread *pMaster);
~CWorkerThread();
void operator()();
void shutdown(void);
private:
void ProcessRequest(CClient *client, FCGIRequest *req);
POSTFILE_KEY ParseMultipartData(const std::string &data, const std::string &boundary);
bool keep_alive;
bool run;
CSelectThread* Master;
IMutex* stop_mutex;
ICondition* stop_cond;
};

52
configure.ac Normal file
View File

@ -0,0 +1,52 @@
# -*- Autoconf -*-
# Process this file with autoconf to produce a configure script.
AC_PREREQ(2.61)
AC_INIT([compiled server], [0.1], [urpc@gmx.de])
AC_CONFIG_SRCDIR([AcceptThread.cpp])
AC_CONFIG_HEADER([config.h])
AM_INIT_AUTOMAKE
# Checks for programs.
AC_PROG_CXX
AC_PROG_CC
#AX_BOOST_BASE([1.38.0])
#AX_BOOST_THREAD
#if !($HAVE_BOOST_THREAD)
#then
# echo "Sorry, you need the Thread-Lib from Boost."
# echo "Please install from http://www.boost.org"
# exit 1
#fi
AX_PTHREAD
if !($HAVE_PTHREAD)
then
echo "Sorry, your system needs the pthread library."
echo "Either install it or give up."
exit 1
fi
# Checks for libraries.
# Checks for header files.
AC_HEADER_STDC
AC_CHECK_HEADERS([pthread.h arpa/inet.h fcntl.h netdb.h netinet/in.h stdlib.h sys/socket.h sys/time.h unistd.h])
# Checks for typedefs, structures, and compiler characteristics.
AC_HEADER_STDBOOL
AC_C_CONST
AC_C_INLINE
AC_TYPE_SIZE_T
AC_HEADER_TIME
AC_STRUCT_TM
# Checks for library functions.
AC_FUNC_SELECT_ARGTYPES
AC_FUNC_STRFTIME
AC_CHECK_FUNCS([gettimeofday memset select socket strstr])
AC_CONFIG_FILES([Makefile])
AC_OUTPUT

View File

@ -0,0 +1,80 @@
/*************************************************************************
* UrBackup - Client/Server backup system
* Copyright (C) 2011 Martin Raiber
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
**************************************************************************/
#include "AESDecryption.h"
AESDecryption::AESDecryption(const std::string &password)
{
m_sbbKey.resize(CryptoPP::SHA256::DIGESTSIZE);
CryptoPP::SHA256().CalculateDigest(m_sbbKey, (byte*)password.c_str(), password.size() );
dec=NULL;
}
AESDecryption::~AESDecryption()
{
delete dec;
}
std::string AESDecryption::decrypt(const std::string &data)
{
if(dec==NULL)
{
size_t done=0;
if(!iv_buffer.empty() && iv_buffer.size()+data.size()>=16)
{
CryptoPP::SecByteBlock m_IV;
m_IV.resize(16);
memcpy(m_IV.BytePtr(), &iv_buffer[0], 16);
memcpy(m_IV.BytePtr()+iv_buffer.size(), &data[0], 16-iv_buffer.size());
dec=new CryptoPP::CFB_Mode<CryptoPP::AES>::Decryption(m_sbbKey.begin(),m_sbbKey.size(), m_IV.begin() );
done=16-iv_buffer.size();
}
else if(data.size()>=16)
{
CryptoPP::SecByteBlock m_IV;
m_IV.resize(16);
memcpy(m_IV.BytePtr(), &data[0], 16);
dec=new CryptoPP::CFB_Mode<CryptoPP::AES>::Decryption(m_sbbKey.begin(),m_sbbKey.size(), m_IV.begin() );
done=16;
}
else
{
iv_buffer+=data;
done=data.size();
}
if(done<data.size())
{
std::string ret;
ret.resize(data.size()-done);
dec->ProcessString((byte*)&ret[0], (byte*)&data[done], ret.size() );
return ret;
}
else
{
return "";
}
}
else
{
std::string ret;
ret.resize(data.size());
dec->ProcessString((byte*)&ret[0], (byte*)&data[0], data.size() );
return ret;
}
}

View File

@ -0,0 +1,28 @@
#include <string>
#ifdef _WIN32
#include <aes.h>
#include <sha.h>
#include <modes.h>
#else
#include <crypto++/aes.h>
#include <crypto++/sha.h>
#include <crypto++/modes.h>
#endif
#include "IAESDecryption.h"
class AESDecryption : public IAESDecryption
{
public:
AESDecryption(const std::string &password);
~AESDecryption();
std::string decrypt(const std::string &data);
private:
CryptoPP::SecByteBlock m_sbbKey;
CryptoPP::CFB_Mode<CryptoPP::AES>::Decryption *dec;
std::string iv_buffer;
};

View File

@ -0,0 +1,56 @@
/*************************************************************************
* UrBackup - Client/Server backup system
* Copyright (C) 2011 Martin Raiber
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
**************************************************************************/
#include "AESEncryption.h"
AESEncryption::AESEncryption(const std::string &password)
{
m_sbbKey.resize(CryptoPP::SHA256::DIGESTSIZE);
CryptoPP::SHA256().CalculateDigest(m_sbbKey, (byte*)password.c_str(), password.size() );
m_IV.resize(16);
for(int i=0;i<16;++i)
{
m_IV[i]=rand()%256;
}
iv_done=false;
enc=new CryptoPP::CFB_Mode<CryptoPP::AES>::Encryption(m_sbbKey.begin(),m_sbbKey.size(), m_IV.begin() );
}
AESEncryption::~AESEncryption()
{
delete enc;
}
std::string AESEncryption::encrypt(const std::string &data)
{
std::string ret;
if(iv_done==false)
{
ret.resize(16);
memcpy((char*)ret.c_str(), m_IV.BytePtr(), 16);
}
size_t osize=ret.size();
ret.resize(osize+data.size());
enc->ProcessString((byte*)&ret[osize], (byte*)data.c_str(), data.size() );
return ret;
}

View File

@ -0,0 +1,29 @@
#include <string>
#ifdef _WIN32
#include <aes.h>
#include <sha.h>
#include <modes.h>
#else
#include <crypto++/aes.h>
#include <crypto++/sha.h>
#include <crypto++/modes.h>
#endif
#include "IAESEncryption.h"
class AESEncryption : public IAESEncryption
{
public:
AESEncryption(const std::string &password);
~AESEncryption();
std::string encrypt(const std::string &data);
private:
bool iv_done;
CryptoPP::SecByteBlock m_sbbKey;
CryptoPP::SecByteBlock m_IV;
CryptoPP::CFB_Mode<CryptoPP::AES>::Encryption *enc;
};

0
cryptoplugin/AUTHORS Normal file
View File

674
cryptoplugin/COPYING Normal file
View File

@ -0,0 +1,674 @@
GNU GENERAL PUBLIC LICENSE
Version 3, 29 June 2007
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
Preamble
The GNU General Public License is a free, copyleft license for
software and other kinds of works.
The licenses for most software and other practical works are designed
to take away your freedom to share and change the works. By contrast,
the GNU General Public License is intended to guarantee your freedom to
share and change all versions of a program--to make sure it remains free
software for all its users. We, the Free Software Foundation, use the
GNU General Public License for most of our software; it applies also to
any other work released this way by its authors. You can apply it to
your programs, too.
When we speak of free software, we are referring to freedom, not
price. Our General Public Licenses are designed to make sure that you
have the freedom to distribute copies of free software (and charge for
them if you wish), that you receive source code or can get it if you
want it, that you can change the software or use pieces of it in new
free programs, and that you know you can do these things.
To protect your rights, we need to prevent others from denying you
these rights or asking you to surrender the rights. Therefore, you have
certain responsibilities if you distribute copies of the software, or if
you modify it: responsibilities to respect the freedom of others.
For example, if you distribute copies of such a program, whether
gratis or for a fee, you must pass on to the recipients the same
freedoms that you received. You must make sure that they, too, receive
or can get the source code. And you must show them these terms so they
know their rights.
Developers that use the GNU GPL protect your rights with two steps:
(1) assert copyright on the software, and (2) offer you this License
giving you legal permission to copy, distribute and/or modify it.
For the developers' and authors' protection, the GPL clearly explains
that there is no warranty for this free software. For both users' and
authors' sake, the GPL requires that modified versions be marked as
changed, so that their problems will not be attributed erroneously to
authors of previous versions.
Some devices are designed to deny users access to install or run
modified versions of the software inside them, although the manufacturer
can do so. This is fundamentally incompatible with the aim of
protecting users' freedom to change the software. The systematic
pattern of such abuse occurs in the area of products for individuals to
use, which is precisely where it is most unacceptable. Therefore, we
have designed this version of the GPL to prohibit the practice for those
products. If such problems arise substantially in other domains, we
stand ready to extend this provision to those domains in future versions
of the GPL, as needed to protect the freedom of users.
Finally, every program is threatened constantly by software patents.
States should not allow patents to restrict development and use of
software on general-purpose computers, but in those that do, we wish to
avoid the special danger that patents applied to a free program could
make it effectively proprietary. To prevent this, the GPL assures that
patents cannot be used to render the program non-free.
The precise terms and conditions for copying, distribution and
modification follow.
TERMS AND CONDITIONS
0. Definitions.
"This License" refers to version 3 of the GNU General Public License.
"Copyright" also means copyright-like laws that apply to other kinds of
works, such as semiconductor masks.
"The Program" refers to any copyrightable work licensed under this
License. Each licensee is addressed as "you". "Licensees" and
"recipients" may be individuals or organizations.
To "modify" a work means to copy from or adapt all or part of the work
in a fashion requiring copyright permission, other than the making of an
exact copy. The resulting work is called a "modified version" of the
earlier work or a work "based on" the earlier work.
A "covered work" means either the unmodified Program or a work based
on the Program.
To "propagate" a work means to do anything with it that, without
permission, would make you directly or secondarily liable for
infringement under applicable copyright law, except executing it on a
computer or modifying a private copy. Propagation includes copying,
distribution (with or without modification), making available to the
public, and in some countries other activities as well.
To "convey" a work means any kind of propagation that enables other
parties to make or receive copies. Mere interaction with a user through
a computer network, with no transfer of a copy, is not conveying.
An interactive user interface displays "Appropriate Legal Notices"
to the extent that it includes a convenient and prominently visible
feature that (1) displays an appropriate copyright notice, and (2)
tells the user that there is no warranty for the work (except to the
extent that warranties are provided), that licensees may convey the
work under this License, and how to view a copy of this License. If
the interface presents a list of user commands or options, such as a
menu, a prominent item in the list meets this criterion.
1. Source Code.
The "source code" for a work means the preferred form of the work
for making modifications to it. "Object code" means any non-source
form of a work.
A "Standard Interface" means an interface that either is an official
standard defined by a recognized standards body, or, in the case of
interfaces specified for a particular programming language, one that
is widely used among developers working in that language.
The "System Libraries" of an executable work include anything, other
than the work as a whole, that (a) is included in the normal form of
packaging a Major Component, but which is not part of that Major
Component, and (b) serves only to enable use of the work with that
Major Component, or to implement a Standard Interface for which an
implementation is available to the public in source code form. A
"Major Component", in this context, means a major essential component
(kernel, window system, and so on) of the specific operating system
(if any) on which the executable work runs, or a compiler used to
produce the work, or an object code interpreter used to run it.
The "Corresponding Source" for a work in object code form means all
the source code needed to generate, install, and (for an executable
work) run the object code and to modify the work, including scripts to
control those activities. However, it does not include the work's
System Libraries, or general-purpose tools or generally available free
programs which are used unmodified in performing those activities but
which are not part of the work. For example, Corresponding Source
includes interface definition files associated with source files for
the work, and the source code for shared libraries and dynamically
linked subprograms that the work is specifically designed to require,
such as by intimate data communication or control flow between those
subprograms and other parts of the work.
The Corresponding Source need not include anything that users
can regenerate automatically from other parts of the Corresponding
Source.
The Corresponding Source for a work in source code form is that
same work.
2. Basic Permissions.
All rights granted under this License are granted for the term of
copyright on the Program, and are irrevocable provided the stated
conditions are met. This License explicitly affirms your unlimited
permission to run the unmodified Program. The output from running a
covered work is covered by this License only if the output, given its
content, constitutes a covered work. This License acknowledges your
rights of fair use or other equivalent, as provided by copyright law.
You may make, run and propagate covered works that you do not
convey, without conditions so long as your license otherwise remains
in force. You may convey covered works to others for the sole purpose
of having them make modifications exclusively for you, or provide you
with facilities for running those works, provided that you comply with
the terms of this License in conveying all material for which you do
not control copyright. Those thus making or running the covered works
for you must do so exclusively on your behalf, under your direction
and control, on terms that prohibit them from making any copies of
your copyrighted material outside their relationship with you.
Conveying under any other circumstances is permitted solely under
the conditions stated below. Sublicensing is not allowed; section 10
makes it unnecessary.
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
No covered work shall be deemed part of an effective technological
measure under any applicable law fulfilling obligations under article
11 of the WIPO copyright treaty adopted on 20 December 1996, or
similar laws prohibiting or restricting circumvention of such
measures.
When you convey a covered work, you waive any legal power to forbid
circumvention of technological measures to the extent such circumvention
is effected by exercising rights under this License with respect to
the covered work, and you disclaim any intention to limit operation or
modification of the work as a means of enforcing, against the work's
users, your or third parties' legal rights to forbid circumvention of
technological measures.
4. Conveying Verbatim Copies.
You may convey verbatim copies of the Program's source code as you
receive it, in any medium, provided that you conspicuously and
appropriately publish on each copy an appropriate copyright notice;
keep intact all notices stating that this License and any
non-permissive terms added in accord with section 7 apply to the code;
keep intact all notices of the absence of any warranty; and give all
recipients a copy of this License along with the Program.
You may charge any price or no price for each copy that you convey,
and you may offer support or warranty protection for a fee.
5. Conveying Modified Source Versions.
You may convey a work based on the Program, or the modifications to
produce it from the Program, in the form of source code under the
terms of section 4, provided that you also meet all of these conditions:
a) The work must carry prominent notices stating that you modified
it, and giving a relevant date.
b) The work must carry prominent notices stating that it is
released under this License and any conditions added under section
7. This requirement modifies the requirement in section 4 to
"keep intact all notices".
c) You must license the entire work, as a whole, under this
License to anyone who comes into possession of a copy. This
License will therefore apply, along with any applicable section 7
additional terms, to the whole of the work, and all its parts,
regardless of how they are packaged. This License gives no
permission to license the work in any other way, but it does not
invalidate such permission if you have separately received it.
d) If the work has interactive user interfaces, each must display
Appropriate Legal Notices; however, if the Program has interactive
interfaces that do not display Appropriate Legal Notices, your
work need not make them do so.
A compilation of a covered work with other separate and independent
works, which are not by their nature extensions of the covered work,
and which are not combined with it such as to form a larger program,
in or on a volume of a storage or distribution medium, is called an
"aggregate" if the compilation and its resulting copyright are not
used to limit the access or legal rights of the compilation's users
beyond what the individual works permit. Inclusion of a covered work
in an aggregate does not cause this License to apply to the other
parts of the aggregate.
6. Conveying Non-Source Forms.
You may convey a covered work in object code form under the terms
of sections 4 and 5, provided that you also convey the
machine-readable Corresponding Source under the terms of this License,
in one of these ways:
a) Convey the object code in, or embodied in, a physical product
(including a physical distribution medium), accompanied by the
Corresponding Source fixed on a durable physical medium
customarily used for software interchange.
b) Convey the object code in, or embodied in, a physical product
(including a physical distribution medium), accompanied by a
written offer, valid for at least three years and valid for as
long as you offer spare parts or customer support for that product
model, to give anyone who possesses the object code either (1) a
copy of the Corresponding Source for all the software in the
product that is covered by this License, on a durable physical
medium customarily used for software interchange, for a price no
more than your reasonable cost of physically performing this
conveying of source, or (2) access to copy the
Corresponding Source from a network server at no charge.
c) Convey individual copies of the object code with a copy of the
written offer to provide the Corresponding Source. This
alternative is allowed only occasionally and noncommercially, and
only if you received the object code with such an offer, in accord
with subsection 6b.
d) Convey the object code by offering access from a designated
place (gratis or for a charge), and offer equivalent access to the
Corresponding Source in the same way through the same place at no
further charge. You need not require recipients to copy the
Corresponding Source along with the object code. If the place to
copy the object code is a network server, the Corresponding Source
may be on a different server (operated by you or a third party)
that supports equivalent copying facilities, provided you maintain
clear directions next to the object code saying where to find the
Corresponding Source. Regardless of what server hosts the
Corresponding Source, you remain obligated to ensure that it is
available for as long as needed to satisfy these requirements.
e) Convey the object code using peer-to-peer transmission, provided
you inform other peers where the object code and Corresponding
Source of the work are being offered to the general public at no
charge under subsection 6d.
A separable portion of the object code, whose source code is excluded
from the Corresponding Source as a System Library, need not be
included in conveying the object code work.
A "User Product" is either (1) a "consumer product", which means any
tangible personal property which is normally used for personal, family,
or household purposes, or (2) anything designed or sold for incorporation
into a dwelling. In determining whether a product is a consumer product,
doubtful cases shall be resolved in favor of coverage. For a particular
product received by a particular user, "normally used" refers to a
typical or common use of that class of product, regardless of the status
of the particular user or of the way in which the particular user
actually uses, or expects or is expected to use, the product. A product
is a consumer product regardless of whether the product has substantial
commercial, industrial or non-consumer uses, unless such uses represent
the only significant mode of use of the product.
"Installation Information" for a User Product means any methods,
procedures, authorization keys, or other information required to install
and execute modified versions of a covered work in that User Product from
a modified version of its Corresponding Source. The information must
suffice to ensure that the continued functioning of the modified object
code is in no case prevented or interfered with solely because
modification has been made.
If you convey an object code work under this section in, or with, or
specifically for use in, a User Product, and the conveying occurs as
part of a transaction in which the right of possession and use of the
User Product is transferred to the recipient in perpetuity or for a
fixed term (regardless of how the transaction is characterized), the
Corresponding Source conveyed under this section must be accompanied
by the Installation Information. But this requirement does not apply
if neither you nor any third party retains the ability to install
modified object code on the User Product (for example, the work has
been installed in ROM).
The requirement to provide Installation Information does not include a
requirement to continue to provide support service, warranty, or updates
for a work that has been modified or installed by the recipient, or for
the User Product in which it has been modified or installed. Access to a
network may be denied when the modification itself materially and
adversely affects the operation of the network or violates the rules and
protocols for communication across the network.
Corresponding Source conveyed, and Installation Information provided,
in accord with this section must be in a format that is publicly
documented (and with an implementation available to the public in
source code form), and must require no special password or key for
unpacking, reading or copying.
7. Additional Terms.
"Additional permissions" are terms that supplement the terms of this
License by making exceptions from one or more of its conditions.
Additional permissions that are applicable to the entire Program shall
be treated as though they were included in this License, to the extent
that they are valid under applicable law. If additional permissions
apply only to part of the Program, that part may be used separately
under those permissions, but the entire Program remains governed by
this License without regard to the additional permissions.
When you convey a copy of a covered work, you may at your option
remove any additional permissions from that copy, or from any part of
it. (Additional permissions may be written to require their own
removal in certain cases when you modify the work.) You may place
additional permissions on material, added by you to a covered work,
for which you have or can give appropriate copyright permission.
Notwithstanding any other provision of this License, for material you
add to a covered work, you may (if authorized by the copyright holders of
that material) supplement the terms of this License with terms:
a) Disclaiming warranty or limiting liability differently from the
terms of sections 15 and 16 of this License; or
b) Requiring preservation of specified reasonable legal notices or
author attributions in that material or in the Appropriate Legal
Notices displayed by works containing it; or
c) Prohibiting misrepresentation of the origin of that material, or
requiring that modified versions of such material be marked in
reasonable ways as different from the original version; or
d) Limiting the use for publicity purposes of names of licensors or
authors of the material; or
e) Declining to grant rights under trademark law for use of some
trade names, trademarks, or service marks; or
f) Requiring indemnification of licensors and authors of that
material by anyone who conveys the material (or modified versions of
it) with contractual assumptions of liability to the recipient, for
any liability that these contractual assumptions directly impose on
those licensors and authors.
All other non-permissive additional terms are considered "further
restrictions" within the meaning of section 10. If the Program as you
received it, or any part of it, contains a notice stating that it is
governed by this License along with a term that is a further
restriction, you may remove that term. If a license document contains
a further restriction but permits relicensing or conveying under this
License, you may add to a covered work material governed by the terms
of that license document, provided that the further restriction does
not survive such relicensing or conveying.
If you add terms to a covered work in accord with this section, you
must place, in the relevant source files, a statement of the
additional terms that apply to those files, or a notice indicating
where to find the applicable terms.
Additional terms, permissive or non-permissive, may be stated in the
form of a separately written license, or stated as exceptions;
the above requirements apply either way.
8. Termination.
You may not propagate or modify a covered work except as expressly
provided under this License. Any attempt otherwise to propagate or
modify it is void, and will automatically terminate your rights under
this License (including any patent licenses granted under the third
paragraph of section 11).
However, if you cease all violation of this License, then your
license from a particular copyright holder is reinstated (a)
provisionally, unless and until the copyright holder explicitly and
finally terminates your license, and (b) permanently, if the copyright
holder fails to notify you of the violation by some reasonable means
prior to 60 days after the cessation.
Moreover, your license from a particular copyright holder is
reinstated permanently if the copyright holder notifies you of the
violation by some reasonable means, this is the first time you have
received notice of violation of this License (for any work) from that
copyright holder, and you cure the violation prior to 30 days after
your receipt of the notice.
Termination of your rights under this section does not terminate the
licenses of parties who have received copies or rights from you under
this License. If your rights have been terminated and not permanently
reinstated, you do not qualify to receive new licenses for the same
material under section 10.
9. Acceptance Not Required for Having Copies.
You are not required to accept this License in order to receive or
run a copy of the Program. Ancillary propagation of a covered work
occurring solely as a consequence of using peer-to-peer transmission
to receive a copy likewise does not require acceptance. However,
nothing other than this License grants you permission to propagate or
modify any covered work. These actions infringe copyright if you do
not accept this License. Therefore, by modifying or propagating a
covered work, you indicate your acceptance of this License to do so.
10. Automatic Licensing of Downstream Recipients.
Each time you convey a covered work, the recipient automatically
receives a license from the original licensors, to run, modify and
propagate that work, subject to this License. You are not responsible
for enforcing compliance by third parties with this License.
An "entity transaction" is a transaction transferring control of an
organization, or substantially all assets of one, or subdividing an
organization, or merging organizations. If propagation of a covered
work results from an entity transaction, each party to that
transaction who receives a copy of the work also receives whatever
licenses to the work the party's predecessor in interest had or could
give under the previous paragraph, plus a right to possession of the
Corresponding Source of the work from the predecessor in interest, if
the predecessor has it or can get it with reasonable efforts.
You may not impose any further restrictions on the exercise of the
rights granted or affirmed under this License. For example, you may
not impose a license fee, royalty, or other charge for exercise of
rights granted under this License, and you may not initiate litigation
(including a cross-claim or counterclaim in a lawsuit) alleging that
any patent claim is infringed by making, using, selling, offering for
sale, or importing the Program or any portion of it.
11. Patents.
A "contributor" is a copyright holder who authorizes use under this
License of the Program or a work on which the Program is based. The
work thus licensed is called the contributor's "contributor version".
A contributor's "essential patent claims" are all patent claims
owned or controlled by the contributor, whether already acquired or
hereafter acquired, that would be infringed by some manner, permitted
by this License, of making, using, or selling its contributor version,
but do not include claims that would be infringed only as a
consequence of further modification of the contributor version. For
purposes of this definition, "control" includes the right to grant
patent sublicenses in a manner consistent with the requirements of
this License.
Each contributor grants you a non-exclusive, worldwide, royalty-free
patent license under the contributor's essential patent claims, to
make, use, sell, offer for sale, import and otherwise run, modify and
propagate the contents of its contributor version.
In the following three paragraphs, a "patent license" is any express
agreement or commitment, however denominated, not to enforce a patent
(such as an express permission to practice a patent or covenant not to
sue for patent infringement). To "grant" such a patent license to a
party means to make such an agreement or commitment not to enforce a
patent against the party.
If you convey a covered work, knowingly relying on a patent license,
and the Corresponding Source of the work is not available for anyone
to copy, free of charge and under the terms of this License, through a
publicly available network server or other readily accessible means,
then you must either (1) cause the Corresponding Source to be so
available, or (2) arrange to deprive yourself of the benefit of the
patent license for this particular work, or (3) arrange, in a manner
consistent with the requirements of this License, to extend the patent
license to downstream recipients. "Knowingly relying" means you have
actual knowledge that, but for the patent license, your conveying the
covered work in a country, or your recipient's use of the covered work
in a country, would infringe one or more identifiable patents in that
country that you have reason to believe are valid.
If, pursuant to or in connection with a single transaction or
arrangement, you convey, or propagate by procuring conveyance of, a
covered work, and grant a patent license to some of the parties
receiving the covered work authorizing them to use, propagate, modify
or convey a specific copy of the covered work, then the patent license
you grant is automatically extended to all recipients of the covered
work and works based on it.
A patent license is "discriminatory" if it does not include within
the scope of its coverage, prohibits the exercise of, or is
conditioned on the non-exercise of one or more of the rights that are
specifically granted under this License. You may not convey a covered
work if you are a party to an arrangement with a third party that is
in the business of distributing software, under which you make payment
to the third party based on the extent of your activity of conveying
the work, and under which the third party grants, to any of the
parties who would receive the covered work from you, a discriminatory
patent license (a) in connection with copies of the covered work
conveyed by you (or copies made from those copies), or (b) primarily
for and in connection with specific products or compilations that
contain the covered work, unless you entered into that arrangement,
or that patent license was granted, prior to 28 March 2007.
Nothing in this License shall be construed as excluding or limiting
any implied license or other defenses to infringement that may
otherwise be available to you under applicable patent law.
12. No Surrender of Others' Freedom.
If conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License. If you cannot convey a
covered work so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you may
not convey it at all. For example, if you agree to terms that obligate you
to collect a royalty for further conveying from those to whom you convey
the Program, the only way you could satisfy both those terms and this
License would be to refrain entirely from conveying the Program.
13. Use with the GNU Affero General Public License.
Notwithstanding any other provision of this License, you have
permission to link or combine any covered work with a work licensed
under version 3 of the GNU Affero General Public License into a single
combined work, and to convey the resulting work. The terms of this
License will continue to apply to the part which is the covered work,
but the special requirements of the GNU Affero General Public License,
section 13, concerning interaction through a network will apply to the
combination as such.
14. Revised Versions of this License.
The Free Software Foundation may publish revised and/or new versions of
the GNU General Public License from time to time. Such new versions will
be similar in spirit to the present version, but may differ in detail to
address new problems or concerns.
Each version is given a distinguishing version number. If the
Program specifies that a certain numbered version of the GNU General
Public License "or any later version" applies to it, you have the
option of following the terms and conditions either of that numbered
version or of any later version published by the Free Software
Foundation. If the Program does not specify a version number of the
GNU General Public License, you may choose any version ever published
by the Free Software Foundation.
If the Program specifies that a proxy can decide which future
versions of the GNU General Public License can be used, that proxy's
public statement of acceptance of a version permanently authorizes you
to choose that version for the Program.
Later license versions may give you additional or different
permissions. However, no additional obligations are imposed on any
author or copyright holder as a result of your choosing to follow a
later version.
15. Disclaimer of Warranty.
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
16. Limitation of Liability.
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
SUCH DAMAGES.
17. Interpretation of Sections 15 and 16.
If the disclaimer of warranty and limitation of liability provided
above cannot be given local legal effect according to their terms,
reviewing courts shall apply local law that most closely approximates
an absolute waiver of all civil liability in connection with the
Program, unless a warranty or assumption of liability accompanies a
copy of the Program in return for a fee.
END OF TERMS AND CONDITIONS
How to Apply These Terms to Your New Programs
If you develop a new program, and you want it to be of the greatest
possible use to the public, the best way to achieve this is to make it
free software which everyone can redistribute and change under these terms.
To do so, attach the following notices to the program. It is safest
to attach them to the start of each source file to most effectively
state the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.
<one line to give the program's name and a brief idea of what it does.>
Copyright (C) <year> <name of author>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
Also add information on how to contact you by electronic and paper mail.
If the program does terminal interaction, make it output a short
notice like this when it starts in an interactive mode:
<program> Copyright (C) <year> <name of author>
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.
The hypothetical commands `show w' and `show c' should show the appropriate
parts of the General Public License. Of course, your program's commands
might be different; for a GUI interface, you would use an "about box".
You should also get your employer (if you work as a programmer) or school,
if any, to sign a "copyright disclaimer" for the program, if necessary.
For more information on this, and how to apply and follow the GNU GPL, see
<http://www.gnu.org/licenses/>.
The GNU General Public License does not permit incorporating your program
into proprietary programs. If your program is a subroutine library, you
may consider it more useful to permit linking proprietary applications with
the library. If this is what you want to do, use the GNU Lesser General
Public License instead of this License. But first, please read
<http://www.gnu.org/philosophy/why-not-lgpl.html>.

3
cryptoplugin/ChangeLog Normal file
View File

@ -0,0 +1,3 @@
Please see
http://www.urbackup.org
for Changelog

View File

@ -0,0 +1,118 @@
/*************************************************************************
* UrBackup - Client/Server backup system
* Copyright (C) 2011 Martin Raiber
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
**************************************************************************/
#include "../vld.h"
#include "CryptoFactory.h"
#include "../Interface/Server.h"
#include "../Interface/ThreadPool.h"
#include "AESEncryption.h"
#include "AESDecryption.h"
#ifdef _WIN32
#include <dsa.h>
#include <osrng.h>
#include <files.h>
#else
#include <crypto++/dsa.h>
#include <crypto++/osrng.h>
#include <crypto++/files.h>
#endif
IAESEncryption* CryptoFactory::createAESEncryption(const std::string &password)
{
return new AESEncryption(password);
}
IAESDecryption* CryptoFactory::createAESDecryption(const std::string &password)
{
return new AESDecryption(password);
}
bool CryptoFactory::generatePrivatePublicKeyPair(const std::string &keybasename)
{
CryptoPP::AutoSeededRandomPool rnd;
CryptoPP::DSA::PrivateKey dsaPrivate;
dsaPrivate.GenerateRandomWithKeySize(rnd, 1024);
Server->Log("Calculating public key...", LL_INFO);
CryptoPP::DSA::PublicKey dsaPublic;
dsaPublic.AssignFrom(dsaPrivate);
if (!dsaPrivate.Validate(rnd, 3) || !dsaPublic.Validate(rnd, 3))
{
Server->Log("Validating key pair failed", LL_ERROR);
return false;
}
dsaPrivate.Save(CryptoPP::FileSink((keybasename+".priv").c_str()).Ref());
dsaPublic.Save(CryptoPP::FileSink((keybasename+".pub").c_str()).Ref());
return true;
}
bool CryptoFactory::signFile(const std::string &keyfilename, const std::string &filename, const std::string &sigfilename)
{
CryptoPP::DSA::PrivateKey PrivateKey;
CryptoPP::AutoSeededRandomPool rnd;
try
{
PrivateKey.Load(CryptoPP::FileSource(keyfilename.c_str(), true).Ref());
CryptoPP::DSA::Signer signer( PrivateKey );
CryptoPP::FileSource( filename.c_str(), true,
new CryptoPP::SignerFilter( rnd, signer,
new CryptoPP::FileSink( sigfilename.c_str() )
) // SignerFilter
);
return true;
}
catch(...)
{
Server->Log("Exception occured in CryptoFactory::signFile", LL_ERROR);
}
return false;
}
bool CryptoFactory::verifyFile(const std::string &keyfilename, const std::string &filename, const std::string &sigfilename)
{
CryptoPP::DSA::PublicKey PublicKey;
CryptoPP::AutoSeededRandomPool rnd;
try
{
PublicKey.Load(CryptoPP::FileSource(keyfilename.c_str(), true).Ref());
CryptoPP::DSA::Verifier verifier( PublicKey );
CryptoPP::SignatureVerificationFilter svf(verifier);
CryptoPP::FileSource( sigfilename.c_str(), true, new CryptoPP::Redirector( svf, CryptoPP::Redirector::PASS_WAIT_OBJECTS ) );
CryptoPP::FileSource( filename.c_str(), true, new CryptoPP::Redirector( svf ) );
return svf.GetLastResult();
}
catch(...)
{
Server->Log("Exception occured in CryptoFactory::verifyFile", LL_ERROR);
}
return false;
}

View File

@ -0,0 +1,11 @@
#include "ICryptoFactory.h"
class CryptoFactory : public ICryptoFactory
{
public:
virtual IAESEncryption* createAESEncryption(const std::string &password);
virtual IAESDecryption* createAESDecryption(const std::string &password);
virtual bool generatePrivatePublicKeyPair(const std::string &keybasename);
virtual bool signFile(const std::string &keyfilename, const std::string &filename, const std::string &sigfilename);
virtual bool verifyFile(const std::string &keyfilename, const std::string &filename, const std::string &sigfilename);
};

View File

@ -0,0 +1,14 @@
#ifndef IAESDECRYPTION_H
#define IAESDECRYPTION_H
#include <string>
#include "../Interface/Object.h"
class IAESDecryption : public IObject
{
public:
virtual std::string decrypt(const std::string &data)=0;
};
#endif

View File

@ -0,0 +1,14 @@
#ifndef IAESENCRYPTION_H
#define IAESENCRYPTION_H
#include <string>
#include "../Interface/Object.h"
class IAESEncryption : public IObject
{
public:
virtual std::string encrypt(const std::string &data)=0;
};
#endif

View File

@ -0,0 +1,14 @@
#include <string>
#include "IAESEncryption.h"
#include "IAESDecryption.h"
#include "../Interface/Plugin.h"
class ICryptoFactory: public IPlugin
{
public:
virtual IAESEncryption* createAESEncryption(const std::string &password)=0;
virtual IAESDecryption* createAESDecryption(const std::string &password)=0;
virtual bool generatePrivatePublicKeyPair(const std::string &name)=0;
virtual bool signFile(const std::string &keyfilename, const std::string &filename, const std::string &sigfilename)=0;
virtual bool verifyFile(const std::string &keyfilename, const std::string &filename, const std::string &sigfilename)=0;
};

4
cryptoplugin/Makefile.am Normal file
View File

@ -0,0 +1,4 @@
lib_LTLIBRARIES = libcryptoplugin.la
libcryptoplugin_la_SOURCES = dllmain.cpp AESDecryption.cpp CryptoFactory.cpp pluginmgr.cpp AESEncryption.cpp
AM_CXXFLAGS = -DLINUX
AM_LDFLAGS = -lcrypto++

3
cryptoplugin/NEWS Normal file
View File

@ -0,0 +1,3 @@
Please see
http://www.urbackup.org
for Changelog

Some files were not shown because too many files have changed in this diff Show More