Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
G
guestbook
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
jan.koester
guestbook
Commits
20955d91
Commit
20955d91
authored
1 year ago
by
jan.koester
Browse files
Options
Downloads
Patches
Plain Diff
initial commit
parent
f4e2f7d9
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
CMakeLists.txt
+19
-0
19 additions, 0 deletions
CMakeLists.txt
guest.html
+37
-0
37 additions, 0 deletions
guest.html
guest.txt
+8
-0
8 additions, 0 deletions
guest.txt
main.cpp
+129
-0
129 additions, 0 deletions
main.cpp
with
193 additions
and
0 deletions
CMakeLists.txt
0 → 100644
+
19
−
0
View file @
20955d91
cmake_minimum_required
(
VERSION 3.0
)
find_package
(
libnetplus REQUIRED
)
find_package
(
libcryptplus REQUIRED
)
find_package
(
httppp REQUIRED
)
project
(
guestbook
)
add_executable
(
guestbook main.cpp
)
target_include_directories
(
guestbook
PUBLIC
${
httppp_INCLUDE_DIRECTORIES
}
${
htmlpp_INCLUDE_DIRECTORIES
}
${
netplus_INCLUDE_DIRECTORIES
}
)
target_link_libraries
(
guestbook
${
httppp_LIBRARIES
}
netplus htmlpp
)
This diff is collapsed.
Click to expand it.
guest.html
0 → 100644
+
37
−
0
View file @
20955d91
<!DOCTYPE html>
<html
lang=
""
>
<head>
<meta
charset=
"utf-8"
>
<title>
Guestbook
</title>
<style>
body
{
background
:
rgb
(
61
,
174
,
233
);
}
#book
div
{
background
:
rgb
(
252
,
233
,
20
);
margin
:
10px
0
;
}
#book
li
{
list-style
:
none
;
}
#book
ul
{
margin
:
0
;
padding
:
0
;
}
</style>
</head>
<body>
<div
id=
"gform"
>
<form
action=
""
method=
"POST"
>
<h1>
Bitte Schreiben sie etwas.
</h1>
<label
for=
"fname"
>
Name:
</label>
<input
type=
"text"
name=
"guestname"
id=
"guestname"
/>
<label
for=
"fname"
>
Text:
</label>
<input
type=
"text"
name=
"guestentry"
id=
"guestentry"
/>
<input
type=
"submit"
value=
"Posten"
/>
</form>
</div>
<div
id=
"book"
>
</div>
</body>
</html>
This diff is collapsed.
Click to expand it.
guest.txt
0 → 100644
+
8
−
0
View file @
20955d91
Jan|testeintrag
Jonas|testeintrag2
Torben|testeintrag3
Peter|Viele Grüße
Anna|Liebe Grüße
Anna|Liebe Grüße
Helmut|Tolle Sonnenbrillen
Helmut|Tolle Sonnenbrillen
This diff is collapsed.
Click to expand it.
main.cpp
0 → 100644
+
129
−
0
View file @
20955d91
#include
<algorithm>
#include
<cstring>
#include
<iostream>
#include
<fstream>
#include
<mutex>
#include
<httppp/http.h>
#include
<httppp/httpd.h>
#include
<htmlpp/html.h>
std
::
mutex
file_mutex
;
class
Controller
:
public
netplus
::
event
{
public:
Controller
(
netplus
::
socket
*
serversocket
,
libhtmlpp
::
HtmlElement
*
tpl
)
:
event
(
serversocket
){
_tpl
=
tpl
;
};
void
RequestEvent
(
netplus
::
con
*
curcon
){
libhttppp
::
HttpRequest
curreq
;
try
{
curreq
.
parse
(
curcon
);
libhttppp
::
HttpForm
gform
;
try
{
std
::
string
guestname
,
guestentry
;
gform
.
parse
(
&
curreq
);
for
(
libhttppp
::
HttpForm
::
UrlcodedFormData
*
cururlform
=
gform
.
getUrlcodedFormData
();
cururlform
;
cururlform
=
cururlform
->
nextUrlcodedFormData
())
{
if
(
strcmp
(
"guestname"
,
cururlform
->
getKey
())
==
0
){
guestname
=
cururlform
->
getValue
();
}
else
if
(
strcmp
(
"guestentry"
,
cururlform
->
getKey
())
==
0
){
guestentry
=
cururlform
->
getValue
();
}
std
::
cout
<<
cururlform
->
getKey
()
<<
std
::
endl
;
}
if
(
!
guestname
.
empty
()
&&
!
guestentry
.
empty
()){
std
::
string
entry
;
entry
=
guestname
;
entry
+=
"|"
;
entry
+=
guestentry
;
file_mutex
.
lock
();
std
::
ofstream
guestfile_out
(
"guest.txt"
,
std
::
ios
::
app
);
if
(
guestfile_out
.
is_open
())
guestfile_out
<<
entry
<<
"
\n
"
;
guestfile_out
.
close
();
file_mutex
.
unlock
();
}
}
catch
(...){
}
libhtmlpp
::
HtmlElement
site
;
site
=
_tpl
;
libhttppp
::
HttpResponse
resp
;
resp
.
setState
(
HTTP200
);
resp
.
setVersion
(
HTTPVERSION
(
2.0
));
resp
.
setContentLength
(
0
);
file_mutex
.
lock
();
std
::
string
line
;
std
::
ifstream
guestfile
(
"guest.txt"
);
libhtmlpp
::
HtmlElement
guestul
(
"ul"
);
if
(
!
guestfile
.
is_open
()){
libhttppp
::
HTTPException
e
;
e
[
libhttppp
::
HTTPException
::
Error
]
<<
"could not open guest.txt"
;
throw
e
;
}
while
(
getline
(
guestfile
,
line
)
){
std
::
string
name
,
entry
;
int
deli
=
line
.
find
(
'|'
);
name
=
line
.
substr
(
0
,
deli
);
entry
=
line
.
substr
(
deli
+
1
,
line
.
length
()
-
(
deli
+
1
));
libhtmlpp
::
HtmlElement
guestli
(
"li"
);
libhtmlpp
::
HtmlString
gentry
;
gentry
<<
"<div><span class=
\"
guest_author
\"
>"
<<
name
<<
":<br></span><span class=
\"
guest_entry
\"
>"
<<
entry
<<
"</span></div>"
;
guestli
.
appendChild
(
gentry
.
parse
());
guestul
.
appendChild
(
&
guestli
);
}
guestfile
.
close
();
file_mutex
.
unlock
();
libhtmlpp
::
HtmlElement
*
book
=
site
.
getElementbyID
(
"book"
);
if
(
book
){
book
->
appendChild
(
&
guestul
);
}
std
::
string
hdoc
;
libhtmlpp
::
print
(
&
site
,
nullptr
,
hdoc
);
resp
.
send
(
curcon
,
hdoc
.
c_str
(),
hdoc
.
length
());
}
catch
(
libhttppp
::
HTTPException
&
e
)
{
if
(
e
.
getErrorType
()
!=
libhttppp
::
HTTPException
::
Note
)
{
libhttppp
::
HttpResponse
curres
;
curres
.
setState
(
HTTP500
);
curres
.
setVersion
(
HTTPVERSION
(
2.0
));
curres
.
setContentLength
(
0
);
curres
.
send
(
curcon
,
e
.
what
(),
strlen
(
e
.
what
()));
}
}
}
private
:
libhtmlpp
::
HtmlElement
*
_tpl
;
};
class
HttpConD
:
public
libhttppp
::
HttpD
{
public:
HttpConD
(
int
argc
,
char
**
argv
,
libhtmlpp
::
HtmlElement
*
tpl
)
:
HttpD
(
argc
,
argv
){
libhttppp
::
HTTPException
httpexception
;
try
{
Controller
controller
(
getServerSocket
(),
tpl
);
controller
.
runEventloop
();
}
catch
(
libhttppp
::
HTTPException
&
e
){
std
::
cerr
<<
e
.
what
()
<<
std
::
endl
;
}
};
private
:
};
int
main
(
int
argc
,
char
**
argv
){
libhtmlpp
::
HtmlPage
page
;
HttpConD
(
argc
,
argv
,
page
.
loadFile
(
"guest.html"
));
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment