Merge branch 'develop' into '125-Gestión-recolección-y-correlación-de-logs-dev'

# Conflicts:
#   pandora_server/lib/PandoraFMS/Config.pm
This commit is contained in:
Daniel Maya 2017-09-05 10:00:24 +02:00
commit b6c44db3cd
417 changed files with 2310 additions and 30524 deletions

View File

@ -1,36 +0,0 @@
Introduction
------------
Pandora FMS uses a tool called "anytermd" to create a "proxy" between user browser and remote destination. This tool launches as a daemon, listeting in a port, and executing a command, forwarding all output to the user browser.
You need to install the daemon in the server, and execute it.
Installing anytermd
-------------------
Sources are placed in extras/anytermd.
Make sure you have installed gnu c++ compiler (gcc-c++), make, boost-devel and zlib-devel.
Run:
make
Later, install manually the binary to /usr/bin
cp anytermd /usr/bin
Executing anytermd
------------------
To run the server daemons, you need to do manually, Pandora FMS server / console doesn't start up automatically. Pandora FMS SSH/Telnet extension will search for a different instance of anyterd running in 8023 for Telnet connections and 8022 for SSH connections.
Execute it like:
anytermd --port 8023 --user apache -c 'telnet %p'
anytermd --port 8022 --user apache -c 'ssh %p'
Replace "apache" with "httpd" or any other httpd based user your system may have. This will use ports 8023 and 8022, be sure that ports are "open and clear" from the user browser to the console webserver system. No firewalls there.
For more updated install docs, please refer official Pandora FMS documentation.

View File

@ -1,340 +0,0 @@
GNU GENERAL PUBLIC LICENSE
Version 2, June 1991
Copyright (C) 1989, 1991 Free Software Foundation, Inc.
59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
Preamble
The licenses for most software are designed to take away your
freedom to share and change it. By contrast, the GNU General Public
License is intended to guarantee your freedom to share and change free
software--to make sure the software is free for all its users. This
General Public License applies to most of the Free Software
Foundation's software and to any other program whose authors commit to
using it. (Some other Free Software Foundation software is covered by
the GNU Library General Public License instead.) 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
this service 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 make restrictions that forbid
anyone to deny you these rights or to ask you to surrender the rights.
These restrictions translate to certain responsibilities for you if you
distribute copies of the software, or if you modify it.
For example, if you distribute copies of such a program, whether
gratis or for a fee, you must give the recipients all the rights that
you have. 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.
We protect your rights with two steps: (1) copyright the software, and
(2) offer you this license which gives you legal permission to copy,
distribute and/or modify the software.
Also, for each author's protection and ours, we want to make certain
that everyone understands that there is no warranty for this free
software. If the software is modified by someone else and passed on, we
want its recipients to know that what they have is not the original, so
that any problems introduced by others will not reflect on the original
authors' reputations.
Finally, any free program is threatened constantly by software
patents. We wish to avoid the danger that redistributors of a free
program will individually obtain patent licenses, in effect making the
program proprietary. To prevent this, we have made it clear that any
patent must be licensed for everyone's free use or not licensed at all.
The precise terms and conditions for copying, distribution and
modification follow.
GNU GENERAL PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
0. This License applies to any program or other work which contains
a notice placed by the copyright holder saying it may be distributed
under the terms of this General Public License. The "Program", below,
refers to any such program or work, and a "work based on the Program"
means either the Program or any derivative work under copyright law:
that is to say, a work containing the Program or a portion of it,
either verbatim or with modifications and/or translated into another
language. (Hereinafter, translation is included without limitation in
the term "modification".) Each licensee is addressed as "you".
Activities other than copying, distribution and modification are not
covered by this License; they are outside its scope. The act of
running the Program is not restricted, and the output from the Program
is covered only if its contents constitute a work based on the
Program (independent of having been made by running the Program).
Whether that is true depends on what the Program does.
1. You may copy and distribute 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 and disclaimer of warranty; keep intact all the
notices that refer to this License and to the absence of any warranty;
and give any other recipients of the Program a copy of this License
along with the Program.
You may charge a fee for the physical act of transferring a copy, and
you may at your option offer warranty protection in exchange for a fee.
2. You may modify your copy or copies of the Program or any portion
of it, thus forming a work based on the Program, and copy and
distribute such modifications or work under the terms of Section 1
above, provided that you also meet all of these conditions:
a) You must cause the modified files to carry prominent notices
stating that you changed the files and the date of any change.
b) You must cause any work that you distribute or publish, that in
whole or in part contains or is derived from the Program or any
part thereof, to be licensed as a whole at no charge to all third
parties under the terms of this License.
c) If the modified program normally reads commands interactively
when run, you must cause it, when started running for such
interactive use in the most ordinary way, to print or display an
announcement including an appropriate copyright notice and a
notice that there is no warranty (or else, saying that you provide
a warranty) and that users may redistribute the program under
these conditions, and telling the user how to view a copy of this
License. (Exception: if the Program itself is interactive but
does not normally print such an announcement, your work based on
the Program is not required to print an announcement.)
These requirements apply to the modified work as a whole. If
identifiable sections of that work are not derived from the Program,
and can be reasonably considered independent and separate works in
themselves, then this License, and its terms, do not apply to those
sections when you distribute them as separate works. But when you
distribute the same sections as part of a whole which is a work based
on the Program, the distribution of the whole must be on the terms of
this License, whose permissions for other licensees extend to the
entire whole, and thus to each and every part regardless of who wrote it.
Thus, it is not the intent of this section to claim rights or contest
your rights to work written entirely by you; rather, the intent is to
exercise the right to control the distribution of derivative or
collective works based on the Program.
In addition, mere aggregation of another work not based on the Program
with the Program (or with a work based on the Program) on a volume of
a storage or distribution medium does not bring the other work under
the scope of this License.
3. You may copy and distribute the Program (or a work based on it,
under Section 2) in object code or executable form under the terms of
Sections 1 and 2 above provided that you also do one of the following:
a) Accompany it with the complete corresponding machine-readable
source code, which must be distributed under the terms of Sections
1 and 2 above on a medium customarily used for software interchange; or,
b) Accompany it with a written offer, valid for at least three
years, to give any third party, for a charge no more than your
cost of physically performing source distribution, a complete
machine-readable copy of the corresponding source code, to be
distributed under the terms of Sections 1 and 2 above on a medium
customarily used for software interchange; or,
c) Accompany it with the information you received as to the offer
to distribute corresponding source code. (This alternative is
allowed only for noncommercial distribution and only if you
received the program in object code or executable form with such
an offer, in accord with Subsection b above.)
The source code for a work means the preferred form of the work for
making modifications to it. For an executable work, complete source
code means all the source code for all modules it contains, plus any
associated interface definition files, plus the scripts used to
control compilation and installation of the executable. However, as a
special exception, the source code distributed need not include
anything that is normally distributed (in either source or binary
form) with the major components (compiler, kernel, and so on) of the
operating system on which the executable runs, unless that component
itself accompanies the executable.
If distribution of executable or object code is made by offering
access to copy from a designated place, then offering equivalent
access to copy the source code from the same place counts as
distribution of the source code, even though third parties are not
compelled to copy the source along with the object code.
4. You may not copy, modify, sublicense, or distribute the Program
except as expressly provided under this License. Any attempt
otherwise to copy, modify, sublicense or distribute the Program is
void, and will automatically terminate your rights under this License.
However, parties who have received copies, or rights, from you under
this License will not have their licenses terminated so long as such
parties remain in full compliance.
5. You are not required to accept this License, since you have not
signed it. However, nothing else grants you permission to modify or
distribute the Program or its derivative works. These actions are
prohibited by law if you do not accept this License. Therefore, by
modifying or distributing the Program (or any work based on the
Program), you indicate your acceptance of this License to do so, and
all its terms and conditions for copying, distributing or modifying
the Program or works based on it.
6. Each time you redistribute the Program (or any work based on the
Program), the recipient automatically receives a license from the
original licensor to copy, distribute or modify the Program subject to
these terms and conditions. You may not impose any further
restrictions on the recipients' exercise of the rights granted herein.
You are not responsible for enforcing compliance by third parties to
this License.
7. If, as a consequence of a court judgment or allegation of patent
infringement or for any other reason (not limited to patent issues),
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
distribute so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you
may not distribute the Program at all. For example, if a patent
license would not permit royalty-free redistribution of the Program by
all those who receive copies directly or indirectly through you, then
the only way you could satisfy both it and this License would be to
refrain entirely from distribution of the Program.
If any portion of this section is held invalid or unenforceable under
any particular circumstance, the balance of the section is intended to
apply and the section as a whole is intended to apply in other
circumstances.
It is not the purpose of this section to induce you to infringe any
patents or other property right claims or to contest validity of any
such claims; this section has the sole purpose of protecting the
integrity of the free software distribution system, which is
implemented by public license practices. Many people have made
generous contributions to the wide range of software distributed
through that system in reliance on consistent application of that
system; it is up to the author/donor to decide if he or she is willing
to distribute software through any other system and a licensee cannot
impose that choice.
This section is intended to make thoroughly clear what is believed to
be a consequence of the rest of this License.
8. If the distribution and/or use of the Program is restricted in
certain countries either by patents or by copyrighted interfaces, the
original copyright holder who places the Program under this License
may add an explicit geographical distribution limitation excluding
those countries, so that distribution is permitted only in or among
countries not thus excluded. In such case, this License incorporates
the limitation as if written in the body of this License.
9. The Free Software Foundation may publish revised and/or new versions
of the 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 a version number of this License which applies to it and "any
later version", you have the option of following the terms and conditions
either of that version or of any later version published by the Free
Software Foundation. If the Program does not specify a version number of
this License, you may choose any version ever published by the Free Software
Foundation.
10. If you wish to incorporate parts of the Program into other free
programs whose distribution conditions are different, write to the author
to ask for permission. For software which is copyrighted by the Free
Software Foundation, write to the Free Software Foundation; we sometimes
make exceptions for this. Our decision will be guided by the two goals
of preserving the free status of all derivatives of our free software and
of promoting the sharing and reuse of software generally.
NO WARRANTY
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, 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.
12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
REDISTRIBUTE 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.
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
convey 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 2 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, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Also add information on how to contact you by electronic and paper mail.
If the program is interactive, make it output a short notice like this
when it starts in an interactive mode:
Gnomovision version 69, Copyright (C) year name of author
Gnomovision 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, the commands you use may
be called something other than `show w' and `show c'; they could even be
mouse-clicks or menu items--whatever suits your program.
You should also get your employer (if you work as a programmer) or your
school, if any, to sign a "copyright disclaimer" for the program, if
necessary. Here is a sample; alter the names:
Yoyodyne, Inc., hereby disclaims all copyright interest in the program
`Gnomovision' (which makes passes at compilers) written by James Hacker.
<signature of Ty Coon>, 1 April 1989
Ty Coon, President of Vice
This 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 Library General
Public License instead of this License.

View File

@ -1,48 +0,0 @@
# Makefile
# This file is part of Anyterm; see http://anyterm.org/
# (C) 2009 Philip Endecott
# 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 2 of the License, or
# 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, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
# The Makefiles are organised so that you have have multiple build
# directories for different versions of the executable, i.e. debug vs.
# optimised builds, cross-compiled builds etc. This top-level
# Makefile simply invokes make in the default build directory and
# copies the resulting executable to the top level. If you want to
# build variants, create new build directories (e.g. build.debug)
# and copy build/Makefile into them. Make any necessary changes in
# the Makefile copies. These build directory Makefiles include a
# shared common.mk that does most of the work.
EXECUTABLE=anytermd
default_target: ${EXECUTABLE}
${EXECUTABLE}: FORCE
${MAKE} -C build ${EXECUTABLE}
cp build/${EXECUTABLE} $@
clean: FORCE
${MAKE} -C build clean
veryclean: FORCE
${MAKE} -C build veryclean
FORCE:
.PHONY: default_target clean veryclean

View File

@ -1,6 +0,0 @@
This is an special bundle/package for anyterm, prepared to use with Pandora FMS as remote connection system for SSH and Telnet. You cannot use it the "default" anyterm packaged in your system, because it has some modifications.
In order to use it, you need to install from sources or from Pandora FMS project packages. Please read INSTALL to know how to do it.
For more information about anyterm, please check http://anyterm.org/

View File

@ -1,122 +0,0 @@
.TH "anytermd" "1" "1.1.27" "Phil Endecott" ""
.SH "NAME"
.LP
anytermd \- A terminal\-emulating HTTP daemon
.SH "SYNOPSIS"
.LP
anytermd
[\fB\-\-command\fR \fIarg\fP]
[\fB\-\-device\fR \fIarg\fP]
[\fB\-\-port\fR \fIarg\fP]
[\fB\-\-user\fR \fIarg\fP]
[\fB\-\-auth\fR \fIarg\fP]
[\fB\-\-charset\fR \fIarg\fP]
[\fB\-\-foreground\fR]
[\fB\-\-diff\fR]
[\fB\-\-nodiff\fR]
[\fB\-\-max\-sessions\fR \fIarg\fR]
[\fB\-\-max\-http\-connections\fR \fIarg\fR]
[\fB\-\-local\-only\fR]
[\fB\-\-name\fR \fIarg\fR]
.LP
anytermd \-\-help
.SH "DESCRIPTION"
.LP
Anyterm provides a terminal window on a web page, so you can run command-line programs on
a machine even when the only access to it is over HTTP.
.LP
Anyterm consists of some Javascript on a web page, an XmlHttpRequest channel on standard ports
back to the server, an HTTP proxy such as Apache's mod_proxy and the Anyterm daemon. The daemon,
anytermd, uses a pseudo\-terminal to communicate with a shell or other application, and includes
terminal emulation. Key presses are picked up by the Javscript which sends them to the daemon;
changes to the emulated screen are sent from the daemon to the Javascript which updates its
display. Performance is quite reasonable and SSL can be used to secure the connection.
\fIFor security reasons, it is highly recommended that anytermd NOT be exposed directly to
the Internet!\fR See the section \fBSECURITY\fR below.
.SH "OPTIONS"
.LP
Default values are indicated in parentheses ().
.TP
\fB\-c | \-\-command\fR \fIarg\fP (=/bin/bash)
Command to run in terminal
.TP
\fB\-d | \-\-device\fR \fIarg\fP
Device to connect to (e.g. serial port)
.TP
\fB\-p | \-\-port\fR \fIarg\fP (=8080)
Port number to listen on
.TP
\fB\-u | \-\-user\fR \fIarg\fP
User to run as
.TP
\fB\-a | \-\-auth\fR \fIarg\fP (=none)
Authorisation: none|null|trivial
.TP
\fB\-s | \-\-charset\fR \fIarg\fP (=ascii)
Character set
.TP
\fB\-f | \-\-foreground\fR
run in foreground
.TP
\fB\-\-diff\fR
Send only differences to browser
.TP
\fB\-n | \-\-nodiff\fR
Send whole screen to browser each time
.TP
\fB\-m | \-\-max\-sessions\fR \fIarg\fR (=20)
Maximum number of simultaneous sessions
.TP
\fB\-\-max\-http\-connections\fR \fIarg\fR (=unlimited)
Maximum number of simultaneous HTTP connections
.TP
\fB\-\-local\-only\fR
Accept connections only from localhost
.TP
\fB\-\-name\fR \fIarg\fR (=anyterm)
Name used for logging and pid file
.TP
\fB\-\-help\fR
show help message
.SH "SECURITY"
.LP
\fIDo not run anytermd as root.\fR
.LP
Anyterm's code has not been audited for security. It is almost certainly possible to cause it to
crash by sending it invalid input, and experience suggests that this sort of weakness can also be
exploited to allow arbitary code execution.
.LP
Note that all CGI applications and similar programs are subject to this sort of problem, though
some are better written than others. The Anyterm code does not need run with a higher priviledge
level than any other web application, so weaknesses in Anyterm do not put your system at any higher
risk than weaknesses in any other web application would.
.LP
\fIAvoid exposing anytermd directly to the Internet.\fR
.LP
anytermd should be used only as a backend service, reachable only via a frontend HTTPS
proxy, such as Apache, that requires authentication. \fIhttp://anyterm.org/1.1/install.html\fR
gives examples of how to set this up.
.LP
A more complete and up\-to\-date discussion of security issues in anytermd can be found at
\fIhttp://anyterm.org/security.html\fR.
.SH "EXAMPLES"
.LP
If you just want to test Anyterm, you can do:
.LP
anytermd \-\-local\-only
.LP
and then connect to http://localhost:8080 with your Javascript\-enabled web browser. The
brower should display a terminal window containing a bash command prompt owned by the user who
started anytermd.
.LP
If you want to set up SSH\-over\-HTTP access on localhost:8022, you might run it as:
.LP
anytermd \-\-command "/usr/bin/ssh \-o your-username@localhost" \-\-port 8022 \-\-user nobody
\-\-charset utf\-8 \-\-local\-only
.SH "SEE ALSO"
.LP
Anyterm is more fully documented on its web site, \fBhttp://anyterm.org/\fP. The web site
may be more up-to-date than this man page.
.SH "AUTHOR"
.LP
Anyterm is written by Phil Endecott. This man page was contributed by Eric Rossen.

View File

@ -1,55 +0,0 @@
Name: anytermd
Version: 1.1.29
Release: 1.1.29
Summary: Pandora FMS Remote connection gateway
License: GPLv2
Group: Applications/Communications
Vendor: ArticaST <http://www.artica.es>
Source0: %{name}-%{version}.tar.gz
Packager: Sancho Lerena <slerena@artica.es>
BuildRoot: %{_tmppath}/%{name}-%{version}-buildroot
URL: http://pandorafms.org
Requires(post): /sbin/chkconfig
Requires(preun): /sbin/chkconfig
Requires(preun): /sbin/service
Requires(postun): /sbin/service
Requires: telnet openssh-clients
%description
Pandora FMS uses a tool called "anytermd" to create a "proxy" between user browser and remote destination. This tool launches as a daemon, listeting in a port, and executing a command, forwarding all output to the user browser. That means all the connections are done FROM the pandora server and it has to be installed the telnet and ssh client
%prep
rm -rf $RPM_BUILD_ROOT
%setup -q -n anytermd
%build
make
%install
install -Dm 755 contrib/anytermd $RPM_BUILD_ROOT%{_initrddir}/anytermd
install -Dm 755 anytermd $RPM_BUILD_ROOT%{_bindir}/anytermd
%clean
rm -rf $RPM_BUILD_ROOT
%post
if [ $1 -eq 0 ]; then
/sbin/chkconfig --add anytermd
fi
%preun
if [ $1 -eq 0 ]; then
/sbin/chkconfig --del anytermd
fi
%postun
if [ $1 -ge 1 ]; then
/sbin/service anytermd stop >/dev/null 2>&1
fi
%files
%defattr(-,root,root,-)
%{_bindir}/*
%{_initrddir}/anytermd

View File

@ -1,55 +0,0 @@
Name: anytermd
Version: 1.1.29
Release: 1.1.29
Summary: Pandora FMS Remote connection gateway
License: GPLv2
Group: Applications/Communications
Vendor: ArticaST <http://www.artica.es>
Source0: %{name}-%{version}.tar.gz
Packager: Sancho Lerena <slerena@artica.es>
BuildRoot: %{_tmppath}/%{name}-%{version}-buildroot
URL: http://pandorafms.org
Requires(post): /sbin/chkconfig
Requires(preun): /sbin/chkconfig
Requires(preun): /sbin/service
Requires(postun): /sbin/service
Requires: telnet openssh
%description
Pandora FMS uses a tool called "anytermd" to create a "proxy" between user browser and remote destination. This tool launches as a daemon, listeting in a port, and executing a command, forwarding all output to the user browser. That means all the connections are done FROM the pandora server and it has to be installed the telnet and ssh client
%prep
rm -rf $RPM_BUILD_ROOT
%setup -q -n anytermd
%build
make
%install
install -Dm 755 contrib/anytermd $RPM_BUILD_ROOT%{_initrddir}/anytermd
install -Dm 755 anytermd $RPM_BUILD_ROOT%{_bindir}/anytermd
%clean
rm -rf $RPM_BUILD_ROOT
%post
if [ $1 -eq 0 ]; then
/sbin/chkconfig --add anytermd
fi
%preun
if [ $1 -eq 0 ]; then
/sbin/chkconfig --del anytermd
fi
%postun
if [ $1 -ge 1 ]; then
/sbin/service anytermd stop >/dev/null 2>&1
fi
%files
%defattr(-,root,root,-)
%{_bindir}/*
%{_initrddir}/anytermd

View File

@ -1,132 +0,0 @@
/* browser/anyterm.css
This file is part of Anyterm; see http://anyterm.org/
(C) 2005-2008 Philip Endecott
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 2 of the License, or
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, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
/* These are the background colours: */
.a { background-color: #000000; } /* black */
.b { background-color: #cd0000; } /* red */
.c { background-color: #00cd00; } /* green */
.d { background-color: #cdcd00; } /* yellow */
.e { background-color: #0000cd; } /* blue */
.f { background-color: #cd00cd; } /* magenta */
.g { background-color: #00cdcd; } /* cyan */
.h { background-color: #e5e5e5; } /* white */
/* These are the foreground colours used when bold mode is NOT enabled.
They're the same as the background colours. */
.i { color: #000000; } /* black */
.j { color: #cd0000; } /* red */
.k { color: #00cd00; } /* green */
.l { color: #cdcd00; } /* yellow */
.m { color: #0000cd; } /* blue */
.n { color: #cd00cd; } /* magenta */
.o { color: #00cdcd; } /* cyan */
.p { color: #e5e5e5; } /* white */
/* These are the brighter foreground colours used when bold mode IS enabled.
The business with !important and .p .z is because the .p default is set
on the enclosing term element; I can't see a better way to get the desired
behaviour. */
.z.i { color: #4d4d4d !important; } /* black */
.z.j { color: #ff0000 !important; } /* red */
.z.k { color: #00ff00 !important; } /* green */
.z.l { color: #ffff00 !important; } /* yellow */
.z.m { color: #0000ff !important; } /* blue */
.z.n { color: #ff00ff !important; } /* magenta */
.z.o { color: #00ffff !important; } /* cyan */
.z.p, .p .z { color: #ffffff; } /* white */
/* If you want a black-on-white colour scheme like xterm, rather than the
default white-on-black, you need to change the lines for black and white
above to something like the following:
.a { background-color: #ffffff; }
.h { background-color: #000000; }
.i { color: #e5e5e5; }
.p { color: #000000; }
.z.i { color: #ffffff !important; }
.z.p, .p .z { color: #000000; }
*/
/* If the following rule is enabled, bold mode will actually use a bold font.
This is not a good idea in general as the bold font will probably be wider
than the normal font, messing up the layout, at least for some subset of
the character set. So it's commented out; bold characters will be
distinguished only by their brighter colours (above) */
/* .z { font-weight: bold; } */
/* The cursor. You can make it blink if you really want to (on some browsers). */
.cursor {
border: 1px solid red;
margin: -1px;
/*text-decoration: blink;*/
}
/* Properties for the page outside the terminal: */
body {
background-color: white;
/* Don't like the white background? How about this:
background-color: #222222;
*/
}
noscript {
/* This is for the message that users see if they don't have Javascript
enabled. We want it to be visible whatever the page background colour
(above) is set to, so we give it its own background colour. */
color: black;
background-color: white;
}
/* The remaining definitions determine the appearance of the frame around the
terminal, its title bar, and buttons: */
.termframe {
float: left;
padding: 0.2ex;
background-color: none repeat scroll 0% 0% #80BA27;
border-top-right-radius: 5px;
border-top-left-radius: 5px;
}
.termframe p {
margin: 0;
color: white;
font-weight: bold;
font-family: sans-serif;
}
.termframe a {
cursor: pointer;
}
img.button {
margin: 0 3px;
cursor: pointer;
vertical-align: top;
}
.term {
line-height: 17px;
overflow: auto;
overflow-x: visible;
}

View File

@ -1,28 +0,0 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Pandora FMS Remote Gateway</title>
<script type="text/javascript" src="anyterm.js">
</script>
<script type="text/javascript">
var param = get_url_param("param");
window.onload=function() {create_term("term","Pandora FMS Remote Gateway",28,100,param,"",1000);};
function get_url_param( name ) {
var regexS = "[\\?&]"+name+"=([^&#]*)";
var regex = new RegExp( regexS );
var results = regex.exec( window.location.href );
if( results == null )
return "";
else
return results[1];
}
</script>
<link rel="stylesheet" type="text/css" href="anyterm.css">
</head>
<body>
<noscript>Javascript is essential for this page. Please use a browser
that supports Javascript.</noscript>
<div id="term"></div>
</body>
</html>

View File

@ -1,789 +0,0 @@
// browser/anyterm.js
// This file is part of Anyterm; see http://anyterm.org/
// (C) 2005-2006 Philip Endecott
// 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 2 of the License, or
// 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, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
var undefined;
var url_prefix = "";
var frame;
var term;
var open=false;
var session;
var method="POST";
//var method="GET";
// Random sequence numbers are needed to prevent Opera from caching
// replies
var is_opera = navigator.userAgent.toLowerCase().indexOf("opera") != -1;
if (is_opera) {
method="GET";
}
var seqnum_val=Math.round(Math.random()*100000);
function cachebust() {
if (is_opera) {
seqnum_val++;
return "&x="+seqnum_val;
} else {
return "";
}
}
// Cross-platform creation of XMLHttpRequest object:
function new_XMLHttpRequest() {
if (window.XMLHttpRequest) {
// For most browsers:
return new XMLHttpRequest();
} else {
// For IE, it's active-X voodoo.
// There are different versions in different browsers.
// The ones we try are the ones that Sarissa tried. The disabled ones
// apparently also exist, but it seems to work OK without trying them.
//try{ return new ActiveXObject("MSXML3.XMLHTTP"); } catch(e){}
try{ return new ActiveXObject("Msxml2.XMLHTTP.5.0"); } catch(e){}
try{ return new ActiveXObject("Msxml2.XMLHTTP.4.0"); } catch(e){}
try{ return new ActiveXObject("MSXML2.XMLHTTP.3.0"); } catch(e){}
try{ return new ActiveXObject("MSXML2.XMLHTTP"); } catch(e){}
//try{ return new ActiveXObject("Msxml2.XMLHTTP"); } catch(e){}
try{ return new ActiveXObject("Microsoft.XMLHTTP"); } catch(e){}
throw new Error("Could not find an XMLHttpRequest active-X class.")
}
}
// Asynchronous and Synchronous XmlHttpRequest wrappers
// AsyncLoader is a class; an instance specifies a callback function.
// Call load to get something and the callback is invoked with the
// returned document.
function AsyncLoader(cb) {
this.callback = cb;
this.load = function (url,query) {
var xmlhttp = new_XMLHttpRequest();
var cbk = this.callback;
//var timeoutID = window.setTimeout("alert('No response after 20 secs')",20000);
xmlhttp.onreadystatechange = function () {
if (xmlhttp.readyState==4) {
//window.clearTimeout(timeoutID);
if (xmlhttp.status==200) {
cbk(xmlhttp.responseText);
} else {
alert("Server returned status code "+xmlhttp.status+":\n"+xmlhttp.statusText);
cbk(null);
}
}
}
if (method=="GET") {
xmlhttp.open(method, url+"?"+query, true);
xmlhttp.send(null);
} else if (method=="POST") {
xmlhttp.open(method, url, true);
xmlhttp.setRequestHeader('Content-Type',
'application/x-www-form-urlencoded');
xmlhttp.send(query);
}
}
}
// Synchronous loader is a simple function
function sync_load(url,query) {
var xmlhttp = new_XMLHttpRequest();
if (method=="GET") {
xmlhttp.open(method, url+"?"+query, false);
xmlhttp.send(null);
} else if (method=="POST") {
xmlhttp.open(method, url, false);
xmlhttp.setRequestHeader('Foo','1234');
xmlhttp.setRequestHeader('Content-Type',
'application/x-www-form-urlencoded');
xmlhttp.send(query);
}
if (xmlhttp.status!=200) {
alert("Server returned status code "+xmlhttp.status+":\n"+xmlhttp.statusText);
return null;
}
return xmlhttp.responseText;
}
// Process error message from server:
function handle_resp_error(resp) {
if (resp.charAt(0)=="E") {
var msg = resp.substr(1);
alert(msg);
return true;
}
return false;
}
// Receive channel:
var rcv_loader;
var disp="";
function process_editscript(edscr) {
var ndisp="";
var i=0;
var dp=0;
while (i<edscr.length) {
var cmd=edscr.charAt(i);
i++;
var cp=edscr.indexOf(":",i);
var num=Number(edscr.substr(i,cp-i));
i=cp+1;
//alert("cmd="+cmd+" num="+num);
if (cmd=="d") {
dp+=num;
} else if (cmd=="k") {
ndisp+=disp.substr(dp,num);
dp+=num;
} else if (cmd=="i") {
//if (edscr.length<i+num) {
//alert("edit script ended early; expecting "+num+" but got only "+edscr.length-cp);
//}
ndisp+=edscr.substr(i,num);
i+=num;
}
}
return ndisp;
}
var visible_height_frac = 1;
function display(edscr) {
//alert(edscr);
var ndisp;
if (edscr=="n") {
return;
} else if (edscr.charAt(0)=="R") {
ndisp = edscr.substr(1);
} else {
ndisp = process_editscript(edscr);
}
disp=ndisp;
term.innerHTML=ndisp;
if (visible_height_frac != 1) {
var termheight = visible_height_frac * term.scrollHeight;
term.style.height = termheight+"px";
term.scrollTop = term.scrollHeight;
}
}
function scrollterm(pages) {
term.scrollTop += pages * visible_height_frac * term.scrollHeight;
}
var rcv_timeout;
function get() {
//alert("get");
rcv_loader.load(url_prefix+"anyterm-module","a=rcv&s="+session+cachebust());
rcv_timeout = window.setTimeout("alert('no response from server after 60 secs')",60000);
}
function rcv(resp) {
// Called asynchronously when the received document has returned
// from the server.
window.clearTimeout(rcv_timeout);
if (!open) {
return;
}
if (resp=="") {
// We seem to get this if the connection to the server fails.
alert("Connection to server failed");
return;
}
if (handle_resp_error(resp)) {
return;
}
display(resp);
get();
}
rcv_loader = new AsyncLoader(rcv);
// Transmit channel:
var kb_buf="";
var send_loader;
var send_in_progress=false;
function send() {
send_in_progress=true;
send_loader.load(url_prefix+"anyterm-module",
"a=send&s="+session+cachebust()+"&k="+encodeURIComponent(kb_buf));
kb_buf="";
}
function send_done(resp) {
send_in_progress=false;
if (handle_resp_error(resp)) {
return;
}
if (kb_buf!="") {
send();
}
}
send_loader = new AsyncLoader(send_done);
function maybe_send() {
if (!send_in_progress && open && kb_buf!="") {
send();
}
}
function process_key(k) {
// alert("key="+k);
// return;
kb_buf+=k;
maybe_send();
}
function esc_seq(s) {
return String.fromCharCode(27)+"["+s;
}
function key_ev_stop(ev) {
// We want this key event to do absolutely nothing else.
ev.cancelBubble=true;
if (ev.stopPropagation) ev.stopPropagation();
if (ev.preventDefault) ev.preventDefault();
try { ev.keyCode=0; } catch(e){}
}
function key_ev_supress(ev) {
// We want this keydown event to become a keypress event, but nothing else.
ev.cancelBubble=true;
if (ev.stopPropagation) ev.stopPropagation();
}
// When a key is pressed the browser delivers several events: typically first a keydown
// event, then a keypress event, then a keyup event. Ideally we'd just use the keypress
// event, but there's a problem with that: the browser may not send a keypress event for
// unusual keys such as function keys, control keys, cursor keys and so on. The exact
// behaviour varies between browsers and probably versions of browsers.
//
// So to get these keys we need to get the keydown events. They have a couple of
// problems. Firstly, you get these events for things like pressing the shift key.
// Secondly, unlike keypress events you don't get auto-repeat.
function keypress(ev) {
if (!ev) var ev=window.event;
// Only handle "safe" characters here. Anything unusual is ignored; it would
// have been handled earlier by the keydown function below.
if ((ev.ctrlKey && !ev.altKey) // Ctrl is pressed (but not altgr, which is reported
// as ctrl+alt in at least some browsers).
|| (ev.which==0) // there's no key in the event; maybe a shift key?
// (Mozilla sends which==0 && keyCode==0 when you press
// the 'windows logo' key.)
|| (ev.keyCode==8) // backspace
|| (ev.keyCode==16)) { // shift; Opera sends this.
key_ev_stop(ev);
return false;
}
var kc;
if (ev.keyCode) kc=ev.keyCode;
if (ev.which) kc=ev.which;
var k=String.fromCharCode(kc);
// When a key is pressed with ALT, we send ESC followed by the key's normal
// code. But we don't want to do this when ALT-GR is pressed.
if (ev.altKey && !ev.ctrlKey) {
k = String.fromCharCode(27)+k;
}
// alert("keypress keyCode="+ev.keyCode+" which="+ev.which+
// " shiftKey="+ev.shiftKey+" ctrlKey="+ev.ctrlKey+" altKey="+ev.altKey);
process_key(k);
key_ev_stop(ev);
return false;
}
function keydown(ev) {
if (!ev) var ev=window.event;
// alert("keydown keyCode="+ev.keyCode+" which="+ev.which+
// " shiftKey="+ev.shiftKey+" ctrlKey="+ev.ctrlKey+" altKey="+ev.altKey);
var k;
var kc=ev.keyCode;
// Handle special keys. We do this here because IE doesn't send
// keypress events for these (or at least some versions of IE don't for
// at least many of them). This is unfortunate as it means that the
// cursor keys don't auto-repeat, even in browsers where that would be
// possible. That could be improved.
// Interpret shift-pageup/down locally
if (ev.shiftKey && kc==33) { scrollterm(-0.5); key_ev_stop(ev); return false; }
else if (ev.shiftKey && kc==34) { scrollterm(0.5); key_ev_stop(ev); return false; }
else if (kc==33) k=esc_seq("5~"); // PgUp
else if (kc==34) k=esc_seq("6~"); // PgDn
else if (kc==35) k=esc_seq("4~"); // End
else if (kc==36) k=esc_seq("1~"); // Home
else if (kc==37) k=esc_seq("D"); // Left
else if (kc==38) k=esc_seq("A"); // Up
else if (kc==39) k=esc_seq("C"); // Right
else if (kc==40) k=esc_seq("B"); // Down
else if (kc==45) k=esc_seq("2~"); // Ins
else if (kc==46) k=esc_seq("3~"); // Del
else if (kc==27) k=String.fromCharCode(27); // Escape
else if (kc==9) k=String.fromCharCode(9); // Tab
else if (kc==8) k=String.fromCharCode(8); // Backspace
else if (kc==112) k=esc_seq(ev.shiftKey ? "25~" : "[A"); // F1
else if (kc==113) k=esc_seq(ev.shiftKey ? "26~" : "[B"); // F2
else if (kc==114) k=esc_seq(ev.shiftKey ? "28~" : "[C"); // F3
else if (kc==115) k=esc_seq(ev.shiftKey ? "29~" : "[D"); // F4
else if (kc==116) k=esc_seq(ev.shiftKey ? "31~" : "[E"); // F5
else if (kc==117) k=esc_seq(ev.shiftKey ? "32~" : "17~"); // F6
else if (kc==118) k=esc_seq(ev.shiftKey ? "33~" : "18~"); // F7
else if (kc==119) k=esc_seq(ev.shiftKey ? "34~" : "19~"); // F8
else if (kc==120) k=esc_seq("20~"); // F9
else if (kc==121) k=esc_seq("21~"); // F10
else if (kc==122) k=esc_seq("23~"); // F11
else if (kc==123) k=esc_seq("24~"); // F12
else {
// For most keys we'll stop now and let the subsequent keypress event
// process the key. This has the advantage that auto-repeat will work.
// But we'll carry on here for control keys.
// Note that when altgr is pressed, the event reports ctrl and alt being
// pressed because it doesn't have a separate field for altgr. We'll
// handle altgr in the keypress handler.
if (!ev.ctrlKey // ctrl not pressed
|| (ev.ctrlKey && ev.altKey) // altgr pressed
|| (ev.keyCode==17)) { // I think that if you press shift-control,
// you'll get an event with !ctrlKey && keyCode==17.
key_ev_supress(ev);
return; // Note that we don't "return false" here, as we want the
// keypress handler to be invoked.
}
// OK, so now we're handling a ctrl key combination.
// There are some assumptions below about whether these symbols are shifted
// or not; does this work with different keyboards?
if (ev.shiftKey) {
if (kc==50) k=String.fromCharCode(0); // Ctrl-@
else if (kc==54) k=String.fromCharCode(30); // Ctrl-^, doesn't work
else if (kc==94) k=String.fromCharCode(30); // Ctrl-^, doesn't work
else if (kc==109) k=String.fromCharCode(31); // Ctrl-_
else {
key_ev_supress(ev);
return;
}
} else {
if (kc>=65 && kc<=90) k=String.fromCharCode(kc-64); // Ctrl-A..Z
else if (kc==219) k=String.fromCharCode(27); // Ctrl-[
else if (kc==220) k=String.fromCharCode(28); // Ctrl-\ .
else if (kc==221) k=String.fromCharCode(29); // Ctrl-]
else if (kc==190) k=String.fromCharCode(30); // Since ctrl-^ doesn't work, map
// ctrl-. to its code.
else if (kc==32) k=String.fromCharCode(0); // Ctrl-space sends 0, like ctrl-@.
else {
key_ev_supress(ev);
return;
}
}
}
// alert("keydown keyCode="+ev.keyCode+" which="+ev.which+
// " shiftKey="+ev.shiftKey+" ctrlKey="+ev.ctrlKey+" altKey="+ev.altKey);
process_key(k);
key_ev_stop(ev);
return false;
}
// Open, close and initialisation:
function open_term(rows,cols,p,charset,scrollback) {
var params = "a=open&rows="+rows+"&cols="+cols;
if (p) {
params += "&p="+p;
}
if (charset) {
params += "&ch="+charset;
}
if (scrollback) {
if (scrollback>1000) {
alert("The maximum scrollback is currently limited to 1000 lines. "
+"Please choose a smaller value and try again.");
return;
}
params += "&sb="+scrollback;
}
params += cachebust();
var resp = sync_load(url_prefix+"anyterm-module",params);
if (handle_resp_error(resp)) {
return;
}
open=true;
session=resp;
}
function close_term() {
if (!open) {
alert("Connection is not open");
return;
}
open=false;
var resp = sync_load(url_prefix+"anyterm-module","a=close&s="+session+cachebust());
handle_resp_error(resp); // If we get an error, we still close everything.
document.onkeypress=null;
document.onkeydown=null;
window.onbeforeunload=null;
var e;
while (e=frame.firstChild) {
frame.removeChild(e);
}
frame.className="";
if (on_close_goto_url) {
document.location = on_close_goto_url;
}
}
function get_anyterm_version() {
var svn_url="$URL: file:///var/lib/svn/anyterm/tags/releases/1.1/1.1.29/browser/anyterm.js $";
var re = /releases\/[0-9]+\.[0-9]+\/([0-9\.]+)/;
var match = re.exec(svn_url);
if (match) {
return match[1];
} else {
return "";
}
}
function substitute_variables(s) {
var version = get_anyterm_version();
if (version!="") {
version="-"+version;
}
var hostname=document.location.host;
return s.replace(/%v/g,version).replace(/%h/g,hostname);
}
// Copying
function copy_ie_clipboard() {
try {
window.document.execCommand("copy",false,null);
} catch (err) {
return undefined;
}
return 1;
}
function copy_mozilla_clipboard() {
// Thanks to Simon Wissinger for this function.
try {
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
} catch (err) {
return undefined;
}
var sel=window.getSelection();
var copytext=sel.toString();
var str=Components.classes["@mozilla.org/supports-string;1"]
.createInstance(Components.interfaces.nsISupportsString);
if (!str) return undefined;
str.data=copytext;
var trans=Components.classes["@mozilla.org/widget/transferable;1"]
.createInstance(Components.interfaces.nsITransferable);
if (!trans) return undefined;
trans.addDataFlavor("text/unicode");
trans.setTransferData("text/unicode", str, copytext.length * 2);
var clipid=Components.interfaces.nsIClipboard;
var clip=Components.classes["@mozilla.org/widget/clipboard;1"].getService(clipid);
if (!clip) return undefined;
clip.setData(trans, null, clipid.kGlobalClipboard);
return 1;
}
function copy_to_clipboard() {
var r=copy_ie_clipboard();
if (r==undefined) {
r=copy_mozilla_clipboard();
}
if (r==undefined) {
alert("Copy seems to be disabled; maybe you need to change your security settings?"
+"\n(Copy on the Edit menu will probably work)");
}
}
// Pasting
function get_mozilla_clipboard() {
// This function is taken from
// http://www.nomorepasting.com/paste.php?action=getpaste&pasteID=41974&PHPSESSID=e6565dcf5de07256345e562b97ac9f46
// which does not indicate any particular copyright conditions. It
// is a public forum, so one might conclude that it is public
// domain.
// IMHO it's disgraceful that Mozilla makes us use these 30 lines of
// undocumented gobledegook to do what IE does, and documents, with
// just 'window.clipboardData.getData("Text")'. What on earth were
// they thinking?
try {
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
} catch (err) {
return undefined;
}
var clip = Components.classes["@mozilla.org/widget/clipboard;1"]
.createInstance(Components.interfaces.nsIClipboard);
if (!clip) {
return undefined;
}
var trans = Components.classes["@mozilla.org/widget/transferable;1"]
.createInstance(Components.interfaces.nsITransferable);
if (!trans) {
return undefined;
}
trans.addDataFlavor("text/unicode");
clip.getData(trans,clip.kGlobalClipboard);
var str=new Object();
var strLength=new Object();
try {
trans.getTransferData("text/unicode",str,strLength);
} catch(err) {
// One reason for getting here seems to be that nothing is selected
return "";
}
if (str) {
str=str.value.QueryInterface(Components.interfaces.nsISupportsString);
}
if (str) {
return str.data.substring(0,strLength.value / 2);
} else {
return ""; // ? is this "clipboard empty" or "cannot access"?
}
}
function get_ie_clipboard() {
if (window.clipboardData) {
return window.clipboardData.getData("Text");
}
return undefined;
}
function get_default_clipboard() {
return prompt("Paste into this box and press OK:","");
}
function paste_from_clipboard() {
var p = get_ie_clipboard();
if (p==undefined) {
p = get_mozilla_clipboard();
}
if (p==undefined) {
p = get_default_clipboard();
if (p) {
process_key(p);
}
return;
}
if (p=="") {
alert("The clipboard seems to be empty");
return;
}
if (confirm('Click OK to "type" the following into the terminal:\n'+p)) {
process_key(p);
}
}
function create_button(label,fn) {
var button=document.createElement("A");
var button_t=document.createTextNode("["+label+"] ");
button.appendChild(button_t);
button.onclick=fn;
return button;
}
function create_img_button(imgfn,label,fn) {
var button=document.createElement("A");
var button_img=document.createElement("IMG");
var class_attr=document.createAttribute("CLASS");
class_attr.value="button";
button_img.setAttributeNode(class_attr);
var src_attr=document.createAttribute("SRC");
src_attr.value=imgfn;
button_img.setAttributeNode(src_attr);
var alt_attr=document.createAttribute("ALT");
alt_attr.value="["+label+"] ";
button_img.setAttributeNode(alt_attr);
var title_attr=document.createAttribute("TITLE");
title_attr.value=label;
button_img.setAttributeNode(title_attr);
button.appendChild(button_img);
button.onclick=fn;
return button;
}
function create_term(elem_id,title,rows,cols,p,charset,scrollback) {
if (open) {
alert("Terminal is already open");
return;
}
title=substitute_variables(title);
frame=document.getElementById(elem_id);
if (!frame) {
alert("There is no element named '"+elem_id+"' in which to build a terminal");
return;
}
frame.className="termframe";
var title_p=document.createElement("P");
title_p.appendChild(create_img_button("copy.gif","Copy",copy_to_clipboard));
title_p.appendChild(create_img_button("paste.gif","Paste",paste_from_clipboard));
title_p.appendChild(create_ctrlkey_menu());
var title_t=document.createTextNode(" "+title+" ");
title_p.appendChild(title_t);
// title_p.appendChild(create_button("close",close_term));
frame.appendChild(title_p);
term=document.createElement("PRE");
frame.appendChild(term);
term.className="term a p";
var termbody=document.createTextNode("");
term.appendChild(termbody);
visible_height_frac=Number(rows)/(Number(rows)+Number(scrollback));
if (scrollback>0) {
term.style.overflowY="scroll";
}
document.onhelp = function() { return false; };
document.onkeypress=keypress;
document.onkeydown=keydown;
open_term(rows,cols,p,charset,scrollback);
if (open) {
window.onbeforeunload=warn_unload;
get();
maybe_send();
}
}
function warn_unload() {
if (open) {
return "Leaving this page will close the terminal.";
}
}
function create_ctrlkey_menu() {
var sel=document.createElement("SELECT");
create_ctrlkey_menu_entry(sel,"Control keys...",-1);
create_ctrlkey_menu_entry(sel,"Ctrl-@",0);
for (var code=1; code<27; code++) {
var letter=String.fromCharCode(64+code);
create_ctrlkey_menu_entry(sel,"Ctrl-"+letter,code);
}
create_ctrlkey_menu_entry(sel,"Ctrl-[",27);
create_ctrlkey_menu_entry(sel,"Ctrl-\\",28);
create_ctrlkey_menu_entry(sel,"Ctrl-]",29);
create_ctrlkey_menu_entry(sel,"Ctrl-^",30);
create_ctrlkey_menu_entry(sel,"Ctrl-_",31);
sel.onchange=function() {
var code = sel.options[sel.selectedIndex].value;
if (code>=0) {
process_key(String.fromCharCode(code));
}
};
return sel;
}
function create_ctrlkey_menu_entry(sel,name,code) {
var opt=document.createElement("OPTION");
opt.appendChild(document.createTextNode(name));
var value_attr=document.createAttribute("VALUE");
value_attr.value=code;
opt.setAttributeNode(value_attr);
sel.appendChild(opt);
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 911 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 232 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 148 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 225 B

View File

@ -1,5 +0,0 @@
Activity.d ../src/Activity.o: ../src/Activity.cc ../src/Activity.hh \
../libpbe/include/FileDescriptor.hh ../libpbe/include/Exception.hh \
../libpbe/include/missing_syscalls.hh \
../libpbe/include/compiler_magic.hh ../libpbe/include/Thread.hh \
../libpbe/include/select.hh ../libpbe/include/Exception.hh

View File

@ -1,17 +0,0 @@
Anyterm.d ../src/Anyterm.o: ../src/Anyterm.cc ../src/Anyterm.hh \
../libpbe/include/Locked.hh ../libpbe/include/Mutex.hh \
../libpbe/include/atomic.hh ../libpbe/include/Lock.hh \
../libpbe/include/Exception.hh ../libpbe/include/Futex.hh \
../libpbe/include/missing_syscalls.hh ../src/Session.hh \
../src/SessionId.hh ../libpbe/include/Mutex.hh \
../libpbe/include/Condition.hh ../libpbe/include/HPtime.hh \
../libpbe/include/Unlock.hh ../src/Screen.hh ../src/Cell.hh \
../src/Attributes.hh ../src/unicode.hh ../libpbe/include/endian.hh \
../src/Terminal.hh ../libpbe/include/Iconver.hh ../src/Activity.hh \
../libpbe/include/FileDescriptor.hh ../libpbe/include/compiler_magic.hh \
../libpbe/include/Thread.hh ../src/config.hh \
../libpbe/include/HttpRequest.hh ../libpbe/include/URI.hh \
../src/Error.hh ../src/auto_CgiParams.hh ../src/CgiParams.hh \
../src/SubProcess.hh ../src/SerialPortActivity.hh \
../libpbe/include/SerialPort.hh ../libpbe/include/FileDescriptor.hh \
../src/expand_command.hh ../libpbe/include/compiler_magic.hh

View File

@ -1,21 +0,0 @@
AnytermDaemon.d ../src/AnytermDaemon.o: ../src/AnytermDaemon.cc \
../src/AnytermDaemon.hh ../libpbe/include/HttpDaemon.hh \
../libpbe/include/Daemon.hh ../libpbe/include/FileDescriptor.hh \
../libpbe/include/Exception.hh ../libpbe/include/missing_syscalls.hh \
../libpbe/include/compiler_magic.hh ../libpbe/include/Mutex.hh \
../libpbe/include/atomic.hh ../libpbe/include/Lock.hh \
../libpbe/include/Futex.hh ../libpbe/include/Condition.hh \
../libpbe/include/HPtime.hh ../libpbe/include/Unlock.hh \
../libpbe/include/HttpRequest.hh ../libpbe/include/URI.hh \
../libpbe/include/HttpResponse.hh ../libpbe/include/HttpAuthenticator.hh \
../libpbe/include/HttpRequest.hh ../libpbe/include/HttpResponse.hh \
../src/Anyterm.hh ../libpbe/include/Locked.hh ../src/Session.hh \
../src/SessionId.hh ../libpbe/include/Mutex.hh \
../libpbe/include/Condition.hh ../src/Screen.hh ../src/Cell.hh \
../src/Attributes.hh ../src/unicode.hh ../libpbe/include/endian.hh \
../src/Terminal.hh ../libpbe/include/Iconver.hh ../src/Activity.hh \
../libpbe/include/FileDescriptor.hh ../libpbe/include/Thread.hh \
../src/config.hh ../src/NullAuthenticator.hh \
../libpbe/include/HttpAuthenticator.hh \
../libpbe/include/compiler_magic.hh ../src/TrivialAuthenticator.hh \
../src/static_content.hh ../libpbe/include/segv_backtrace.hh

View File

@ -1,31 +0,0 @@
# build/Makefile
# This file is part of Anyterm; see http://anyterm.org/
# (C) 2009 Philip Endecott
# 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 2 of the License, or
# 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, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
# The Makefiles are aranged so that you can have multiple build
# directories for different build variants e.g. with or without
# debugging etc. Each build directory's Makefile should just set
# any necessary variables and then include ../common.mk, which does
# all of the work.
DEBUG_FLAGS=
OPTIMISE_FLAGS=-O
include ../common.mk

View File

@ -1,7 +0,0 @@
SerialPort.d ../src/SerialPort.o: ../src/SerialPort.cc \
../src/SerialPortActivity.hh ../src/Activity.hh \
../libpbe/include/FileDescriptor.hh ../libpbe/include/Exception.hh \
../libpbe/include/missing_syscalls.hh \
../libpbe/include/compiler_magic.hh ../libpbe/include/Thread.hh \
../libpbe/include/SerialPort.hh ../libpbe/include/FileDescriptor.hh \
../libpbe/include/select.hh ../libpbe/include/Exception.hh

View File

@ -1,12 +0,0 @@
Session.d ../src/Session.o: ../src/Session.cc ../src/Session.hh \
../src/SessionId.hh ../libpbe/include/Mutex.hh \
../libpbe/include/atomic.hh ../libpbe/include/Lock.hh \
../libpbe/include/Exception.hh ../libpbe/include/Futex.hh \
../libpbe/include/missing_syscalls.hh ../libpbe/include/Condition.hh \
../libpbe/include/HPtime.hh ../libpbe/include/Unlock.hh ../src/Screen.hh \
../src/Cell.hh ../src/Attributes.hh ../src/unicode.hh \
../libpbe/include/endian.hh ../src/Terminal.hh \
../libpbe/include/Iconver.hh ../src/Activity.hh \
../libpbe/include/FileDescriptor.hh ../libpbe/include/compiler_magic.hh \
../libpbe/include/Thread.hh ../libpbe/include/Lock.hh ../src/config.hh \
../src/html.hh ../src/editscript.hh ../src/Error.hh

View File

@ -1 +0,0 @@
SessionId.d ../src/SessionId.o: ../src/SessionId.cc ../src/SessionId.hh

View File

@ -1,6 +0,0 @@
SubProcess.d ../src/SubProcess.o: ../src/SubProcess.cc \
../src/SubProcess.hh ../src/Activity.hh \
../libpbe/include/FileDescriptor.hh ../libpbe/include/Exception.hh \
../libpbe/include/missing_syscalls.hh \
../libpbe/include/compiler_magic.hh ../libpbe/include/Thread.hh \
../libpbe/include/select.hh ../libpbe/include/Exception.hh

View File

@ -1,5 +0,0 @@
Terminal.d ../src/Terminal.o: ../src/Terminal.cc ../src/Terminal.hh \
../src/Cell.hh ../src/Attributes.hh ../src/unicode.hh \
../libpbe/include/endian.hh ../src/Screen.hh \
../libpbe/include/Iconver.hh ../libpbe/include/Exception.hh \
../libpbe/include/Exception.hh

View File

@ -1,3 +0,0 @@
UrlEncodedCgiParams.d ../src/UrlEncodedCgiParams.o: \
../src/UrlEncodedCgiParams.cc ../src/UrlEncodedCgiParams.hh \
../src/CgiParams.hh ../libpbe/include/Exception.hh

View File

@ -1,4 +0,0 @@
auto_CgiParams.d ../src/auto_CgiParams.o: ../src/auto_CgiParams.cc \
../src/auto_CgiParams.hh ../src/CgiParams.hh \
../libpbe/include/HttpRequest.hh ../libpbe/include/URI.hh \
../src/UrlEncodedCgiParams.hh

View File

@ -1,2 +0,0 @@
diff.d ../src/diff.o: ../src/diff.cc ../src/diff.hh ../src/unicode.hh \
../libpbe/include/endian.hh

View File

@ -1,3 +0,0 @@
editscript.d ../src/editscript.o: ../src/editscript.cc \
../src/editscript.hh ../src/unicode.hh ../libpbe/include/endian.hh \
../src/diff.hh

View File

@ -1 +0,0 @@
expand_command.d ../src/expand_command.o: ../src/expand_command.cc

View File

@ -1,3 +0,0 @@
html.d ../src/html.o: ../src/html.cc ../src/html.hh ../src/Screen.hh \
../src/Cell.hh ../src/Attributes.hh ../src/unicode.hh \
../libpbe/include/endian.hh

View File

@ -1,21 +0,0 @@
main.d ../src/main.o: ../src/main.cc ../src/AnytermDaemon.hh \
../libpbe/include/HttpDaemon.hh ../libpbe/include/Daemon.hh \
../libpbe/include/FileDescriptor.hh ../libpbe/include/Exception.hh \
../libpbe/include/missing_syscalls.hh \
../libpbe/include/compiler_magic.hh ../libpbe/include/Mutex.hh \
../libpbe/include/atomic.hh ../libpbe/include/Lock.hh \
../libpbe/include/Futex.hh ../libpbe/include/Condition.hh \
../libpbe/include/HPtime.hh ../libpbe/include/Unlock.hh \
../libpbe/include/HttpRequest.hh ../libpbe/include/URI.hh \
../libpbe/include/HttpResponse.hh ../libpbe/include/HttpAuthenticator.hh \
../libpbe/include/HttpRequest.hh ../libpbe/include/HttpResponse.hh \
../src/Anyterm.hh ../libpbe/include/Locked.hh ../src/Session.hh \
../src/SessionId.hh ../libpbe/include/Mutex.hh \
../libpbe/include/Condition.hh ../src/Screen.hh ../src/Cell.hh \
../src/Attributes.hh ../src/unicode.hh ../libpbe/include/endian.hh \
../src/Terminal.hh ../libpbe/include/Iconver.hh ../src/Activity.hh \
../libpbe/include/FileDescriptor.hh ../libpbe/include/Thread.hh \
../src/config.hh ../src/NullAuthenticator.hh \
../libpbe/include/HttpAuthenticator.hh \
../libpbe/include/compiler_magic.hh ../src/TrivialAuthenticator.hh \
../libpbe/include/Exception.hh ../libpbe/include/segv_backtrace.hh

View File

@ -1 +0,0 @@
static_content.d static_content.o: static_content.cc static_content.hh

View File

@ -1,115 +0,0 @@
# common.mk
# This file is part of Anyterm; see http://anyterm.org/
# (C) 2005-2009 Philip Endecott
# 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 2 of the License, or
# 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, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
# You can have multiple build directories each with their own Makefiles.
# Those Makefiles include this common code; they can set variables to
# control things like optimisation level, debugging etc first. You should
# make changes in those build Makefiles rather than here, unless your
# change shouls apply to all build variants.
# Note that paths in here are relative to the build directory.
default_target: anytermd
SRC_DIR=../src
VPATH=${SRC_DIR} .
UNAME_S=$(shell uname -s)
ifeq (${UNAME_S},Darwin)
else
HAVE_GNU_LD=1
endif
LIBPBE_DIR=../libpbe
CPP_FLAGS=
GCC_FLAGS=-pthread
#GCC_FLAGS=-D_REENTRANT
COMPILE_FLAGS=$(CPP_FLAGS) $(GCC_FLAGS) -W -Wall ${OPTIMISE_FLAGS} ${DEBUG_FLAGS}
CC_COMPILE_FLAGS=$(COMPILE_FLAGS)
LINK_FLAGS=${GCC_FLAGS} ${DEBUG_FLAGS} \
-lutil
ifeq (${UNAME_S},OpenBSD)
LINK_FLAGS+=-liconv
endif
ifeq (${UNAME_S},Darwin)
LINK_FLAGS+=-liconv
endif
LIBPBE_MAKE_OPTIONS=
include ../libpbe.mk
CC_SRCS=$(sort $(notdir $(wildcard ${SRC_DIR}/*.cc)) static_content.cc)
BLOBFILES=anyterm.html anyterm.js anyterm.css copy.png paste.png copy.gif paste.gif
BLOBS=$(addsuffix .blob.o,$(BLOBFILES))
OBJS=$(addsuffix .o,$(notdir $(basename $(CC_SRCS))))
%.o: %.cc
$(CXX) $(CC_COMPILE_FLAGS) -c $<
ifdef HAVE_GNU_LD
%.blob.o: ../browser/%
cp $^ . ; $(LD) -r -b binary -o $@ $* ; rm $*
else
%.blob.c: ../browser/% ./mk_blob
./mk_blob $(subst .,_,$*) < $< > $@
mk_blob: mk_blob.c
$(CC) -o $@ $<
endif
anytermd: $(OBJS) $(BLOBS) $(LIBPBE_LIB)
$(CXX) -o $@ $(OBJS) $(BLOBS) $(LINK_FLAGS)
%.d: %.cc
$(CXX) -MM -MG -MT $@ -MT $(<:%.cc=%.o) $(CPP_FLAGS) $(GCC_FLAGS) -o $@ $<
DEPENDS=$(addsuffix .d,$(basename $(OBJS)))
-include $(DEPENDS)
install: FORCE
install anytermd /usr/local/bin
clean: FORCE
$(RM) -f *.o *.blob.c static_content.cc
veryclean: clean
$(RM) *.d
.PHONY: default_target install FORCE
static_content.cc: ../scripts/mk_static_content.sh ../browser/*
PATH="$${PATH}:../scripts" ../scripts/mk_static_content.sh $(BLOBFILES) > $@
static_content.o: CPP_FLAGS+=-I../src

View File

@ -1,15 +0,0 @@
This directory contains Anyterm-related files contributed by users.
If you have something that you think could be useful to others, do
please share it. Get in touch via the Anyterm forum at
http://anyterm.org/forums/.
se-linux/*
Configuration files Security-Enhanced Linux (e.g. Fedora Core).
Last updated for Anyterm-1.1.1.
Contributed by Carl Roth.
anyterm.spec
For building RPMs.
Last updated for Anyterm-1.1.1.
Contributed by Carl Roth.

View File

@ -1,136 +0,0 @@
#!/bin/bash
# Copyright (c) 2005-2010 Artica ST
#
# Author: Sancho Lerena <slerena@artica.es> 2006-2010
#
# /etc/init.d/anytermd
#
# System startup script for Pandora FMS's anyterm tool
#
# Comments to support chkconfig on RedHat Linux
# chkconfig: 2345 90 10
# description: Pandora FMS Server anytermd startup scrip
#
# Comments to support LSB init script conventions
### BEGIN INIT INFO
# Provides: anytermd
# Required-Start: $network
# Should-Start: $network
# Required-Stop: $syslog
# Should-Stop:
# Default-Start: 2 3 5
# Default-Stop: 0 1 6
# Short-Description: Anytermd startup script
# Description: Anytermd Server startup script for being used with Pandora FMS
### END INIT INFO
export PANDORA_DAEMON=/usr/bin/anytermd
# Uses a wait limit before sending a KILL signal, before trying to stop
# Pandora FMS server nicely. Some big systems need some time before close
# all pending tasks / threads.
export MAXWAIT=60
# Check for SUSE status scripts
if [ -f /etc/rc.status ]
then
. /etc/rc.status
rc_reset
else
# Define rc functions for non-suse systems, "void" functions.
function rc_status () { VOID=1; }
function rc_exit () { exit; }
function rc_failed () { VOID=1; }
fi
# This function replace pidof, not working in the same way in different linux distros
function pidof_pandora () (
# This sets COLUMNS to XXX chars, because if command is run
# in a "strech" term, ps aux don't report more than COLUMNS
# characters and this will not work.
COLUMNS=300
PANDORA_PID=`ps aux | grep "$PANDORA_DAEMON" | grep -v grep | tail -1 | awk '{ print $2 }'`
echo $PANDORA_PID
)
# Main script
if [ ! -f $PANDORA_DAEMON ]
then
echo "Anytermd not found, please check setup and read manual"
rc_status -s
rc_exit
fi
case "$1" in
start)
PANDORA_PID=`pidof_pandora`
if [ ! -z "$PANDORA_PID" ]
then
echo "Antermd is currently running on this machine with PID ($PANDORA_PID). Aborting now..."
rc_failed 1
rc_exit
fi
$PANDORA_DAEMON --port 8023 --user pandora -c 'telnet %p'
$PANDORA_DAEMON --port 8022 --user pandora -c 'ssh %p'
sleep 1
PANDORA_PID=`pidof_pandora`
if [ ! -z "$PANDORA_PID" ]
then
echo "Anyterm is now running with PID $PANDORA_PID"
rc_status -v
else
echo "Cannot start Anytermd. Aborted."
rc_status -s
fi
;;
stop)
PANDORA_PID=`pidof_pandora`
if [ -z "$PANDORA_PID" ]
then
echo "Anytermd is not running, cannot stop it."
rc_failed
else
echo "Killing anytermd processes $PANDORA_PID"
kill "$PANDORA_PID" > /dev/null 2>&1
# Let rid of the other process....shazam !
PANDORA_PID=`pidof_pandora`
if [ ! -z "$PANDORA_PID" ]
then
kill "$PANDORA_PID" > /dev/null 2>&1
fi
rc_status -v
fi
;;
status)
PANDORA_PID=`pidof_pandora`
if [ -z "$PANDORA_PID" ]
then
echo "Anytermd is not running."
rc_status
else
echo "Anytermd is running with PID $PANDORA_PID."
rc_status
fi
;;
force-reload|restart)
$0 stop
$0 start
;;
*)
echo "Usage: anytermd { start | stop | restart | status }"
exit 1
esac
rc_exit

View File

@ -1,44 +0,0 @@
# libpbe.mk
# This file is part of Anyterm; see http://anyterm.org/
# (C) 2006-2009 Philip Endecott
# 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 2 of the License, or
# 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, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
UNAME_S=$(shell uname -s)
UNAME_R=$(shell uname -r)
ifeq (${UNAME_S},Linux)
KVER=$(subst ., ,${UNAME_R})
ifeq ($(word 1,${KVER}),2)
ifeq ($(word 2,${KVER}),4)
SUPPORT_LINUX_2_4=1
endif
endif
endif
CPP_FLAGS+=-I$(LIBPBE_DIR)/include
ifdef SUPPORT_LINUX_2_4
CPP_FLAGS+=-DSUPPORT_LINUX_2_4
endif
LINK_FLAGS+=-L$(LIBPBE_DIR) -lpbe
LIBPBE_LIB=$(LIBPBE_DIR)/libpbe.a
$(LIBPBE_LIB): FORCE
cd $(LIBPBE_DIR); $(MAKE) $(LIBPBE_MAKE_OPTIONS)

View File

@ -1,28 +0,0 @@
Certain files in this library are distributed under the terms of the Boost
Software License, shown below, but most are not. Please refer to each file's
header for details of the license that applies.
Boost Software License - Version 1.0 - August 17th, 2003
Permission is hereby granted, free of charge, to any person or organization
obtaining a copy of the software and accompanying documentation covered by
this license (the "Software") to use, reproduce, display, distribute,
execute, and transmit the Software, and to prepare derivative works of the
Software, and to permit third-parties to whom the Software is furnished to
do so, all subject to the following:
The copyright notices in the Software and this entire statement, including
the above license grant, this restriction and the following disclaimer,
must be included in all copies of the Software, in whole or in part, and
all derivative works of the Software, unless such copies or derivative
works are solely in the form of machine-executable object code generated by
a source language processor.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.

View File

@ -1,340 +0,0 @@
GNU GENERAL PUBLIC LICENSE
Version 2, June 1991
Copyright (C) 1989, 1991 Free Software Foundation, Inc.
59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
Preamble
The licenses for most software are designed to take away your
freedom to share and change it. By contrast, the GNU General Public
License is intended to guarantee your freedom to share and change free
software--to make sure the software is free for all its users. This
General Public License applies to most of the Free Software
Foundation's software and to any other program whose authors commit to
using it. (Some other Free Software Foundation software is covered by
the GNU Library General Public License instead.) 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
this service 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 make restrictions that forbid
anyone to deny you these rights or to ask you to surrender the rights.
These restrictions translate to certain responsibilities for you if you
distribute copies of the software, or if you modify it.
For example, if you distribute copies of such a program, whether
gratis or for a fee, you must give the recipients all the rights that
you have. 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.
We protect your rights with two steps: (1) copyright the software, and
(2) offer you this license which gives you legal permission to copy,
distribute and/or modify the software.
Also, for each author's protection and ours, we want to make certain
that everyone understands that there is no warranty for this free
software. If the software is modified by someone else and passed on, we
want its recipients to know that what they have is not the original, so
that any problems introduced by others will not reflect on the original
authors' reputations.
Finally, any free program is threatened constantly by software
patents. We wish to avoid the danger that redistributors of a free
program will individually obtain patent licenses, in effect making the
program proprietary. To prevent this, we have made it clear that any
patent must be licensed for everyone's free use or not licensed at all.
The precise terms and conditions for copying, distribution and
modification follow.
GNU GENERAL PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
0. This License applies to any program or other work which contains
a notice placed by the copyright holder saying it may be distributed
under the terms of this General Public License. The "Program", below,
refers to any such program or work, and a "work based on the Program"
means either the Program or any derivative work under copyright law:
that is to say, a work containing the Program or a portion of it,
either verbatim or with modifications and/or translated into another
language. (Hereinafter, translation is included without limitation in
the term "modification".) Each licensee is addressed as "you".
Activities other than copying, distribution and modification are not
covered by this License; they are outside its scope. The act of
running the Program is not restricted, and the output from the Program
is covered only if its contents constitute a work based on the
Program (independent of having been made by running the Program).
Whether that is true depends on what the Program does.
1. You may copy and distribute 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 and disclaimer of warranty; keep intact all the
notices that refer to this License and to the absence of any warranty;
and give any other recipients of the Program a copy of this License
along with the Program.
You may charge a fee for the physical act of transferring a copy, and
you may at your option offer warranty protection in exchange for a fee.
2. You may modify your copy or copies of the Program or any portion
of it, thus forming a work based on the Program, and copy and
distribute such modifications or work under the terms of Section 1
above, provided that you also meet all of these conditions:
a) You must cause the modified files to carry prominent notices
stating that you changed the files and the date of any change.
b) You must cause any work that you distribute or publish, that in
whole or in part contains or is derived from the Program or any
part thereof, to be licensed as a whole at no charge to all third
parties under the terms of this License.
c) If the modified program normally reads commands interactively
when run, you must cause it, when started running for such
interactive use in the most ordinary way, to print or display an
announcement including an appropriate copyright notice and a
notice that there is no warranty (or else, saying that you provide
a warranty) and that users may redistribute the program under
these conditions, and telling the user how to view a copy of this
License. (Exception: if the Program itself is interactive but
does not normally print such an announcement, your work based on
the Program is not required to print an announcement.)
These requirements apply to the modified work as a whole. If
identifiable sections of that work are not derived from the Program,
and can be reasonably considered independent and separate works in
themselves, then this License, and its terms, do not apply to those
sections when you distribute them as separate works. But when you
distribute the same sections as part of a whole which is a work based
on the Program, the distribution of the whole must be on the terms of
this License, whose permissions for other licensees extend to the
entire whole, and thus to each and every part regardless of who wrote it.
Thus, it is not the intent of this section to claim rights or contest
your rights to work written entirely by you; rather, the intent is to
exercise the right to control the distribution of derivative or
collective works based on the Program.
In addition, mere aggregation of another work not based on the Program
with the Program (or with a work based on the Program) on a volume of
a storage or distribution medium does not bring the other work under
the scope of this License.
3. You may copy and distribute the Program (or a work based on it,
under Section 2) in object code or executable form under the terms of
Sections 1 and 2 above provided that you also do one of the following:
a) Accompany it with the complete corresponding machine-readable
source code, which must be distributed under the terms of Sections
1 and 2 above on a medium customarily used for software interchange; or,
b) Accompany it with a written offer, valid for at least three
years, to give any third party, for a charge no more than your
cost of physically performing source distribution, a complete
machine-readable copy of the corresponding source code, to be
distributed under the terms of Sections 1 and 2 above on a medium
customarily used for software interchange; or,
c) Accompany it with the information you received as to the offer
to distribute corresponding source code. (This alternative is
allowed only for noncommercial distribution and only if you
received the program in object code or executable form with such
an offer, in accord with Subsection b above.)
The source code for a work means the preferred form of the work for
making modifications to it. For an executable work, complete source
code means all the source code for all modules it contains, plus any
associated interface definition files, plus the scripts used to
control compilation and installation of the executable. However, as a
special exception, the source code distributed need not include
anything that is normally distributed (in either source or binary
form) with the major components (compiler, kernel, and so on) of the
operating system on which the executable runs, unless that component
itself accompanies the executable.
If distribution of executable or object code is made by offering
access to copy from a designated place, then offering equivalent
access to copy the source code from the same place counts as
distribution of the source code, even though third parties are not
compelled to copy the source along with the object code.
4. You may not copy, modify, sublicense, or distribute the Program
except as expressly provided under this License. Any attempt
otherwise to copy, modify, sublicense or distribute the Program is
void, and will automatically terminate your rights under this License.
However, parties who have received copies, or rights, from you under
this License will not have their licenses terminated so long as such
parties remain in full compliance.
5. You are not required to accept this License, since you have not
signed it. However, nothing else grants you permission to modify or
distribute the Program or its derivative works. These actions are
prohibited by law if you do not accept this License. Therefore, by
modifying or distributing the Program (or any work based on the
Program), you indicate your acceptance of this License to do so, and
all its terms and conditions for copying, distributing or modifying
the Program or works based on it.
6. Each time you redistribute the Program (or any work based on the
Program), the recipient automatically receives a license from the
original licensor to copy, distribute or modify the Program subject to
these terms and conditions. You may not impose any further
restrictions on the recipients' exercise of the rights granted herein.
You are not responsible for enforcing compliance by third parties to
this License.
7. If, as a consequence of a court judgment or allegation of patent
infringement or for any other reason (not limited to patent issues),
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
distribute so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you
may not distribute the Program at all. For example, if a patent
license would not permit royalty-free redistribution of the Program by
all those who receive copies directly or indirectly through you, then
the only way you could satisfy both it and this License would be to
refrain entirely from distribution of the Program.
If any portion of this section is held invalid or unenforceable under
any particular circumstance, the balance of the section is intended to
apply and the section as a whole is intended to apply in other
circumstances.
It is not the purpose of this section to induce you to infringe any
patents or other property right claims or to contest validity of any
such claims; this section has the sole purpose of protecting the
integrity of the free software distribution system, which is
implemented by public license practices. Many people have made
generous contributions to the wide range of software distributed
through that system in reliance on consistent application of that
system; it is up to the author/donor to decide if he or she is willing
to distribute software through any other system and a licensee cannot
impose that choice.
This section is intended to make thoroughly clear what is believed to
be a consequence of the rest of this License.
8. If the distribution and/or use of the Program is restricted in
certain countries either by patents or by copyrighted interfaces, the
original copyright holder who places the Program under this License
may add an explicit geographical distribution limitation excluding
those countries, so that distribution is permitted only in or among
countries not thus excluded. In such case, this License incorporates
the limitation as if written in the body of this License.
9. The Free Software Foundation may publish revised and/or new versions
of the 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 a version number of this License which applies to it and "any
later version", you have the option of following the terms and conditions
either of that version or of any later version published by the Free
Software Foundation. If the Program does not specify a version number of
this License, you may choose any version ever published by the Free Software
Foundation.
10. If you wish to incorporate parts of the Program into other free
programs whose distribution conditions are different, write to the author
to ask for permission. For software which is copyrighted by the Free
Software Foundation, write to the Free Software Foundation; we sometimes
make exceptions for this. Our decision will be guided by the two goals
of preserving the free status of all derivatives of our free software and
of promoting the sharing and reuse of software generally.
NO WARRANTY
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, 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.
12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
REDISTRIBUTE 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.
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
convey 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 2 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, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Also add information on how to contact you by electronic and paper mail.
If the program is interactive, make it output a short notice like this
when it starts in an interactive mode:
Gnomovision version 69, Copyright (C) year name of author
Gnomovision 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, the commands you use may
be called something other than `show w' and `show c'; they could even be
mouse-clicks or menu items--whatever suits your program.
You should also get your employer (if you work as a programmer) or your
school, if any, to sign a "copyright disclaimer" for the program, if
necessary. Here is a sample; alter the names:
Yoyodyne, Inc., hereby disclaims all copyright interest in the program
`Gnomovision' (which makes passes at compilers) written by James Hacker.
<signature of Ty Coon>, 1 April 1989
Ty Coon, President of Vice
This 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 Library General
Public License instead of this License.

View File

@ -1,46 +0,0 @@
# Makefile
# This file is part of libpbe; see http://decimail.org
# (C) 2005-2007 Philip Endecott
# 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 2 of the License, or
# 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, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
default_target: library
BUILD_DIR=build
LIBRARY=libpbe.a
library: $(LIBRARY)
$(LIBRARY): FORCE
cd ${BUILD_DIR}; ${MAKE} ${LIBRARY}
cp ${BUILD_DIR}/${LIBRARY} ${LIBRARY}
libpbe%.a: FORCE
${MAKE} -C build$* libpbe.a
cp build$*/libpbe.a $@
clean: FORCE
cd ${BUILD_DIR}; $(MAKE) clean
rm $(LIBRARY)
veryclean: FORCE
cd ${BUILD_DIR}; $(MAKE) veryclean
rm $(LIBRARY)
.PHONY: clean veryclean library default_target
FORCE:

View File

@ -1,8 +0,0 @@
This is libpbe, a personal library of C++ utilities.
See the examples directory for some example code using these functions
(not all examples are up to date.)
For more information, see
http://decimail.org/
http://anyterm.org/

View File

@ -1,8 +0,0 @@
platdir=/Developer/Platforms/iPhoneSimulator.platform
CXX=${platdir}/Developer/usr/bin/g++
AR=${platdir}/Developer/usr/bin/ar
OPTIMISE_FLAGS=-O
DEBUG_FLAGS=
include ../common.mk

View File

@ -1,4 +0,0 @@
CgiParams.d CgiParams.o: ../src/CgiParams.cc ../include/CgiParams.hh \
../include/StringSplitter.hh ../include/ci_string.hh \
../include/Exception.hh ../include/utils.hh \
../include/StringTransformer.hh

View File

@ -1 +0,0 @@
CgiVars.d CgiVars.o: ../src/CgiVars.cc ../include/CgiVars.hh

View File

@ -1,7 +0,0 @@
Daemon.d Daemon.o: ../src/Daemon.cc ../include/Daemon.hh \
../include/FileDescriptor.hh ../include/Exception.hh \
../include/missing_syscalls.hh ../include/compiler_magic.hh \
../include/Mutex.hh ../include/atomic.hh ../include/Lock.hh \
../include/Futex.hh ../include/Condition.hh ../include/HPtime.hh \
../include/Unlock.hh ../include/Exception.hh ../include/Lock.hh \
../include/Thread.hh

View File

@ -1,2 +0,0 @@
Date.d Date.o: ../src/Date.cc ../include/Date.hh ../include/DateTime.hh \
../include/Date.hh ../include/Time.hh ../include/Exception.hh

View File

@ -1,2 +0,0 @@
Directory.d Directory.o: ../src/Directory.cc ../include/Directory.hh \
../include/Exception.hh

View File

@ -1 +0,0 @@
Exception.d Exception.o: ../src/Exception.cc ../include/Exception.hh

View File

@ -1,3 +0,0 @@
HttpAuthenticator.d HttpAuthenticator.o: ../src/HttpAuthenticator.cc \
../include/HttpAuthenticator.hh ../include/base64.hh \
../include/init_array.hh ../include/compiler_magic.hh

View File

@ -1,8 +0,0 @@
HttpClient.d HttpClient.o: ../src/HttpClient.cc ../include/HttpClient.hh \
../include/URI.hh ../include/HttpResponse.hh \
../include/FileDescriptor.hh ../include/Exception.hh \
../include/missing_syscalls.hh ../include/compiler_magic.hh \
../include/HttpRequest.hh ../include/TcpClientSocket.hh ../include/ip.hh \
../include/Gunzipper.hh ../include/Bunzipper.hh \
../include/FileDescriptor.hh ../include/rfcdate.hh \
../include/FileType.hh ../include/atomic_ofstream.hh

View File

@ -1,10 +0,0 @@
HttpDaemon.d HttpDaemon.o: ../src/HttpDaemon.cc ../include/HttpDaemon.hh \
../include/Daemon.hh ../include/FileDescriptor.hh \
../include/Exception.hh ../include/missing_syscalls.hh \
../include/compiler_magic.hh ../include/Mutex.hh ../include/atomic.hh \
../include/Lock.hh ../include/Futex.hh ../include/Condition.hh \
../include/HPtime.hh ../include/Unlock.hh ../include/HttpRequest.hh \
../include/URI.hh ../include/HttpResponse.hh \
../include/HttpAuthenticator.hh ../include/HttpRequest.hh \
../include/parse_http_request.hh ../include/HttpResponse.hh \
../include/rfcdate.hh

View File

@ -1,5 +0,0 @@
HttpResponse.d HttpResponse.o: ../src/HttpResponse.cc \
../include/HttpResponse.hh ../include/FileDescriptor.hh \
../include/Exception.hh ../include/missing_syscalls.hh \
../include/compiler_magic.hh ../include/FileDescriptor.hh \
../include/mustfind.hh

View File

@ -1 +0,0 @@
include ../common.mk

View File

@ -1 +0,0 @@
SmtpClient.d SmtpClient.o: ../src/SmtpClient.cc

View File

@ -1 +0,0 @@
URI.d URI.o: ../src/URI.cc ../include/URI.hh

View File

@ -1,6 +0,0 @@
charset_names.d charset_names.o: ../src/charset_names.cc \
../include/charset/charset_names.hh ../include/charset/charset_t.hh \
../include/charset/generated/charset_t_enum_body.hh \
../src/generated/charset_iana_names_body.cc \
../src/generated/charset_mime_names_body.cc \
../src/generated/charset_lookup_body.cc

View File

@ -1 +0,0 @@
ci_string.d ci_string.o: ../src/ci_string.cc ../include/ci_string.hh

View File

@ -1,2 +0,0 @@
create_dir.d create_dir.o: ../src/create_dir.cc ../include/create_dir.hh \
../include/Exception.hh ../include/FileType.hh

View File

@ -1 +0,0 @@
csv.d csv.o: ../src/csv.cc ../include/csv.hh

View File

@ -1 +0,0 @@
format.d format.o: ../src/format.cc ../include/format.hh

View File

@ -1 +0,0 @@
geometry.d geometry.o: ../src/geometry.cc ../include/geometry.hh

View File

@ -1 +0,0 @@
ip.d ip.o: ../src/ip.cc ../include/ip.hh ../include/Exception.hh

View File

@ -1,8 +0,0 @@
iso8859_tables.d iso8859_tables.o: ../src/iso8859_tables.cc \
../include/charset/conv/iso8859.hh ../include/charset/charset_t.hh \
../include/charset/generated/charset_t_enum_body.hh \
../include/charset/char_t.hh ../include/charset/charset_traits.hh \
../include/charset/charset_t.hh ../include/charset/char_t.hh \
../include/charset/char_conv.hh ../include/charset/charset_traits.hh \
../include/charset/error_policy.hh ../include/compiler_magic.hh \
../src/generated/iso8859_tables_body.cc

View File

@ -1,2 +0,0 @@
markup.d markup.o: ../src/markup.cc ../include/markup.hh \
../include/StringTransformer.hh

View File

@ -1,3 +0,0 @@
parse_http_request.d parse_http_request.o: ../src/parse_http_request.cc \
../include/parse_http_request.hh ../include/HttpRequest.hh \
../include/URI.hh ../include/Exception.hh

View File

@ -1 +0,0 @@
rfcdate.d rfcdate.o: ../src/rfcdate.cc

View File

@ -1,2 +0,0 @@
run_cmd.d run_cmd.o: ../src/run_cmd.cc ../include/run_cmd.hh \
../include/Exception.hh

View File

@ -1,2 +0,0 @@
segv_backtrace.d segv_backtrace.o: ../src/segv_backtrace.cc \
../include/segv_backtrace.hh ../include/compiler_magic.hh

View File

@ -1,2 +0,0 @@
select.d select.o: ../src/select.cc ../include/select.hh \
../include/Exception.hh

View File

@ -1,3 +0,0 @@
to_ascii_letters.d to_ascii_letters.o: ../src/to_ascii_letters.cc \
../include/charset/to_ascii_letters.hh ../include/charset/char_t.hh \
../src/generated/to_ascii_letters_tables.cc

View File

@ -1,2 +0,0 @@
utils.d utils.o: ../src/utils.cc ../include/utils.hh \
../include/StringTransformer.hh ../include/Exception.hh

View File

@ -1 +0,0 @@
include ../common.mk

View File

@ -1,112 +0,0 @@
# src/Makefile
# This file is part of libpbe; see http://decimail.org
# (C) 2004-2007 Philip Endecott
# 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 2 of the License, or
# 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, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
default_target: library
LIBRARY=libpbe.a
library: $(LIBRARY)
UNAME_S=$(shell uname -s)
UNAME_R=$(shell uname -r)
ifeq (${UNAME_S},Linux)
KVER=$(subst ., ,${UNAME_R})
ifeq ($(word 1,${KVER}),2)
ifeq ($(word 2,${KVER}),4)
SUPPORT_LINUX_2_4=1
endif
endif
endif
SRC_DIR=../src
INCLUDE_DIR=../include
VPATH=${SRC_DIR}
SKIP_SRCS:=
ifndef ENABLE_POSTGRESQL
SKIP_SRCS+=Database.cc
endif
ifndef ENABLE_IMAGEMAGICK
SKIP_SRCS+=jpegsize.cc
endif
ifndef ENABLE_RECODE
SKIP_SRCS+=Recoder.cc
endif
ifdef DISABLE_HTTP_CLIENT
SKIP_SRCS+=HttpClient.cc
endif
CC_SRCS=$(filter-out ${SKIP_SRCS},$(notdir $(wildcard ${SRC_DIR}/*.cc)))
CC_SRCS+=
OBJS=$(addsuffix .o,$(notdir $(basename $(CC_SRCS))))
DEPENDS=$(addsuffix .d,$(notdir $(basename $(CC_SRCS))))
-include $(DEPENDS)
WARN_FLAGS=-W -Wall
OPTIMISE_FLAGS=-O
DEBUG_FLAGS=
ifdef ENABLE_POSTGRESQL
PG_INC_FLAGS=-I$(shell pg_config --includedir)
else
PG_INC_FLAGS=
endif
INC_FLAGS+=$(PG_INC_FLAGS) -I${INCLUDE_DIR}
COMPILE_FLAGS=$(WARN_FLAGS) $(OPTIMISE_FLAGS) $(DEBUG_FLAGS) $(INC_FLAGS) -pthread -fPIC
ifdef SUPPORT_LINUX_2_4
COMPILE_FLAGS+=-DSUPPORT_LINUX_2_4
endif
$(LIBRARY): $(OBJS)
$(AR) ruv $(LIBRARY) $(OBJS)
%.o: %.cc
$(CXX) $(CXXFLAGS) $(COMPILE_FLAGS) -c $<
%.d: %.cc
$(CXX) $(CXXFLAGS) -pthread -MM -MT $@ -MT $(notdir $(<:%.cc=%.o)) $(INC_FLAGS) -o $@ $<
all: $(EXECUTABLE)
clean: FORCE
$(RM) *.o $(LIBRARY)
veryclean: clean FORCE
$(RM) *.d
FORCE:
testing:
echo ${CC_SRCS}

View File

@ -1,228 +0,0 @@
pbe::Database
=============
pbe::Database is a C++ SQL database API. It is implemented as a wrapper around
PostgreSQL's libpq C client library. Its objective is:
- To support a "modern" C++ style with a concise convenient syntax.
- To avoid the need to construct SQL queries in strings as far as possible.
- To perform as much compile-time type checking as possible.
- To have minimal overhead compared to raw libpq.
The source code is somewhat commented, and you should consider the comments in
the source to be more more definitive, comprehensive and up-to-date than this
file.
Usage
-----
Here's a very quick summary:
#include <Database.hh>
using namespace pbe;
...
Database db("dbname=foo, username=blah");
Query<string,int> insert_thing(db,"insert into things(name,num) values ($1,$2)");
SingletonQuery<int, string> count_things(db,"select sum(num) from things where name=$1");
Transaction t(db);
insert_thing("table",1);
insert_thing("chair",4);
int n = count_things("bed");
t.commit();
Now some more details:
* 1. Connect to the database server.
The pbe::Database object represents a connection to the database server. Its
constructor takes a string which defines the connection parameters in the
standard PostgreSQL format. See the PostgreSQL documentation for details.
* 2. Declare queries.
Queries are declared before use. The query constructor takes a reference to the
database connection and the query's SQL string. Template parameters specify the
C++ types of the parameters. For example, in this example:
Query<string,int> insert_thing(db,"insert into things(name,num) values ($1,$2)");
PostgreSQL is given a query string containing two placeholders for parameters, $1
and $2. Their C++ types are string and int respectively. Compile-time type
checking ensures that when the query is used the C++ parameters have (or are
convertible to) these types. A mapping is built in from C++ types to PostgreSQL
types. At present the mapping is as follows. It is fairly straightforward to
add more types.
C++ Type PostgreSQL type
-------- ---------------
std::string TEXT
int INT4
time_t TIMESTAMP WITH TIME ZONE
float FLOAT4
The geneeral type 'Query', as shown above, should be used for
- Queries that return multi-row, multi-column data.
- Queries that reutrn no data (e.g. update, delete, create table etc.)
The following variants are available for other cases. They have the benefit of
additional type checking and the like.
ColumnQuery<ResultType, Param1Type,...>
- Use this for a query that returns a single column of results, and give the C++
type for the result as the first template parameter.
SingletonQuery<ResultType, Param1Type,...>
- Use this for a query that returns a single value (one row, one column), e.g.
"count(*)" or "select sum(...)". The type of the result value is given as the
first template parameter.
OptQuery<ResultType, Param1Type,...>
- Use this fora query that returns either a single value as above or no results
at all. Once again the result value is given as the first template parameter.
One option for query declaration is to define a subclass of pbe::Database that
contains them. The existence of the SQL database can then be hidden from the use
of the class:
class ThingList: public Database {
public:
Query<string,int> add_thing;
SingletonQuery<int, string> count_things;
Query<string> delete_thing;
ThingList():
Database("dbname=things"),
add_thing(*this, "insert into things(name,num) values ($1,$2)"),
count_things(*this, "select sum(num) from things where name=$1"),
delete_thing(*this, "delete from things where name=$1")
{}
};
...
ThingList tl;
tl.add_thing("pen",25);
tl.add_thing("pencil",50);
tl.delete_thing("desk");
int num_lamps = tl.count_things("lamp");
* 3. Use a transaction.
To group a series of queries in a transaction, declare a Transaction object.
This takes a reference to the Database object as a constructor parameter. A
BEGIN statement is executed when the Transaction object is constructed. After
running your queries, call the Transaction's commit() method to execute a
COMMIT statement.
If something goes wrong and an exception is thrown, the Transaction object's
destructor is called as it goes out of scope. At this point a ROLLBACK statement
is executed.
It is probably best to used additional { } to bind the Transaction tightly to the
queries it is protecting, i.e.
...
{
Transaction t(db);
insert_thing(...);
...more queries...
t.commit();
}
...
* 4. Run the queries.
The Query objects are functors, i.e. they are objects that you can use as
functions. (This is achieved by defining operator().) For example:
insert_thing("table",1);
The parameters are passed to PostgreSQL using libpq's binary parameter format.
The query strings are passed to PostgreSQL the first time that they are used,
where they are stored as "prepared statements" for further uses. The prepared
statements are freed ("deallocated") when the Query object goes out of scope.
If for some reason you don't want to use prepared statements then you can use the
runonce() method:
insert_thing.runonce("table",1);
This should have exactly the same behaviour as the normal case.
(Note that although PostgreSQL only supports prepared statements and binary
parameters for SELECT, UPDATE, INSERT and DELETE statements, you don't need to
worry as this library detects other statements and treats them specially.)
* 5. Get the results.
The result of a general Query can be assigned to a Result object:
Query<int> q(db, "select a,b from t where c=$1");
Result r = q(99);
The size of the result is available in the rows and cols members. Individual
elements can be accessed using the get() method, which takes a row number and
either a column number or a column name, and the expected type as a template
parameter. Type checking is performed; if you want to avoid this small overhead,
use get_nocheck(). There is also an is_null method:
string s = r.get<string>(0,0);
int a = r.get<int>(1,"b");
if (!r.is_null(2,0)) {
...
}
The result of a ColumnQuery is a ColumnResult. ColumnResult takes the result
type as a template parameter, and you access elements using ():
ColumnQuery<string> q(db, "select name from t");
ColumnResult<string> r = q();
string s = r(1);
It is also a standard-library-compatible random-access container:
typedef ColumnResult<string> col_t;
col_t r = q();
for ( col_t::const_iterator i = r.begin();
i != r.end(); ++i ) {
cout << *i << "\n";
}
SingletonResult is used for SingletonQueries. It is convertible to the result
type itself, so you don't normally need to declare it; the exception would be if
you needed tu use is_null() first.
SingletonQuery<int, name> count_things(db,"select sum(num) from things where name=$1");
int n = count_things("bed");
OptResult stores the result of an OptQuery. The presence of a value can be
tested by calling the empty() method.
Instalation / Compilation
-------------------------
pbe::Database is part of libpbe, and you can build the library just by running
"make" at the top level. But libpbe probably contains lots of stuff that you
don't want, so it may be easiest just to copy the Database files, and the few
other files that they depend on, into your own build environment.
There is one significant external dependency which is Boost. Version 1.33.1
works; I can't comment on other versions.
License
-------
This is all licensed under the GPL. I'm aware that this is different from
PostgreSQL itself; if you would like to see this use a different license, let me
know.

View File

@ -1,192 +0,0 @@
Character Sets - Introduction
=============================
This is a bottom-up file-by-file introduction to the character-set functionality in the
include/charsets/ directory.
char_t.hh
---------
This defines defined-size character types char8_t, char16_t and char32_t.
Something similar is proposed for C++0x (see N1823). That doesn't include char8_t; does
that mean that char is certain to be 8 bits? Even so, I think that char8_t is a useful
alias.
charset_t.hh
------------
This defines an enum, charset_t, to name character sets.
It is populated with a large number of character set names and aliases automatically
generated from tha IANA character sets registrations. See the file names.txt for more
information about this automatic processing.
charset_names.hh
----------------
This file provides facilities to convert between the charset_t enum and textual
character set names (in ASCII). This is also based on automatically-generated tables
from the IANA data.
charset_traits.hh
-----------------
This declares a class template, charset_traits<charset_t>, which can be specialised for
each character set. Each specialisation indicates:
- The unit and character types, which differ for character sets variable-length
encodings.
- A state type, for those character sets that have a "shift state".
- Booleans to indicate characteristics such as whether the character set is an ASCII
superset, and so on.
- For variable-length encodings, various functions for encoding and decoding. (More
about this below.)
More will probably be added, for example constants to indicate the maximum or
typical number of units per character.
utf8.hh
-------
This provides a specialisation of charset_traits for utf8, including the encoding and
decoding functions.
Similar files will be needed for UTF-16, iso-2022, GB18030, Big5, Shift-JIS etc.
const_character_iterator.hh
---------------------------
This defines an iterator adaptor, using boost::iterator_adapter, that takes an iterator
over a sequence of units and provides a const iterator over its characters. It does
this using the encoding and decoding functions from the charset_traits, which have
trivial implementations for fixed-length character sets.
The iterator is bidirectional, not random access.
character_output_iterator.hh
----------------------------
This defines a second iterator adaptor that provides a mutable character iterator from a
mutable unit iterator. It is an output iterator, and would normally be used with a
back-insertion iterator that appends to the sequence of units.
charset_char_traits.hh
----------------------
This provides per-character-set classes compatible with std::char_traits.
error_policy.hh
---------------
When an error occurs during conversion, an error_policy indicates what should happen.
This file supplies two error policies, error_policy_throw and
error_policy_return_sentinel.
char_conv.hh
------------
Class char_conv converts a single character from one character set to another. The
input and output character sets, and an error policy, are indicated by template
parameters, and (partial) specialisation will be used to provide conversions for
particular character set pairs.
The default class attempts to convert in two steps via UCS4.
Static booleans could be added to indicate whether the conversion is
losslessly-reversible, and so on - "character set pair traits", in effect.
conv/ascii.hh
-------------
Provides trivial conversion between ASCII and Unicode.
conv/unicode.hh
---------------
Provides trivial conversion between the different Unicode character sets.
conv/iso8859.hh
---------------
Provides conversion to and from the ISO 8859-n character sets. Conversion for 8859-1 is
trivial. For the other character sets, automatically generated tables from the Unicode
mapping data are used. Tables for 8859-to-Unicode are built in; the sparser tables
for the reverse conversion are generated from them when first needed.
char_converter.hh
-----------------
This is a simple wrapper around char_conv that uses a stateful functor to track the
shift state from one invocation to the next.
sequence_conv.hh
----------------
This converts a sequence of characters using a similar interface to char_conv. Its default
implementation invokes char_conv repeatedly to do the work.
Specialisations of this will be provided for fast conversion of contiguous-in-memory data.
sequence_converter.hh
---------------------
This is a simple wrpapper around sequence_conv that uses a stateful functor to track the
shift state from one invocation to the next.
string_adaptor.hh
-----------------
This provides an adaptor that provides character-at-a-time access to a string of units. It
stores a reference to the underlying string.
There is still a lot of work to do here. In particular, in each instance where a std::string
member takes or returns a position we have the choice to use
1. A unit poisition.
2. A character position.
3. An iterator.
There are pros and cons to each.
There's also the question of over-writing the middle of a string.
cs_string.hh
------------
A string tagged with its character set. This is implemented using string_adaptor plus an
owned unit-string. Again, lots still to be decided.
STILL TO DO
===========
I still plan to add:
- Fallback character conversion using iconv.
- Optimisation for conversion of contiguous-in-memory data.
- Conversion from one cs_string to another.
- Typedefs for common string and character types, e.g. utf8_string.
- Worry about all those places where I do comparisons on char values that may or
may not be signed....

View File

@ -1,81 +0,0 @@
Character Set Names
===================
A typical entry from the IANA character set listing at
http://www.iana.org/assignments/character-sets is as follows:
Name: ANSI_X3.4-1968 [RFC1345,KXS2]
MIBenum: 3
Source: ECMA registry
Alias: iso-ir-6
Alias: ANSI_X3.4-1986
Alias: ISO_646.irv:1991
Alias: ASCII
Alias: ISO646-US
Alias: US-ASCII (preferred MIME name)
Alias: us
Alias: IBM367
Alias: cp367
Alias: csASCII
Based on this, three things are needed:
- A set of valid C++ identifiers that can be used in the charset_t enumeration.
- An ASCII string that should be output when the character set's name must be printed.
- A set of ASCII strings that should be recognised when the character set's name is
input.
The following rules are applied:
charset_t enumeration members
-----------------------------
The Name: and all Alias: lines are used. All punctuation characters are replaced by
underscores; all adjacent punctuation characters are compressed to one, and any trailing
punctuation characters are trimmed (?). Letters are mapped to lower case. This results
for the example above in the following:
ansi_x3_4_1968
iso_ir_6
ansi_x3_4_1986
iso_646_irv_1991
ascii
iso646_us
us_ascii
us
ibm367
cp367
csascii
Variants are then produced with underscores omitted [but not underscores that separate
numbers on both sides]:
ansi_x3_4_1968 ansix3_4_1968
iso_ir_6 iso_ir6 isoir_6 isoir6
ansi_x3_4_1986 ansix3_4_1986
iso_646_irv_1991 iso_646_irv1991 iso_646irv_1991 iso_646irv1991
iso646_irv_1991 iso646_irv1991 iso646irv_1991 isi646irv1991
ascii
iso646_us iso646us
us_ascii usascii
us
ibm367
cp367
csascii
ASCII Output
------------
Two functions convert to ASCII: charset_name uses the string from the Name: line in
the description (ANSI_X3.4-1968 in this case) and charset_mime_name uses any "preferred
MIME name" that is specified (US-ASCII in this case).
ASCII Input
-----------
The name is looked up in a similar table to the one used for enumerations above; the
lookup is insensitive to case and to punctuation.

View File

@ -1,46 +0,0 @@
# examples/Makefile
# This file is part of libpbe; see http://decimail.org
# (C) 2007 Philip Endecott
# 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 2 of the License, or
# 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, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
default_target: all
all: inc_daemon mailform directory_explorer fixed_point
DEBUG_FLAGS=-W -Wall
OPT_FLAGS=-O
INC_FLAGS=-I../include
LINK_FLAGS=-L.. -lpbe
CPP=g++
CPP_FLAGS=$(DEBUG_FLAGS) $(OPT_FLAGS) $(INC_FLAGS)
%: %.cc
$(CPP) $(CPP_FLAGS) $< -o $@ $(LINK_FLAGS)
inc_daemon: inc_daemon.cc
$(CPP) $(CPP_FLAGS) $< -o $@ $(LINK_FLAGS) -lomnithread
mailform: mailform.cc
directory_explorer: directory_explorer.cc
bunzip http_get_bunzip: LINK_FLAGS+=-lbz2
gunzip http_get_gunzip http_get_with_etag: LINK_FLAGS+=-lz
.PHONY: default_target all

View File

@ -1,23 +0,0 @@
// Get a backtrace when we de-reference a null ponter.
#include <stdlib.h>
#include "segv_backtrace.hh"
int* ptr;
int badstuff(int i)
{
ptr = NULL;
return badstuff(*ptr * i);
}
int main()
{
get_backtrace_on_segv();
return badstuff(1);
}

View File

@ -1,15 +0,0 @@
#include <iostream>
#include <string>
#include "base64.hh"
using namespace std;
using namespace pbe;
int main()
{
string s="dGhlIHF1aWNrIGJyb3duIGZveCBqdW1wcyBvdmVyIHRoZSBsYXp5IGRvZyEKCg==";
cout << decode_base64(s);
}

View File

@ -1,50 +0,0 @@
// examples/bunzip.cc
// This file is part of libpbe; see http://svn.chezphil.org/libpbe/
// (C) 2008 Philip Endecott
// 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 2 of the License, or
// 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, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "Bunzipper.hh"
#include "FileDescriptor.hh"
#include <string>
#include <iostream>
using namespace std;
using namespace pbe;
int main(int argc, char* argv[])
{
if (argc!=2) {
cerr << "Usage: bunzip <file.bz>\n";
return 1;
}
string fn = argv[1];
FileDescriptor fd(fn,FileDescriptor::read_only);
string in = fd.readall();
Bunzipper bz;
string out = bz(in);
cout << out;
return 0;
}

View File

@ -1,14 +0,0 @@
England,London
Scotland,Edinburgh
Wales,Cardiff
France,Paris
Spain,Madrid
Germany,Berlin
Italy,Rome
Portugal,Lisbon
Russia,Moscow
Serbia,Belgrade
Greece,Athens
Belgium,Brussels
Denmark,Copenhagen
Norway,Oslo
1 England London
2 Scotland Edinburgh
3 Wales Cardiff
4 France Paris
5 Spain Madrid
6 Germany Berlin
7 Italy Rome
8 Portugal Lisbon
9 Russia Moscow
10 Serbia Belgrade
11 Greece Athens
12 Belgium Brussels
13 Denmark Copenhagen
14 Norway Oslo

View File

@ -1,262 +0,0 @@
// Example use of charset.hh in ../include/charset.hh.
//
// To compile, you need to make charset.hh accessible on the include path.
// Also, charset.hh includes my iconv wrapper, which is in ../include/Incover.hh,
// and depends on other things in that directory; those dependencies could be
// made to go away.
// This source file should be viewed using a UTF8 editor, and its output when run should be
// viewed on a UTF8 terminal.
#include "charset.hh"
#include <iostream>
#include <algorithm>
#include <list>
using namespace pbe;
using namespace std;
void compile_time_tagged_strings_example()
{
// This example declares strings with compile-time-fixed character sets, converts
// them to other compile-time-fixed character sets, combines them, and checks for
// consistency:
cout << "\ncompile_time_tagged_strings_example:\n";
utf8_string french = "Le traité simplifié prêt à être soumis "
"à l'approbation des gouvernements";
latin1_string french_fixed = french.recode<latin1>();
utf8_string icelandic = "Smjörið er brætt og hveitið smátt og smátt hrært út í það";
latin1_string icelandic_fixed = icelandic.recode<latin1>();
utf8_string all = french + icelandic;
latin1_string all_fixed = french_fixed + icelandic_fixed;
if ((all.recode<latin1>() == all_fixed)
&& (all == all_fixed.recode<utf8>())) {
cout << "Pass, both strings are '" << all << "'\n";
}
}
void utf8_const_iterator_example()
{
// This example shows how a string with a variable-width
// character set can be iterated over character-at-a-time
// or "unit"-at-a-time.
cout << "\nutf8_const_iterator_example:\n";
utf8_string s = "Théâtre"; // My editor stores UTF8.
// Iterate "unit" (byte) at a time:
cout << "Here are the bytes of '" << s << "': " << hex;
for (utf8_string::const_iterator i = s.begin();
i != s.end(); ++i) {
char8_t c = *i;
cout << static_cast<unsigned int>(static_cast<uint8_t>(c)) << " ";
}
// Iterate character at a time:
cout << "\nHere are the characters of '" << s << "': ";
for (utf8_string::const_character_iterator i = s.begin();
i != utf8_string::const_character_iterator( s.end() ); ++i) {
utf8_char_t c = *i; // A 32-bit decoded Unicode character
cout << static_cast<unsigned int>(c) << " ";
}
cout << dec << "\n";
}
void utf8_output_iterator_example()
{
// This example shows how a string with a variable-width
// character set can be appended to using push_back and
// an output iterator.
cout << "\nutf8_output_iterator_example:\n";
utf8_string s;
for (utf8_char_t c=64; c<96; ++c) {
s.push_back(c);
}
utf8_string::character_output_iterator i(s);
for (utf8_char_t c=150; c<200; ++c) {
*i++ = c;
// s.push_back(c);
}
cout << "Unicode characters 64 to 95 and 150 to 199:\n"
<< s << "\n";
}
void utf8_word_split_example()
{
// This example demonstrates a case where a "unit" rather than a character iterator for a
// UTF8 string is useful: because bytes < 128 can only ever represent single characters in
// UTF8, we can treat a UTF8 string as a sequence of bytes when spliting at spaces.
cout << "\nutf8_word_split_example:\n";
utf8_string s = "Yo también quemo la Corona española";
utf8_string::const_iterator i = s.begin();
utf8_string::const_iterator e = s.end();
utf8_string::const_iterator j;
do {
j = find(i,e,' ');
utf8_string word(i,j);
cout << word << "\n";
i = j+1;
} while (j != e);
}
void ucs4_line_wrap_example()
{
// Sometimes a random-access character iterator is needed, but an iso_8859 or similar byte
// character set can't be used because the characters in the content are not restricted.
// In this case, ucs4 is normally the best choice - though its requirement for 4 bytes per
// character may be considered a disadvantage in memory-limited applications.
// This example uses random access to break a string into lines of <=40 characters each.
cout << "\nucs4_line_wrap_example:\n";
utf8_string text_var = "Партия Единая Россия отказалась от формирования первой "
"тройки федерального списка - его возглавил только президент "
"Владимир Путин. Такое решение было принято на съезде Единой "
"России во вторник. Накануне президент России дал согласие "
"возглавить список Единой России на выборах в Госдуму.";
ucs4_string text_fixed = text_var.recode<ucs4>();
for (unsigned int i=39; i<text_fixed.length(); i+=40) {
while (text_fixed[i]!=' ') {
--i;
}
text_fixed[i] = '\n';
}
cout << text_fixed.recode<utf8>() << "\n";
}
// This example shows how a library-user can make a new character set available.
// The example is the KOI8 character set, a fixed-width byte character set containing
// cyrillic and latin characters.
////// This section needs some attention from a preprocessor expert; I want to use
////// a counter of some sort to allocate new charset_t values with a macro:
////// PBE_DEFINE_CHARSET(koi8);
////// But I can't see a good way to do it. For the time being, I'll choose a value
////// manually:
const charset_t koi8 = static_cast<charset_t>(25);
// Define charset_traits for KOI8:
namespace pbe {
template <>
struct charset_traits<koi8> {
typedef char8_t unit_t;
typedef char8_t char_t;
};
};
typedef tagged_string<koi8> koi8_string;
void user_defined_charset_example()
{
charset_names[koi8] = "koi8";
cout << "\nuser_defined_charset_example:\n";
// We'll convert a string back and forth between utf8 and koi8:
utf8_string u = "Код Обмена Информацией, 8 бит";
koi8_string k = u.recode<koi8>();
utf8_string u2 = k.recode<utf8>();
// KOI8 is a more compact encoiding than UTF8 for cyrillic:
cout << "Length of UTF8 string = " << u2.length()
<< ", length of KOI8 string = " << k.length() << "\n";
}
void runtime_tagged_example()
{
// This example shows how character sets known only at run-time can be used.
// This is motivated by multipart MIME email, where each part can have a different
// character set. But since MIME is rather complex to parse, this example uses
// the following simpler format: the input byte sequence consists of a character
// set name (in ascii) followed by data using that character set enclosed in {},
// followed by further content in another character set, and so on.
// This example first creates such a message and then decomposes it.
cout << "\nruntime_tagged_example:\n";
// We'll store the hybrid message in a std::string.
string message =
string("utf8{") + "El catalán, moneda lingüística" + "}"
+ "iso-8859-1{" + utf8_string("får årets Nobelpris i litteratur.").recode<latin1>() + "}";
// + "ucs2{" + utf8_string("Директором СВР назначен Михаил Фрадков").recode<ucs2>() + "}";
// Now parse it into a list of run-time-tagged strings:
typedef list<rt_tagged_string> strings_t;
strings_t strings;
string::const_iterator i = message.begin();
string::const_iterator e = message.end();
while (i != e) {
string::const_iterator j = find(i,e,'{');
string charset_name(i,j);
string::const_iterator k = find(j,e,'}');
string content(j+1,k);
rt_tagged_string s(lookup_charset(charset_name),content);
strings.push_back(s);
i = k+1;
}
// Output the parsed strings, converting to UTF8 to do so:
for (strings_t::const_iterator a = strings.begin();
a != strings.end(); ++a) {
utf8_string u = a->recode<utf8>();
cout << u << "\n";
}
}
// The following examples illustrate planned functionality that's not yet implemented:
#if 1
#endif
int main()
{
// These examples work:
compile_time_tagged_strings_example();
utf8_const_iterator_example();
utf8_output_iterator_example();
utf8_word_split_example();
ucs4_line_wrap_example();
runtime_tagged_example();
// These examples don't yet work:
#if 1
user_defined_charset_example();
#endif
return 0;
}

View File

@ -1,115 +0,0 @@
// This is an example of the const_string_facade class.
//
// We have a file containing names of countries and their capital cities:
//
// England,London
// Scotland,Edinburgh
// Wales,Cardiff
// etc. etc.
//
// We want to read this in and to store it in a std::map from country name to
// capital city name. This is simple enough to do, but the normal approach has
// the disadvantage that the data is copied out of the buffer into strings
// which are stored in the map. Avoiding this extra copy could be a useful
// thing to do. So instead of using std::strings we'll invent a new class,
// stringref, which just contains a pair of pointers; these point into the
// buffer containing the raw data which is never copied.
//
// const_string_facade is used to make the pair-of-pointers class behave like
// a const std::string: it provides implementations of all the normal member
// and free functions. So we can store them in a map output them and so on.
#include "const_string_facade.hh"
#include <iostream>
#include <string>
#include <map>
#include <algorithm>
#include "FileDescriptor.hh"
using namespace std;
using namespace pbe;
class stringref: public const_string_facade<stringref,char,false> {
// The template parameters are:
// - The derived class (this the the "CRTP").
// - The character type.
// - A bool indicating that the strings are not null-terminated.
public:
stringref(): begin_ptr(NULL), end_ptr(NULL) {}
stringref(const char* b, const char* e): begin_ptr(b), end_ptr(e) {}
private:
const char* begin_ptr;
const char* end_ptr;
// Here are the accessors that const_string_facade needs. Since these
// are private we need to make it a friend.
friend class const_string_facade<stringref,char,false>;
const char* get_begin() const { return begin_ptr; }
const char* get_end() const { return end_ptr; }
};
int main(int argc, char* argv[])
{
if (argc!=3) {
cerr << "Usage: " << argv[0] << " csv-file some-string\n";
exit(1);
}
string fn = argv[1];
string some_string = argv[2];
FileDescriptor f(fn, FileDescriptor::read_only);
char buf[4096];
char* buf_end = buf + f.readmax(buf,sizeof(buf));
typedef map<stringref,stringref> capitals_t;
capitals_t capitals;
char* ptr = buf;
while (ptr<buf_end) {
char* comma_pos = find(ptr,buf_end,',');
char* newline_pos = find(comma_pos,buf_end,'\n');
stringref country(ptr,comma_pos);
stringref city(comma_pos+1,newline_pos);
capitals[country] = city;
ptr = newline_pos+1;
}
for (capitals_t::const_iterator i = capitals.begin();
i != capitals.end(); ++i) {
cout << "The capital of " << i->first << " is " << i->second << "\n";
}
const char* vowels = "aeiouAEIOU";
for (capitals_t::const_iterator i = capitals.begin();
i != capitals.end(); ++i) {
const stringref country = i->first;
size_t first_vowel_pos = country.find_first_of(vowels);
size_t last_consonant_pos = country.find_last_not_of(vowels);
cout << "The first vowel in " << country << " is " << country[first_vowel_pos]
<< " and the last consonant is " << country[last_consonant_pos] << "\n";
size_t ss_pos = country.find(some_string);
if (ss_pos != stringref::npos) {
cout << " '" << country << "' contains '" << some_string << "' at position " << ss_pos << "\n";
}
}
// Hopefully, a stringref has no overhead on top of the two pointers:
cout << "sizeof(stringref) = " << sizeof(stringref) << "\n";
return 0;
}

View File

@ -1,70 +0,0 @@
// examples/directory_explorer.cc
// This file is part of libpbe; see http://decimail.org
// (C) 2006 Philip Endecott
// 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 2 of the License, or
// 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, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
// Example for use of StringTransformer class
// Demonstrate the libpbe::Directory class and get_filetype.
// Main program takes a directory name and recursively prints the filenames
// below it.
#include <iostream>
#include "Directory.hh"
#include "FileType.hh"
#include "Exception.hh"
using namespace std;
using namespace libpbe;
void explore(Directory& d)
{
for (Directory::const_iterator i = d.begin();
i != d.end(); ++i) {
cout << i->pathname << "\n";
if (get_filetype(i->pathname)==directory) {
Directory subdir(i->pathname);
explore(subdir);
}
}
}
int main(int argc, char* argv[])
{
try { try {
if (argc!=2) {
cerr << "usage:\n"
<< " directory_recursor <directory name>\n";
exit(1);
}
string dirname = argv[1];
Directory d(dirname);
explore(d);
exit(0);
} RETHROW_MISC_EXCEPTIONS }
catch (Exception& E) {
E.report(cerr);
exit(1);
}
}

View File

@ -1,42 +0,0 @@
#include <iostream>
#include "fixed.hh"
#include "safe_int.hh"
using namespace std;
using namespace pbe;
typedef pbe::fixed<16,8> f1;
typedef pbe::fixed<16,10> f2;
int main(int argc, char* argv[])
{
f1 a;
f2 b;
f1 c;
f2 d;
pbe::fixed<24,26> e;
a = 0.25;
b = 128;
c = a+b;
d = c * a;
e = d / a;
cout << "a=" << static_cast<double>(a) << " (a.val = " << a.val << ")\n";
cout << "b=" << static_cast<double>(b) << " (b.val = " << b.val << ")\n";
cout << "c=" << static_cast<double>(c) << " (c.val = " << c.val << ")\n";
cout << "d=" << static_cast<double>(d) << " (d.val = " << d.val << ")\n";
cout << "e=" << static_cast<double>(e) << " (e.val = " << e.val << ")\n";
typedef pbe::fixed<8,5,pbe::safe_int<13> > f_t;
f_t f;
f = a;
while (1) {
f = f+f;
cout << "f=" << static_cast<double>(f) << "\n";
}
}

View File

@ -1,50 +0,0 @@
// examples/gunzip.cc
// This file is part of libpbe; see http://svn.chezphil.org/libpbe/
// (C) 2008 Philip Endecott
// 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 2 of the License, or
// 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, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "Gunzipper.hh"
#include "FileDescriptor.hh"
#include <string>
#include <iostream>
using namespace std;
using namespace pbe;
int main(int argc, char* argv[])
{
if (argc!=2) {
cerr << "Usage: gunzip <file.gz>\n";
return 1;
}
string fn = argv[1];
FileDescriptor fd(fn,FileDescriptor::read_only);
string in = fd.readall();
Gunzipper gz;
string out = gz(in);
cout << out;
return 0;
}

View File

@ -1,56 +0,0 @@
// examples/http_get.cc
// This file is part of libpbe; see http://svn.chezphil.org/libpbe/
// (C) 2008 Philip Endecott
// 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 2 of the License, or
// 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, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "HttpClient.hh"
#include "HttpResponse.hh"
#include "Exception.hh"
#include <iostream>
#include <string>
using namespace pbe;
using namespace std;
int main(int argc, char* argv[])
{
try { try {
if (argc!=2) {
cerr << "Usage: http_get <URI>\n";
exit(1);
}
string uri = argv[1];
HttpClient http_client;
HttpResponse response = http_client.get(uri);
cout << response.body;
return 0;
} RETHROW_MISC_EXCEPTIONS }
catch (Exception& E) {
E.report(cerr);
exit(E.exit_status);
}
}

View File

@ -1,54 +0,0 @@
// examples/http_get_bunzip.cc
// This file is part of libpbe; see http://svn.chezphil.org/libpbe/
// (C) 2008 Philip Endecott
// 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 2 of the License, or
// 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, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "HttpClient.hh"
#include "Exception.hh"
#include <iostream>
#include <string>
using namespace pbe;
using namespace std;
int main(int argc, char* argv[])
{
try { try {
if (argc!=3) {
cerr << "Usage: http_get_bunzip <URI.bz> <fn>\n";
exit(1);
}
string uri = argv[1];
string fn = argv[2];
HttpClient http_client;
http_client.get_bunzip_save(uri,fn);
return 0;
} RETHROW_MISC_EXCEPTIONS }
catch (Exception& E) {
E.report(cerr);
exit(E.exit_status);
}
}

View File

@ -1,61 +0,0 @@
// examples/http_get_gunzip.cc
// This file is part of libpbe; see http://svn.chezphil.org/libpbe/
// (C) 2008 Philip Endecott
// 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 2 of the License, or
// 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, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "HttpClient.hh"
#include "Gunzipper.hh"
#include "Exception.hh"
#include <iostream>
#include <string>
using namespace pbe;
using namespace std;
int main(int argc, char* argv[])
{
try { try {
if (argc!=3) {
cerr << "Usage: http_get_gunzip <URI.bz> <fn>\n";
exit(1);
}
string uri = argv[1];
string fn = argv[2];
try {
HttpClient http_client;
http_client.get_gunzip_save(uri,fn);
}
catch (Gunzipper::InvalidData& E) {
cerr << "Gunzipper::InvalidData\n";
exit(1);
}
return 0;
} RETHROW_MISC_EXCEPTIONS }
catch (Exception& E) {
E.report(cerr);
exit(E.exit_status);
}
}

View File

@ -1,55 +0,0 @@
// examples/http_get.cc
// This file is part of libpbe; see http://svn.chezphil.org/libpbe/
// (C) 2008 Philip Endecott
// 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 2 of the License, or
// 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, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "HttpClient.hh"
#include "HttpResponse.hh"
#include "Exception.hh"
#include <iostream>
#include <string>
using namespace pbe;
using namespace std;
int main(int argc, char* argv[])
{
try { try {
if (argc!=3) {
cerr << "Usage: http_get_with_etag <URI> <fn>\n";
exit(1);
}
string uri = argv[1];
string fn = argv[2];
HttpClient http_client;
http_client.get_save_with_etag(uri,fn);
return 0;
} RETHROW_MISC_EXCEPTIONS }
catch (Exception& E) {
E.report(cerr);
exit(E.exit_status);
}
}

View File

@ -1,134 +0,0 @@
// examples/inc_daemon.cc
// This file is part of libpbe; see http://decimail.org
// (C) 2004 Philip Endecott
// 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 2 of the License, or
// 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, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
// Demo program for Daemon class
// The Daemon class does the mucky stuff needed to implement a
// "daemon" (i.e. a server, e.g. imapd, httpd etc) process.
// You make a subclass of Daemon that:
// * Provides "void session(int in_fd, int out_fd)" that does the work.
// File descriptors for input and output to the connection are supplied.
// * Calls the Daemon base class constructor with port number, program
// name (used in syslog calls) and optional syslog "facility" code (see
// man syslog).
//
// Your main program then creates an instance of your Daemon subclass and
// invokes one of three run_*() methods, as shown below.
// This example implements a trivial "inc" daemon that reads a number
// from the user, increments it, and returns the incremented value.
// libpbe includes:
#include "Daemon.hh"
#include "Exception.hh"
// Standard includes:
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
using namespace std;
// To demonstrate exception handling, if the user enters 666 this
// exception is thrown.
class NumberOfTheBeast: public Exception {
public:
void report(ostream& s) {
s << "The number of the beast!" << endl;
}
};
class IncDaemon: public Daemon {
public:
IncDaemon(void): Daemon(1705,"inc_daemon") {}
// Here is the session function that is called to handle a new
// connection. It is run in its own thread.
void session(int in_fd, int out_fd)
{
// I don't know how to make a C++ stream from a file descriptor.
FILE* inf = fdopen(in_fd,"r");
FILE* outf = fdopen(out_fd,"w");
fprintf(outf,"Please enter numbers to increment.\n");
int r=1;
// check for EOF is important - it indicates connection is closed
while(!feof(inf) && !ferror(inf) && !ferror(outf)) {
fprintf(outf,"> ");
fflush(outf);
int n;
r = fscanf(inf,"%d",&n);
if (r==0 || r==EOF) {
break;
}
if (n==666) {
throw NumberOfTheBeast();
}
fprintf(outf,"--->%d<---\n",n+1);
}
if (r==0) {
fprintf(outf,"fscanf() didn't get a number\n");
}
if (r==EOF) {
fprintf(outf,"fscanf() returned EOF\n");
}
if (feof(inf)) {
fprintf(outf,"EOF on input\n");
}
if (ferror(inf)) {
fprintf(outf,"Error on input(!)\n");
}
if (ferror(outf)) {
fprintf(outf,"Error on output(!)\n");
}
fflush(outf);
}
};
int main(int argc, char* argv[])
{
IncDaemon d;
if (argc==1) {
// Guess whether to run in interactive or daemon mode based on isatty(0)
d.run_default();
} else if (argc==2) {
string a(argv[1]);
if (a=="-i") {
// Run interactively, i.e. not a daemon at all
d.run_interactively();
} else if (a=="-d") {
// Run as a daemon
cout << "Daemon about to start. Telnet to port 1705." << endl;
d.run_as_daemon();
} else {
cerr << "Unrecognised option '" << a << "'" << endl;
exit(1);
}
} else {
cerr << "Too many options" << endl;
exit(1);
}
}

View File

@ -1,190 +0,0 @@
// examples/mailform.cc
// This file is part of libpbe; see http://decimail.org
// (C) 2004 Philip Endecott
// 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 2 of the License, or
// 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, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
// MAILFORM
// --------
// This is a demonstration of the libpbe CgiParams and SmtpClient
// classes. It is a CGI program that implements the backend of a
// feedback form, or similar. The user completes a form on a web page
// and submits it to this script, which forwards its content as an
// email message.
// The important bits of the form look like this:
// <form method="post" action="URL of this CGI program">
// <input type="text" name="name">
// <input type="text" name="email">
// <textarea name="message"></textarea>
// <input type="hidden" name="nextpage" value="feedback_received.html">
// </form>
//
// feedback_received.html is the page that will be shown when the
// message has been sucessfully sent.
//
// You can also note from which page the user clicked on the "feedback
// form" page using a tad of javascript (which will not mess up
// non-javascript browsers):
// <script language="javascript" type="text/javascript">
// <!--
// document.writeln('<input type="hidden" name="page" value="'+document.referrer+'">');
// // -->
// </script>
// (Put this inside the <form> element, obviously.)
// libpbe includes:
#include "CgiParams.hh"
#include "SmtpClient.hh"
// Standard includes:
#include <stdlib.h>
#include <iostream>
#include <string>
using namespace std;
// The values can be redefined using -D when compiling. You at least
// need to supply sensible values for SENDER and RECIPIENT.
// From address if the user doesn't specify one:
#ifndef ANON_ADDR
#define ANON_ADDR "anonymous"
#endif
// From address if the user doesn't specify one:
#ifndef SENDER
#define SENDER "webpage@this_machine"
#endif
// Define the recipient of the emails here:
#ifndef RECIPIENT
#define RECIPIENT "feedback@some_domain"
#endif
// SMTP server to connect to:
#ifndef SMTP_SERVER
#define SMTP_SERVER "localhost"
#endif
// Our own domain name, as announced to the SMTP server when the
// connection is established:
#ifndef OWN_DOMAIN
#define OWN_DOMAIN "localhost"
#endif
int main (int argc, char* argv[])
{
// This must be called from a web server as a CGI program. Give up
// immediately if that doesn't seem to be the case. (CGI sets
// various environment variables, of which QUERY_STRING is one.)
if (!getenv("QUERY_STRING")) {
cerr << "This program must be invoked using CGI." << endl;
exit(1);
}
// This is my standard idiom for top-level exception handling, see
// below.
try { try {
// Create a CgiParams object and load it from the environment. We
// don't need to know the details of what this is doing, just that
// it can cope with all of the variants of CGI encoding.
CgiParams params;
params.load();
// Get the form values. get_default() substitutes the supplied
// default if no parameter with that name was supplied. get()
// throws an exception in this case. operator[] can be used if
// you are certain that the parameter is present (like a
// std::map).
string name = params.get_default("name","(none)");
string email = params.get_default("email","(none)");
string page = params.get_default("page","(none)");
string message = params.get("message");
string nextpage = params.get_default("nextpage","index.html");
// Now construct the message. This needs to be a complete message
// in RFC822 (aka RFC2822 which is easier to read) format.
// Do PLEASE ensure that your DATE is in the correct RFC822
// format! And, if you ever write code to parse an email, be
// prepared for dates in just about any misformat you can imagine.
// I speak from experience.
char datetime[36];
time_t t;
time(&t);
struct tm tm;
localtime_r(&t,&tm);
strftime(datetime,sizeof(datetime),"%a, %d %b %Y %H:%M:%S %z",&tm);
// If the user gave an email address, we can give it here as the
// from address. That makes it easy to reply to the right place.
// On the other hand it might break if you have a spam-filtering
// system like SPF in place (anyone know the magic to avoid this?)
string from_addr = (email=="" || email=="(none)") ? ANON_ADDR : email;
string rfc822_message =
"Sender: " + string(SENDER) + "\r\n"
"From: " + from_addr + "\r\n"
"To: " + RECIPIENT + "\r\n"
"Subject: " + "Feedback form" + "\r\n"
"Date: " + datetime + "\r\n"
"\r\n"
"Name: " + name + "\r\n"
"Email: " + email + "\r\n"
"Page: " + page + "\r\n\r\n"
"Message:\r\n" + message + "\r\n";
// Now create the SMTP client.
// If you want to see what is going on on the SMTP connection, you
// can enable logging to syslog by defining SYSLOG in
// SmtpClient.cc.
SmtpClient smtpc;
// Make an SMTP connection to the server
smtpc.connect(SMTP_SERVER,OWN_DOMAIN);
// Send the message
smtpc.send_msg(SENDER,RECIPIENT,rfc822_message);
// Done, disconnect.
smtpc.disconnect();
// Final thing to do is to redirect to the "message sent" HTML page.
cout << "Location: " << nextpage << "\r\n\r\n";
// All done.
exit(0);
// My standard exception handling magic. This converts any odd
// exception types, like char* from 'throw "something bad";', into
// an Exception.
} RETHROW_MISC_EXCEPTIONS }
catch (Exception& E) {
cout << "content-type: text/plain\r\n\r\n"
<< "An error has occured:\r\n";
E.report(cout);
exit(0);
}
}

View File

@ -1,64 +0,0 @@
// examples/recode.cc
// This file is part of libpbe; see http://decimail.org
// (C) 2004 Philip Endecott
// 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 2 of the License, or
// 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, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
// Demo program for libpbe Recoder class
// C++ interface to the recode library
// Convert between character sets e.g. ISO-8859-n to/from unicode
// Also CR to CRLF, do base64 coding and the like
#include "Recoder.hh"
// Create a converter as a global object of class Recoder.
// (There is startup overhead; doesn't have to be global, but is probably
// best in most cases. Don't create and destroy them all over the place)
// In this case, convert LF line endings (the default) to Microsfot-style
// CR-LF line endings.
Recoder lf_to_crlf ( "", "/CR-LF" );
// Parameters to constructor are "from" and "to" character sets.
// See recode documentation for details (info recode)
// Just a few examples:
// ASCII 7-bit ASCII
// ISO-8859-1 8-bit ISO-8859-1 (Latin 1; Western European languages)
// ISO-8859-15 8-bit ISO-8859-15 (ditto plus Euro symbol)
// UTF-8 8-bit Unicode
// UCS-2 16-bit Unicode
// /CR CR for end-of-line (Apple)
// /CR-LF CR-LF for end-of-line (Microsoft)
// [LF is default, use empty string]
// /Base64 Base 64 encoding (used for email attachments)
// /Decimal-1 Output decimal values for each character (for debugging)
// Having created to Recoder object, use it as a function (on strings) to
// actually do the conversion:
#include <string>
#include <iostream>
using namespace std;
int main(int argc, char* argv[])
{
string s = "Hello\nWorld\n";
string t = lf_to_crlf(s);
cout << s << ' ' << t;
}
// Need to link with -lrecode
// Pipe this program into "od -a" to see what is going on.

View File

@ -1,31 +0,0 @@
#include <iostream>
#include "safe_int.hh"
#include "Exception.hh"
using namespace std;
using namespace pbe;
typedef safe_int<7> safe_byte;
int main(int argc, char* argv[])
{
try { try {
safe_byte a = 1;
for (int i=0; i<1024; ++i) {
cout << "a = " << a << "\n";
a = a * static_cast<safe_byte>(3);
}
return 0;
} RETHROW_MISC_EXCEPTIONS }
catch (Exception& E) {
E.report(cerr);
}
}

View File

@ -1,26 +0,0 @@
#include "sort_by.hh"
#include <vector>
using namespace std;
using namespace pbe;
struct A {
int x;
int y;
bool z;
A(int x_, int y_, bool z_): x(x_), y(y_), z(z_) {}
};
int main()
{
std::vector<A> v;
v.push_back(A(1,2,true));
v.push_back(A(3,4,false));
v.push_back(A(9,0,true));
sort_by(v.begin(),v.end(),&A::y);
}

View File

@ -1,26 +0,0 @@
#include "sort_by_pointee.hh"
#include <vector>
using namespace std;
using namespace pbe;
struct A {
int x;
int y;
bool z;
A(int x_, int y_, bool z_): x(x_), y(y_), z(z_) {}
};
int main()
{
std::vector<A*> v;
v.push_back(new A(1,2,true));
v.push_back(new A(3,4,false));
v.push_back(new A(9,0,true));
sort_by_pointee(v.begin(),v.end(),&A::y);
}

View File

@ -1,31 +0,0 @@
#include <list>
#include <iostream>
#include "sorted_ptr_vector.hh"
using namespace std;
using namespace pbe;
struct A {
int x;
int y;
int z;
A(int x_, int y_, int z_): x(x_), y(y_), z(z_) {};
};
int main()
{
list<A*> l;
l.push_back(new A(1,2,3));
l.push_back(new A(5,4,3));
l.push_back(new A(2,3,2));
typedef sorted_ptr_vector<A, int A::*, &A::z> v_t;
v_t v(l.begin(),l.end());
for (v_t::const_iterator i = v.begin(); i != v.end(); ++i) {
cout << (*i)->x << "," << (*i)->y << "," << (*i)->z << "\n";
}
}

View File

@ -1,33 +0,0 @@
#include <string>
#include <vector>
#include <iostream>
#include "string_qsort.hh"
using namespace std;
using namespace pbe;
int main()
{
typedef vector<string> data_t;
data_t data;
while (cin.good()) {
string s;
getline(cin,s);
data.push_back(s);
}
string_qsort(data.begin(), data.end());
// Or try this for comparison:
// std::sort(data.begin(), data.end());
// The result should be the same.
for (data_t::const_iterator i = data.begin();
i != data.end(); ++i) {
cout << *i << "\n";
}
}

View File

@ -1,59 +0,0 @@
// examples/transform_strings.cc
// This file is part of libpbe; see http://decimail.org
// (C) 2004 Philip Endecott
// 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 2 of the License, or
// 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, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
// Example for use of StringTransformer class
// Create a string transformer object to transform strings.
// Create the object once (a bit expensive) and use it many time (cheapish)
// For example: transform a string to escape quotes, make upper case etc.
#include "StringTransformer.hh"
#include <iostream>
#include <sstream>
using namespace std;
bool is_ctrl(char c) {
return c<32;
}
string to_escseq(char c) {
ostringstream s;
s << '\\' << static_cast<int>(c);
return s.str();
}
int main(int argc, char* argv[])
{
StringTransformer escape_quotes;
escape_quotes.add_cs_rule('\"', "\\\""); // replace " with \"
StringTransformer escape_ctrl;
escape_ctrl.add_pf_rule(is_ctrl, to_escseq);
while (1) {
char buf[128];
cin.getline(buf,sizeof(buf));
string s(buf);
cout << "Escape quotes: " << escape_quotes(s) << endl;
cout << "Escape ctrls: " << escape_ctrl(s) << endl;
}
}

View File

@ -1,59 +0,0 @@
// Array2d.hh
// This file is part of libpbe; see http://anyterm.org/
// (C) 2006 Philip Endecott
// 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 2 of the License, or
// 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, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#ifndef libpbe_Array2d_hh
#define libpbe_Array2d_hh
#include <vector>
namespace pbe {
template <typename T, typename Impl=std::vector<T> >
class Array2d {
public:
Array2d(unsigned int w, unsigned int h):
data(w*h), width_(w), height_(h)
{}
Array2d(unsigned int w, unsigned int h, T value):
data(w*h,value), width_(w), height_(h)
{}
const T& operator()(unsigned int x, unsigned int y) const {
return data[y*width_ + x];
}
T& operator()(unsigned int x, unsigned int y) {
return data[y*width_ + x];
}
unsigned int width() const { return width_; }
unsigned int height() const { return height_; }
private:
Impl data;
const unsigned int width_;
const unsigned int height_;
};
};
#endif

View File

@ -1,132 +0,0 @@
// AtomicCounter.hh
// This file is part of libpbe; see http://decimail.org/
// (C) 2007 Philip Endecott
// 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 2 of the License, or
// 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, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#ifndef libpbe_AtomicCounter_hh
#define libpbe_AtomicCounter_hh
// Atomic (i.e. thread-safe) counter. Uses the gcc atomic builtins, except on ARM
// where they are not available. On ARM it uses a swap instruction, using -1 as a sentinel
// value (and has one fewer useful bits as a consequence; code should allow for the counter
// wrapping after 31 or 32 bits). It normally spins if it can't get the lock, but you can define
// YIELD_WHEN_LOCKED to make it yield in that case. Contention should be extremely rare.
// FIXME this should use atomic.hh. It should also test whether the gcc builtins are
// available.
#include <stdint.h>
#if defined(__arm__) && defined(YIELD_WHEN_LOCKED)
#include <sched.h>
#endif
namespace pbe {
#ifdef __arm__
static inline int32_t arm_atomic_read_and_lock(int32_t& mem)
{
int32_t val;
do {
// Equivalent to:
// val = mem;
// mem = -1;
asm volatile ("swp\t%0, %1, [%2]"
:"=&r"(val)
:"r" (-1),
"r" (&mem)
:"memory");
if (val != -1) {
break;
}
#ifdef YIELD_WHEN_LOCKED
sched_yield();
#endif
} while (1);
return val;
}
static inline int32_t arm_atomic_inc(int32_t& mem, int32_t inc)
{
return mem = (arm_atomic_read_and_lock(mem)+inc) & 0x7fffffff;
}
static inline int32_t arm_atomic_inc_pre(int32_t& mem, int32_t inc)
{
int32_t r = arm_atomic_read_and_lock(mem);
mem = (r+inc) & 0x7fffffff;
return r;
}
#endif
class AtomicCounter {
int c;
public:
AtomicCounter():
c(0)
{}
AtomicCounter(int n):
c(n)
{}
int operator++() { // ++n
#ifdef __arm__
return arm_atomic_inc(c, 1);
#else
return __sync_add_and_fetch(&c, 1);
#endif
}
int operator++(int) { // n++
#ifdef __arm__
return arm_atomic_inc_pre(c, 1);
#else
return __sync_fetch_and_add(&c, 1);
#endif
}
int operator--() { // --n
#ifdef __arm__
return arm_atomic_inc(c, -1);
#else
return __sync_add_and_fetch(&c, -1);
#endif
}
int operator--(int) { // n--
#ifdef __arm__
return arm_atomic_inc_pre(c, -1);
#else
return __sync_fetch_and_add(&c, -1);
#endif
}
};
};
#endif

View File

@ -1,134 +0,0 @@
// include/Box.hh
// This file is part of libpbe
// (C) 2007 Philip Endecott
// 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 2 of the License, or
// 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, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#ifndef pbe_Box_hh
#define pbe_Box_hh
#include "Point.hh"
#include <algorithm>
namespace pbe {
template<typename COORD_T,
typename AREA_T = COORD_T>
struct Box {
typedef COORD_T coord_t;
typedef AREA_T area_t;
typedef typename pbe::Point<coord_t> point_t;
coord_t x0;
coord_t y0;
coord_t x1;
coord_t y1;
Box() {}
Box(const Box<coord_t>& other):
x0(other.x0), y0(other.y0), x1(other.x1), y1(other.y1)
{}
Box(coord_t x0_, coord_t y0_, coord_t x1_, coord_t y1_):
x0(x0_), y0(y0_), x1(x1_), y1(y1_)
{}
Box(point_t x0y0, point_t x1y1):
x0(x0y0.x), y0(x0y0.y), x1(x1y1.x), y1(x1y1.y)
{}
Box(point_t x0y0, coord_t w, coord_t h):
x0(x0y0.x), y0(x0y0.y), x1(x0y0.x+w), y1(x0y0.y+h)
{}
coord_t width() const { return x1-x0; }
coord_t height() const { return y1-y0; }
point_t x0y0() const {
return point_t(x0,y0);
}
point_t x0y1() const {
return point_t(x0,y1);
}
point_t x1y0() const {
return point_t(x1,y0);
}
point_t x1y1() const {
return point_t(x1,y1);
}
bool contains(point_t p) const {
return p.x>=x0 && p.x<x1 && p.y>=y0 && p.y<y1;
}
bool contains(Box b) const {
return contains(b.x0y0()) && contains(b.x1y1());
}
void displace(coord_t dx, coord_t dy) {
x0 += dx;
x1 += dx;
y0 += dy;
y1 += dy;
}
bool operator==(const Box& other) const {
return x0==other.x0 && x1==other.x1 && y0==other.y0 && y1==other.y1;
}
};
template <typename COORD_T>
inline bool overlap(const Box<COORD_T>& lhs, const Box<COORD_T>& rhs) {
return lhs.x0<=rhs.x1 && lhs.x1>=rhs.x0
&& lhs.y0<=rhs.y1 && lhs.y1>=rhs.y0;
}
template <typename BOX_T>
inline typename BOX_T::area_t area(BOX_T box) {
return box.width() * box.height();
}
template <typename BOX_T>
inline void expand_box(BOX_T& box, typename BOX_T::point_t point){
box.x0 = min(box.x0,point.x);
box.y0 = min(box.y0,point.y);
box.x1 = max(box.x1,point.x);
box.y1 = max(box.y1,point.y);
}
template <typename BOX_T>
inline BOX_T intersect(const BOX_T& b1, const BOX_T& b2) {
return BOX_T( std::max(b1.x0, b2.x0),
std::max(b1.y0, b2.y0),
std::min(b1.x1, b2.x1),
std::min(b1.y1, b2.y1) );
}
};
#endif

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