1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
|
diff -rup fatrat-1.2.0_beta2/CMakeLists.txt fatrat-1.2.0_beta2.new/CMakeLists.txt
--- fatrat-1.2.0_beta2/CMakeLists.txt 2012-07-14 12:44:27.000000000 +0100
+++ fatrat-1.2.0_beta2.new/CMakeLists.txt 2013-04-29 19:17:48.697623940 +0100
@@ -148,19 +148,13 @@ if(WITH_DOCUMENTATION)
set(QT_USE_QTHELP TRUE)
endif(WITH_DOCUMENTATION)
if(WITH_WEBINTERFACE)
- pkg_check_modules(pion-net REQUIRED "pion-net >= 3.0.0")
+ pkg_check_modules(pion REQUIRED "pion >= 5.0.0")
- if(pion-net_FOUND)
- include_directories(${pion-net_INCLUDE_DIRS})
- #message(STATUS "Pion libdir: ${pion-net_LIBDIR}")
-
- #FILE(GLOB pion_FileService "${pion-net_LIBDIR}/pion/plugins/FileService.*")
- #if(pion_FileService MATCHES "^$")
- # message(FATAL_ERROR "Pion-net FileService plugin not found (libpion-net-plugins?) - ${pion_FileService}")
- #endif(pion_FileService MATCHES "^$")
- else(pion-net_FOUND)
- message(FATAL_ERROR "No pion-net library found")
- endif(pion-net_FOUND)
+ if(pion_FOUND)
+ include_directories(${pion_INCLUDE_DIRS})
+ else(pion_FOUND)
+ message(FATAL_ERROR "No pion library found")
+ endif(pion_FOUND)
endif(WITH_WEBINTERFACE)
#set(CMAKE_REQUIRED_INCLUDES "sys/types.h")
@@ -570,9 +564,7 @@ ${fatrat_QRC_H} ${lrelease_outputs})
add_executable(fatrat-conf src/fatrat-conf.cpp)
# This used to be a workaround until it started causing the exact opposite... oh dear!
-#STRING(REPLACE "-mt" "" pion-net_LIBRARIES "${pion-net_LIBRARIES}")
-#message(STATUS ${pion-net_LIBRARIES})
-target_link_libraries(fatrat -ldl -lpthread ${QT_LIBRARIES} ${libtorrent_LDFLAGS} ${gloox_LDFLAGS} ${curl_LDFLAGS} ${Boost_LIBRARIES} ${pion-net_LIBRARIES} ${QT_ADDITIONAL_LIBS} ${XATTR_LIBRARIES} -export-dynamic)
+target_link_libraries(fatrat -ldl -lpthread ${QT_LIBRARIES} ${libtorrent_LDFLAGS} ${gloox_LDFLAGS} ${curl_LDFLAGS} ${Boost_LIBRARIES} ${pion_LIBRARIES} ${QT_ADDITIONAL_LIBS} ${XATTR_LIBRARIES} -export-dynamic)
target_link_libraries(fatrat-conf ${QT_LIBRARIES})
set(fatrat_DEV_HEADERS
Only in fatrat-1.2.0_beta2.new/: CMakeLists.txt.orig
diff -rup fatrat-1.2.0_beta2/config.h.in fatrat-1.2.0_beta2.new/config.h.in
--- fatrat-1.2.0_beta2/config.h.in 2012-07-14 12:44:27.000000000 +0100
+++ fatrat-1.2.0_beta2.new/config.h.in 2013-04-29 19:18:03.241412755 +0100
@@ -13,7 +13,7 @@
#cmakedefine WITH_CXX0X
#ifdef WITH_WEBINTERFACE
-# define PION_NET_PLUGINS "${pion-net_LIBDIR}/pion/plugins"
+# define PION_NET_PLUGINS "${pion_LIBDIR}/pion/plugins"
#endif
#cmakedefine ENABLE_FAKEDOWNLOAD
diff -rup fatrat-1.2.0_beta2/src/remote/HttpService.cpp fatrat-1.2.0_beta2.new/src/remote/HttpService.cpp
--- fatrat-1.2.0_beta2/src/remote/HttpService.cpp 2012-07-14 12:44:27.000000000 +0100
+++ fatrat-1.2.0_beta2.new/src/remote/HttpService.cpp 2013-04-29 19:17:17.076634049 +0100
@@ -51,9 +51,8 @@ respects for all of the code used other
#include <QMultiMap>
#include <QProcess>
#include <QFile>
-#include <pion/net/PionUser.hpp>
-#include <pion/net/HTTPBasicAuth.hpp>
-#include <pion/net/HTTPResponseWriter.hpp>
+#include <pion/http/basic_auth.hpp>
+#include <pion/http/response_writer.hpp>
#include <boost/filesystem/fstream.hpp>
#include "pion/FileService.hpp"
#include <cstdlib>
@@ -63,7 +62,7 @@ respects for all of the code used other
#include <string.h>
#include <algorithm>
-using namespace pion::net;
+using namespace pion::http;
extern QList<Queue*> g_queues;
extern QReadWriteLock g_queuesLock;
@@ -172,16 +171,16 @@ void HttpService::applySettings()
void HttpService::setupAuth()
{
- pion::net::PionUserManagerPtr userManager(new pion::net::PionUserManager);
+ pion::user_manager_ptr userManager(new pion::user_manager);
QString password = getSettingsValue("remote/password").toString();
- m_auth_ptr = pion::net::HTTPAuthPtr( new pion::net::HTTPBasicAuth(userManager, "FatRat Web Interface") );
- m_server->setAuthentication(m_auth_ptr);
- m_auth_ptr->addRestrict("/");
-
- m_auth_ptr->addUser("fatrat", password.toStdString());
- m_auth_ptr->addUser("admin", password.toStdString());
- m_auth_ptr->addUser("user", password.toStdString());
+ m_auth_ptr = pion::http::auth_ptr( new pion::http::basic_auth(userManager, "FatRat Web Interface") );
+ m_server->set_authentication(m_auth_ptr);
+ m_auth_ptr->add_restrict("/");
+
+ m_auth_ptr->add_user("fatrat", password.toStdString());
+ m_auth_ptr->add_user("admin", password.toStdString());
+ m_auth_ptr->add_user("user", password.toStdString());
}
void HttpService::setup()
@@ -190,28 +189,30 @@ void HttpService::setup()
try
{
- m_server = new pion::net::WebServer(m_port);
+ m_server = new pion::http::plugin_server(m_port);
setupAuth();
setupSSL();
- m_server->addService("/xmlrpc", new XmlRpcService);
- m_server->addService("/subclass", new SubclassService);
- m_server->addService("/log", new LogService);
- m_server->addService("/browse", new TransferTreeBrowserService);
- m_server->addService("/", new pion::plugins::FileService);
- m_server->setServiceOption("/", "directory", DATA_LOCATION "/data/remote");
- m_server->setServiceOption("/", "file", DATA_LOCATION "/data/remote/index.html");
- m_server->addService("/copyrights", new pion::plugins::FileService);
- m_server->setServiceOption("/copyrights", "file", DATA_LOCATION "/README");
- m_server->addService("/download", new TransferDownloadService);
- m_server->addService("/captcha", new CaptchaService);
+ m_server->add_service("/xmlrpc", new XmlRpcService);
+ m_server->add_service("/subclass", new SubclassService);
+ m_server->add_service("/log", new LogService);
+ m_server->add_service("/browse", new TransferTreeBrowserService);
+ m_server->add_service("/", new pion::plugins::FileService);
+ m_server->set_service_option("/", "directory", DATA_LOCATION "/data/remote");
+ m_server->set_service_option("/", "file", DATA_LOCATION "/data/remote/index.html");
+ m_server->add_service("/copyrights", new pion::plugins::FileService);
+ m_server->set_service_option("/copyrights", "file", DATA_LOCATION "/README");
+ m_server->add_service("/download", new TransferDownloadService);
+ m_server->add_service("/captcha", new CaptchaService);
m_server->start();
Logger::global()->enterLogMessage("HttpService", tr("Listening on port %1").arg(m_port));
+ std::cout << "Listening on port " << m_port << std::endl;
}
catch(const std::exception& e)
{
+ std::cerr << e.what() << std::endl;
Logger::global()->enterLogMessage("HttpService", tr("Failed to start: %1").arg(e.what()));
}
}
@@ -225,29 +226,29 @@ void HttpService::setupSSL()
if (file.isEmpty() || !QFile::exists(file))
{
Logger::global()->enterLogMessage("HttpService", tr("SSL key file not found, disabling HTTPS"));
- m_server->setSSLFlag(false);
+ m_server->set_ssl_flag(false);
m_strSSLPem.clear();
}
else
{
Logger::global()->enterLogMessage("HttpService", tr("Loading a SSL key from %1").arg(file));
m_strSSLPem = file;
- m_server->setSSLKeyFile(file.toStdString());
- m_server->setSSLFlag(true);
+ m_server->set_ssl_key_file(file.toStdString());
+ m_server->set_ssl_flag(true);
}
}
else
{
Logger::global()->enterLogMessage("HttpService", tr("Running in plain HTTP mode"));
- m_server->setSSLFlag(false);
+ m_server->set_ssl_flag(false);
m_strSSLPem.clear();
}
}
-void HttpService::LogService::operator()(pion::net::HTTPRequestPtr &request, pion::net::TCPConnectionPtr &tcp_conn)
+void HttpService::LogService::operator()(pion::http::request_ptr &request, pion::tcp::connection_ptr &tcp_conn)
{
- HTTPResponseWriterPtr writer(HTTPResponseWriter::create(tcp_conn, *request, boost::bind(&TCPConnection::finish, tcp_conn)));
- QString uuidTransfer = QString::fromStdString(getRelativeResource(request->getResource()));
+ pion::http::response_writer_ptr writer(pion::http::response_writer::create(tcp_conn, *request, boost::bind(&pion::tcp::connection::finish, tcp_conn)));
+ QString uuidTransfer = QString::fromStdString(get_relative_resource(request->get_resource()));
QString data;
if (uuidTransfer.isEmpty())
@@ -260,8 +261,8 @@ void HttpService::LogService::operator()
if (!q || !t)
{
- writer->getResponse().setStatusCode(HTTPTypes::RESPONSE_CODE_NOT_FOUND);
- writer->getResponse().setStatusMessage(HTTPTypes::RESPONSE_MESSAGE_NOT_FOUND);
+ writer->get_response().set_status_code(pion::http::types::RESPONSE_CODE_NOT_FOUND);
+ writer->get_response().set_status_message(pion::http::types::RESPONSE_MESSAGE_NOT_FOUND);
writer->send();
return;
}
@@ -272,16 +273,16 @@ void HttpService::LogService::operator()
g_queuesLock.unlock();
}
- writer->getResponse().addHeader("Content-Type", "text/plain");
+ writer->get_response().add_header("Content-Type", "text/plain");
writer->write(data.toStdString());
writer->send();
}
-void HttpService::TransferTreeBrowserService::operator()(pion::net::HTTPRequestPtr &request, pion::net::TCPConnectionPtr &tcp_conn)
+void HttpService::TransferTreeBrowserService::operator()(pion::http::request_ptr &request, pion::tcp::connection_ptr &tcp_conn)
{
- HTTPResponseWriterPtr writer(HTTPResponseWriter::create(tcp_conn, *request, boost::bind(&TCPConnection::finish, tcp_conn)));
- QString uuidTransfer = QString::fromStdString(getRelativeResource(request->getResource()));
- QString path = QString::fromStdString(request->getQuery("path"));
+ pion::http::response_writer_ptr writer(pion::http::response_writer::create(tcp_conn, *request, boost::bind(&pion::tcp::connection::finish, tcp_conn)));
+ QString uuidTransfer = QString::fromStdString(get_relative_resource(request->get_resource()));
+ QString path = QString::fromStdString(request->get_query("path"));
path = path.replace("+", " ");
path = QUrl::fromPercentEncoding(path.toUtf8());
@@ -294,8 +295,8 @@ void HttpService::TransferTreeBrowserSer
if (path.contains("/..") || path.contains("../"))
{
- writer->getResponse().setStatusCode(HTTPTypes::RESPONSE_CODE_FORBIDDEN);
- writer->getResponse().setStatusMessage(HTTPTypes::RESPONSE_MESSAGE_FORBIDDEN);
+ writer->get_response().set_status_code(pion::http::types::RESPONSE_CODE_FORBIDDEN);
+ writer->get_response().set_status_message(pion::http::types::RESPONSE_MESSAGE_FORBIDDEN);
writer->send();
return;
}
@@ -304,8 +305,8 @@ void HttpService::TransferTreeBrowserSer
if (!q || !t)
{
- writer->getResponse().setStatusCode(HTTPTypes::RESPONSE_CODE_NOT_FOUND);
- writer->getResponse().setStatusMessage(HTTPTypes::RESPONSE_MESSAGE_NOT_FOUND);
+ writer->get_response().set_status_code(pion::http::types::RESPONSE_CODE_NOT_FOUND);
+ writer->get_response().set_status_message(pion::http::types::RESPONSE_MESSAGE_NOT_FOUND);
writer->send();
return;
}
@@ -320,8 +321,8 @@ void HttpService::TransferTreeBrowserSer
if (!dir.cd(path))
{
- writer->getResponse().setStatusCode(HTTPTypes::RESPONSE_CODE_NOT_FOUND);
- writer->getResponse().setStatusMessage(HTTPTypes::RESPONSE_MESSAGE_NOT_FOUND);
+ writer->get_response().set_status_code(pion::http::types::RESPONSE_CODE_NOT_FOUND);
+ writer->get_response().set_status_message(pion::http::types::RESPONSE_MESSAGE_NOT_FOUND);
writer->send();
return;
}
@@ -371,11 +372,11 @@ void HttpService::TransferTreeBrowserSer
writer->send();
}
-void HttpService::TransferDownloadService::operator()(pion::net::HTTPRequestPtr &request, pion::net::TCPConnectionPtr &tcp_conn)
+void HttpService::TransferDownloadService::operator()(pion::http::request_ptr &request, pion::tcp::connection_ptr &tcp_conn)
{
- HTTPResponseWriterPtr writer(HTTPResponseWriter::create(tcp_conn, *request, boost::bind(&TCPConnection::finish, tcp_conn)));
- QString transfer = QString::fromStdString(request->getQuery("transfer"));
- QString path = QString::fromStdString(request->getQuery("path"));
+ pion::http::response_writer_ptr writer(pion::http::response_writer::create(tcp_conn, *request, boost::bind(&pion::tcp::connection::finish, tcp_conn)));
+ QString transfer = QString::fromStdString(request->get_query("transfer"));
+ QString path = QString::fromStdString(request->get_query("path"));
path = path.replace("+", " ");
path = QUrl::fromPercentEncoding(path.toUtf8());
@@ -387,8 +388,8 @@ void HttpService::TransferDownloadServic
if (path.contains("/..") || path.contains("../"))
{
- writer->getResponse().setStatusCode(HTTPTypes::RESPONSE_CODE_FORBIDDEN);
- writer->getResponse().setStatusMessage(HTTPTypes::RESPONSE_MESSAGE_FORBIDDEN);
+ writer->get_response().set_status_code(pion::http::types::RESPONSE_CODE_FORBIDDEN);
+ writer->get_response().set_status_message(pion::http::types::RESPONSE_MESSAGE_FORBIDDEN);
writer->send();
return;
}
@@ -397,8 +398,8 @@ void HttpService::TransferDownloadServic
if (!q || !t)
{
- writer->getResponse().setStatusCode(HTTPTypes::RESPONSE_CODE_NOT_FOUND);
- writer->getResponse().setStatusMessage(HTTPTypes::RESPONSE_MESSAGE_NOT_FOUND);
+ writer->get_response().set_status_code(pion::http::types::RESPONSE_CODE_NOT_FOUND);
+ writer->get_response().set_status_message(pion::http::types::RESPONSE_MESSAGE_NOT_FOUND);
writer->send();
return;
}
@@ -428,24 +429,24 @@ void HttpService::TransferDownloadServic
response_file.update();
pion::plugins::DiskFileSenderPtr sender_ptr(pion::plugins::DiskFileSender::create(response_file, request, tcp_conn, 8192));
- sender_ptr->getWriter()->getResponse().addHeader("Content-Disposition", disposition.toStdString());
+ sender_ptr->getWriter()->get_response().add_header("Content-Disposition", disposition.toStdString());
if (unsigned long long fileSize = response_file.getFileSize())
{
std::stringstream fileSizeStream;
fileSizeStream << fileSize;
- sender_ptr->getWriter()->getResponse().addHeader("Content-Length", fileSizeStream.str());
+ sender_ptr->getWriter()->get_response().add_header("Content-Length", fileSizeStream.str());
}
sender_ptr->send();
}
-void HttpService::SubclassService::operator()(pion::net::HTTPRequestPtr &request, pion::net::TCPConnectionPtr &tcp_conn)
+void HttpService::SubclassService::operator()(pion::http::request_ptr &request, pion::tcp::connection_ptr &tcp_conn)
{
- pion::net::HTTPResponseWriterPtr writer = HTTPResponseWriter::create(tcp_conn, *request, boost::bind(&TCPConnection::finish, tcp_conn));
+ pion::http::response_writer_ptr writer = pion::http::response_writer::create(tcp_conn, *request, boost::bind(&pion::tcp::connection::finish, tcp_conn));
HttpService::WriteBackImpl wb = HttpService::WriteBackImpl(writer);
- QString transfer = QString::fromStdString(request->getQuery("transfer"));
- QString method = QString::fromStdString(getRelativeResource(request->getResource()));
+ QString transfer = QString::fromStdString(request->get_query("transfer"));
+ QString method = QString::fromStdString(get_relative_resource(request->get_resource()));
Queue* q = 0;
Transfer* t = 0;
@@ -460,15 +461,15 @@ void HttpService::SubclassService::opera
g_queuesLock.unlock();
}
- writer->getResponse().setStatusCode(HTTPTypes::RESPONSE_CODE_NOT_FOUND);
- writer->getResponse().setStatusMessage(HTTPTypes::RESPONSE_MESSAGE_NOT_FOUND);
+ writer->get_response().set_status_code(pion::http::types::RESPONSE_CODE_NOT_FOUND);
+ writer->get_response().set_status_message(pion::http::types::RESPONSE_MESSAGE_NOT_FOUND);
writer->send();
return;
}
QMultiMap<QString,QString> map;
- pion::net::HTTPTypes::QueryParams params = request->getQueryParams();
- for (pion::net::HTTPTypes::QueryParams::iterator it = params.begin(); it != params.end(); it++)
+ pion::ihash_multimap params = request->get_queries();
+ for (pion::ihash_multimap::iterator it = params.begin(); it != params.end(); it++)
{
map.insert(QString::fromStdString(it->first), QString::fromStdString(it->second));
}
@@ -481,7 +482,7 @@ void HttpService::SubclassService::opera
g_queuesLock.unlock();
}
-HttpService::WriteBackImpl::WriteBackImpl(pion::net::HTTPResponseWriterPtr& writer)
+HttpService::WriteBackImpl::WriteBackImpl(pion::http::response_writer_ptr& writer)
: m_writer(writer)
{
@@ -489,7 +490,7 @@ HttpService::WriteBackImpl::WriteBackImp
void HttpService::WriteBackImpl::writeNoCopy(void* data, size_t bytes)
{
- m_writer->writeNoCopy(data, bytes);
+ m_writer->write_no_copy(data, bytes);
}
void HttpService::WriteBackImpl::send()
@@ -504,13 +505,13 @@ void HttpService::WriteBackImpl::write(c
void HttpService::WriteBackImpl::setContentType(const char* type)
{
- m_writer->getResponse().addHeader("Content-Type", type);
+ m_writer->get_response().add_header("Content-Type", type);
}
void HttpService::WriteBackImpl::writeFail(QString error)
{
- m_writer->getResponse().setStatusCode(HTTPTypes::RESPONSE_CODE_NOT_FOUND);
- m_writer->getResponse().setStatusMessage(HTTPTypes::RESPONSE_MESSAGE_NOT_FOUND);
+ m_writer->get_response().set_status_code(pion::http::types::RESPONSE_CODE_NOT_FOUND);
+ m_writer->get_response().set_status_message(pion::http::types::RESPONSE_MESSAGE_NOT_FOUND);
}
int HttpService::findTransfer(QString transferUUID, Queue** q, Transfer** t, bool lockForWrite)
@@ -601,9 +602,9 @@ QVariant HttpService::generateCertificat
/*
-void HttpService::CaptchaService::operator()(pion::net::HTTPRequestPtr &request, pion::net::TCPConnectionPtr &tcp_conn)
+void HttpService::CaptchaService::operator()(pion::http::request_ptr &request, pion::tcp::connection_ptr &tcp_conn)
{
- m_cap.writer = HTTPResponseWriter::create(tcp_conn, *request, boost::bind(&TCPConnection::finish, tcp_conn));
+ m_cap.writer = pion::http::response_writer::create(tcp_conn, *request, boost::bind(&pion::tcp::connection::finish, tcp_conn));
std::string upgrade, connection;
upgrade = request->getHeader("Upgrade");
@@ -616,8 +617,8 @@ void HttpService::CaptchaService::operat
if (connection != "upgrade" || upgrade != "websocket" || m_cap.key1.empty() || m_cap.key2.empty())
{
- m_cap.writer->getResponse().setStatusCode(HTTPTypes::RESPONSE_CODE_BAD_REQUEST);
- m_cap.writer->getResponse().setStatusMessage(HTTPTypes::RESPONSE_MESSAGE_BAD_REQUEST);
+ m_cap.writer->get_response().set_status_code(pion::http::types::RESPONSE_CODE_BAD_REQUEST);
+ m_cap.writer->get_response().set_status_message(pion::http::types::RESPONSE_MESSAGE_BAD_REQUEST);
m_cap.writer->send();
}
@@ -668,30 +669,30 @@ void HttpService::CaptchaService::CapSer
*/
-void HttpService::CaptchaHttpResponseWriter::handleWrite(const boost::system::error_code &write_error, std::size_t bytes_written)
+void HttpService::CaptchaHttpResponseWriter::handle_write(const boost::system::error_code &write_error, std::size_t bytes_written)
{
if (!bytes_written)
{
// TODO: handle errors
HttpService::instance()->removeCaptchaClient(client);
- sendFinalChunk();
+ send_final_chunk();
delete client;
}
- pion::net::HTTPResponseWriter::handleWrite(write_error, bytes_written);
+ pion::http::response_writer::handle_write(write_error, bytes_written);
}
-void HttpService::CaptchaService::operator()(pion::net::HTTPRequestPtr &request, pion::net::TCPConnectionPtr &tcp_conn)
+void HttpService::CaptchaService::operator()(pion::http::request_ptr &request, pion::tcp::connection_ptr &tcp_conn)
{
- if (request->hasQuery("id"))
+ if (request->has_query("id"))
{
- QString id = QString::fromStdString(request->getQuery("id"));
- QString solution = QString::fromStdString(request->getQuery("solution"));
+ QString id = QString::fromStdString(request->get_query("id"));
+ QString solution = QString::fromStdString(request->get_query("solution"));
int iid = id.toInt();
HttpService::instance()->m_captchaHttp.captchaEntered(iid, solution);
- pion::net::HTTPResponseWriterPtr writer = HTTPResponseWriter::create(tcp_conn, *request, boost::bind(&TCPConnection::finish, tcp_conn));
+ pion::http::response_writer_ptr writer = pion::http::response_writer::create(tcp_conn, *request, boost::bind(&pion::tcp::connection::finish, tcp_conn));
writer->send();
}
else
@@ -709,13 +710,13 @@ void HttpService::CaptchaService::operat
RegisteredClient* client = new RegisteredClient;
client->writer = CaptchaHttpResponseWriter::create(client, tcp_conn, *request,
- boost::bind(&TCPConnection::finish, tcp_conn));
+ boost::bind(&pion::tcp::connection::finish, tcp_conn));
HttpService::instance()->addCaptchaClient(client);
- client->writer->getResponse().addHeader("Content-Type", "text/event-stream");
- client->writer->getResponse().addHeader("Cache-Control", "no-store, no-cache, must-revalidate, max-age=0");
- client->writer->getResponse().addHeader("Expires", "Tue, 03 Jul 2001 06:00:00 GMT");
- client->writer->getResponse().addHeader("Pragma", "no-cache");
+ client->writer->get_response().add_header("Content-Type", "text/event-stream");
+ client->writer->get_response().add_header("Cache-Control", "no-store, no-cache, must-revalidate, max-age=0");
+ client->writer->get_response().add_header("Expires", "Tue, 03 Jul 2001 06:00:00 GMT");
+ client->writer->get_response().add_header("Pragma", "no-cache");
}
}
@@ -747,7 +748,7 @@ void HttpService::RegisteredClient::push
writer->clear();
writer->write(buf.data(), buf.length());
- writer->sendChunk(boost::bind(&HttpService::RegisteredClient::finished, this));
+ writer->send_chunk(boost::bind(&HttpService::RegisteredClient::finished, this));
}
else
writeInProgressLock.unlock();
@@ -760,7 +761,7 @@ void HttpService::RegisteredClient::keep
writer->clear();
writer->write(": keepalive\r\n\r\n");
- writer->sendChunk(boost::bind(&HttpService::RegisteredClient::finished, this));
+ writer->send_chunk(boost::bind(&HttpService::RegisteredClient::finished, this));
}
void HttpService::addCaptchaEvent(int id, QString url)
@@ -803,5 +804,5 @@ void HttpService::keepalive()
void HttpService::RegisteredClient::terminate()
{
- writer->getTCPConnection()->finish();
+ writer->get_connection()->finish();
}
diff -rup fatrat-1.2.0_beta2/src/remote/HttpService.h fatrat-1.2.0_beta2.new/src/remote/HttpService.h
--- fatrat-1.2.0_beta2/src/remote/HttpService.h 2012-07-14 12:44:27.000000000 +0100
+++ fatrat-1.2.0_beta2.new/src/remote/HttpService.h 2013-04-29 19:17:17.076634049 +0100
@@ -40,7 +40,8 @@ respects for all of the code used other
#include <ctime>
#include <openssl/ssl.h>
#include <boost/system/system_error.hpp>
-#include <pion/net/HTTPResponseWriter.hpp>
+#include <pion/http/plugin_server.hpp>
+#include <pion/http/response_writer.hpp>
#include "captcha/CaptchaHttp.h"
#include "remote/TransferHttpService.h"
@@ -48,7 +49,8 @@ respects for all of the code used other
# error This file is not supposed to be included!
#endif
-#include <pion/net/WebServer.hpp>
+#include <pion/http/server.hpp>
+#include <pion/http/plugin_service.hpp>
class Queue;
class Transfer;
@@ -83,8 +85,8 @@ private:
void killCaptchaClients();
private:
static HttpService* m_instance;
- pion::net::WebServer* m_server;
- pion::net::HTTPAuthPtr m_auth_ptr;
+ pion::http::plugin_server* m_server;
+ pion::http::auth_ptr m_auth_ptr;
CaptchaHttp m_captchaHttp;
quint16 m_port;
QString m_strSSLPem;
@@ -94,27 +96,27 @@ private:
QList<RegisteredClient*> m_registeredCaptchaClients;
QMutex m_registeredCaptchaClientsMutex;
- class LogService : public pion::net::WebService
+ class LogService : public pion::http::plugin_service
{
- void operator()(pion::net::HTTPRequestPtr &request, pion::net::TCPConnectionPtr &tcp_conn);
+ void operator()(pion::http::request_ptr &request, pion::tcp::connection_ptr &tcp_conn);
};
- class TransferTreeBrowserService : public pion::net::WebService
+ class TransferTreeBrowserService : public pion::http::plugin_service
{
- void operator()(pion::net::HTTPRequestPtr &request, pion::net::TCPConnectionPtr &tcp_conn);
+ void operator()(pion::http::request_ptr &request, pion::tcp::connection_ptr &tcp_conn);
};
- class TransferDownloadService : public pion::net::WebService
+ class TransferDownloadService : public pion::http::plugin_service
{
- void operator()(pion::net::HTTPRequestPtr &request, pion::net::TCPConnectionPtr &tcp_conn);
+ void operator()(pion::http::request_ptr &request, pion::tcp::connection_ptr &tcp_conn);
};
- class SubclassService : public pion::net::WebService
+ class SubclassService : public pion::http::plugin_service
{
public:
- void operator()(pion::net::HTTPRequestPtr &request, pion::net::TCPConnectionPtr &tcp_conn);
+ void operator()(pion::http::request_ptr &request, pion::tcp::connection_ptr &tcp_conn);
};
- /*class CaptchaService : public pion::net::WebService
+ /*class CaptchaService : public pion::http::plugin_service
{
public:
- void operator()(pion::net::HTTPRequestPtr &request, pion::net::TCPConnectionPtr &tcp_conn);
+ void operator()(pion::http::request_ptr &request, pion::tcp::connection_ptr &tcp_conn);
private:
class CapServCap
{
@@ -126,15 +128,15 @@ private:
std::string key1, key2;
char sig[8];
int inbuf;
- pion::net::TCPConnectionPtr tcp_conn;
+ pion::tcp::connection_ptr tcp_conn;
} m_cap;
};*/
class CaptchaHttpResponseWriter;
- class CaptchaService : public pion::net::WebService
+ class CaptchaService : public pion::http::plugin_service
{
public:
- void operator()(pion::net::HTTPRequestPtr &request, pion::net::TCPConnectionPtr &tcp_conn);
+ void operator()(pion::http::request_ptr &request, pion::tcp::connection_ptr &tcp_conn);
};
struct RegisteredClient
{
@@ -151,16 +153,16 @@ private:
void terminate();
};
- class CaptchaHttpResponseWriter : public pion::net::HTTPResponseWriter
+ class CaptchaHttpResponseWriter : public pion::http::response_writer
{
public:
- CaptchaHttpResponseWriter(HttpService::RegisteredClient* cl, pion::net::TCPConnectionPtr &tcp_conn, const pion::net::HTTPRequest& request, FinishedHandler handler = FinishedHandler())
- : pion::net::HTTPResponseWriter(tcp_conn, request, handler), client(cl)
+ CaptchaHttpResponseWriter(HttpService::RegisteredClient* cl, pion::tcp::connection_ptr &tcp_conn, const pion::http::request& request, finished_handler_t handler = finished_handler_t())
+ : pion::http::response_writer(tcp_conn, request, handler), client(cl)
{
}
- static inline boost::shared_ptr<CaptchaHttpResponseWriter> create(HttpService::RegisteredClient* cl, pion::net::TCPConnectionPtr &tcp_conn, const pion::net::HTTPRequest& request, FinishedHandler handler = FinishedHandler())
+ static inline boost::shared_ptr<CaptchaHttpResponseWriter> create(HttpService::RegisteredClient* cl, pion::tcp::connection_ptr &tcp_conn, const pion::http::request& request, finished_handler_t handler = finished_handler_t())
{
return boost::shared_ptr<CaptchaHttpResponseWriter>(new CaptchaHttpResponseWriter(cl, tcp_conn, request, handler));
}
@@ -171,7 +173,7 @@ private:
m_http_response->prepareBuffersForSend(write_buffers, getTCPConnection()->getKeepAlive(),
sendingChunkedMessage());
}*/
- virtual void handleWrite(const boost::system::error_code &write_error, std::size_t bytes_written);
+ virtual void handle_write(const boost::system::error_code &write_error, std::size_t bytes_written);
HttpService::RegisteredClient* client;
};
@@ -179,14 +181,14 @@ private:
class WriteBackImpl : public TransferHttpService::WriteBack
{
public:
- WriteBackImpl(pion::net::HTTPResponseWriterPtr& writer);
+ WriteBackImpl(pion::http::response_writer_ptr& writer);
void write(const char* data, size_t bytes);
void writeFail(QString error);
void writeNoCopy(void* data, size_t bytes);
void send();
void setContentType(const char* type);
private:
- pion::net::HTTPResponseWriterPtr m_writer;
+ pion::http::response_writer_ptr m_writer;
};
};
diff -rup fatrat-1.2.0_beta2/src/remote/pion/FileService.cpp fatrat-1.2.0_beta2.new/src/remote/pion/FileService.cpp
--- fatrat-1.2.0_beta2/src/remote/pion/FileService.cpp 2012-07-14 12:44:27.000000000 +0100
+++ fatrat-1.2.0_beta2.new/src/remote/pion/FileService.cpp 2013-04-29 19:17:17.079967487 +0100
@@ -15,13 +15,14 @@
#include <boost/algorithm/string/case_conv.hpp>
#include "FileService.hpp"
-#include <pion/PionPlugin.hpp>
-#include <pion/net/HTTPResponseWriter.hpp>
+#include <pion/plugin.hpp>
+#include <pion/http/response_writer.hpp>
#include <sstream>
#include <QFileInfo>
using namespace pion;
-using namespace pion::net;
+using namespace pion::http;
+using namespace pion::tcp;
namespace pion { // begin namespace pion
namespace plugins { // begin namespace plugins
@@ -49,7 +50,7 @@ FileService::FileService(void)
m_writable(false)
{}
-void FileService::setOption(const std::string& name, const std::string& value)
+void FileService::set_option(const std::string& name, const std::string& value)
{
if (name == "directory") {
m_directory = value;
@@ -104,10 +105,10 @@ void FileService::setOption(const std::s
}
}
-void FileService::operator()(HTTPRequestPtr& request, TCPConnectionPtr& tcp_conn)
+void FileService::operator()(request_ptr& request, connection_ptr& tcp_conn)
{
// get the relative resource path for the request
- const std::string relative_path(getRelativeResource(request->getResource()));
+ const std::string relative_path(get_relative_resource(request->get_resource()));
// determine the path of the file being requested
boost::filesystem::path file_path;
@@ -117,7 +118,7 @@ void FileService::operator()(HTTPRequest
if (m_file.empty()) {
// no file is specified, either in the request or in the options
PION_LOG_WARN(m_logger, "No file option defined ("
- << getResource() << ")");
+ << get_resource() << ")");
sendNotFoundResponse(request, tcp_conn);
return;
} else {
@@ -129,7 +130,7 @@ void FileService::operator()(HTTPRequest
if (m_directory.empty()) {
// no directory is specified for the relative file
PION_LOG_WARN(m_logger, "No directory option defined ("
- << getResource() << "): " << relative_path);
+ << get_resource() << "): " << relative_path);
sendNotFoundResponse(request, tcp_conn);
return;
} else {
@@ -142,7 +143,7 @@ void FileService::operator()(HTTPRequest
std::string string = file_path.string();
if (string.find(m_directory.string()) != 0) {
PION_LOG_WARN(m_logger, "Request for file outside of directory ("
- << getResource() << "): " << relative_path);
+ << get_resource() << "): " << relative_path);
static const std::string FORBIDDEN_HTML_START =
"<html><head>\n"
"<title>403 Forbidden</title>\n"
@@ -152,14 +153,14 @@ void FileService::operator()(HTTPRequest
static const std::string FORBIDDEN_HTML_FINISH =
" is not in the configured directory.</p>\n"
"</body></html>\n";
- HTTPResponseWriterPtr writer(HTTPResponseWriter::create(tcp_conn, *request,
- boost::bind(&TCPConnection::finish, tcp_conn)));
- writer->getResponse().setStatusCode(HTTPTypes::RESPONSE_CODE_FORBIDDEN);
- writer->getResponse().setStatusMessage(HTTPTypes::RESPONSE_MESSAGE_FORBIDDEN);
- if (request->getMethod() != HTTPTypes::REQUEST_METHOD_HEAD) {
- writer->writeNoCopy(FORBIDDEN_HTML_START);
- writer << request->getResource();
- writer->writeNoCopy(FORBIDDEN_HTML_FINISH);
+ response_writer_ptr writer(response_writer::create(tcp_conn, *request,
+ boost::bind(&connection::finish, tcp_conn)));
+ writer->get_response().set_status_code(types::RESPONSE_CODE_FORBIDDEN);
+ writer->get_response().set_status_message(types::RESPONSE_MESSAGE_FORBIDDEN);
+ if (request->get_method() != types::REQUEST_METHOD_HEAD) {
+ writer->write_no_copy(FORBIDDEN_HTML_START);
+ writer << request->get_resource();
+ writer->write_no_copy(FORBIDDEN_HTML_FINISH);
}
writer->send();
return;
@@ -168,7 +169,7 @@ void FileService::operator()(HTTPRequest
// requests specifying directories are not allowed
if (boost::filesystem::is_directory(file_path)) {
PION_LOG_WARN(m_logger, "Request for directory ("
- << getResource() << "): " << relative_path);
+ << get_resource() << "): " << relative_path);
static const std::string FORBIDDEN_HTML_START =
"<html><head>\n"
"<title>403 Forbidden</title>\n"
@@ -178,21 +179,21 @@ void FileService::operator()(HTTPRequest
static const std::string FORBIDDEN_HTML_FINISH =
" is a directory.</p>\n"
"</body></html>\n";
- HTTPResponseWriterPtr writer(HTTPResponseWriter::create(tcp_conn, *request,
- boost::bind(&TCPConnection::finish, tcp_conn)));
- writer->getResponse().setStatusCode(HTTPTypes::RESPONSE_CODE_FORBIDDEN);
- writer->getResponse().setStatusMessage(HTTPTypes::RESPONSE_MESSAGE_FORBIDDEN);
- if (request->getMethod() != HTTPTypes::REQUEST_METHOD_HEAD) {
- writer->writeNoCopy(FORBIDDEN_HTML_START);
- writer << request->getResource();
- writer->writeNoCopy(FORBIDDEN_HTML_FINISH);
+ response_writer_ptr writer(response_writer::create(tcp_conn, *request,
+ boost::bind(&connection::finish, tcp_conn)));
+ writer->get_response().set_status_code(types::RESPONSE_CODE_FORBIDDEN);
+ writer->get_response().set_status_message(types::RESPONSE_MESSAGE_FORBIDDEN);
+ if (request->get_method() != types::REQUEST_METHOD_HEAD) {
+ writer->write_no_copy(FORBIDDEN_HTML_START);
+ writer << request->get_resource();
+ writer->write_no_copy(FORBIDDEN_HTML_FINISH);
}
writer->send();
return;
}
- if (request->getMethod() == HTTPTypes::REQUEST_METHOD_GET
- || request->getMethod() == HTTPTypes::REQUEST_METHOD_HEAD)
+ if (request->get_method() == types::REQUEST_METHOD_GET
+ || request->get_method() == types::REQUEST_METHOD_HEAD)
{
// the type of response we will send
enum ResponseType {
@@ -207,7 +208,7 @@ void FileService::operator()(HTTPRequest
DiskFile response_file;
// get the If-Modified-Since request header
- const std::string if_modified_since(request->getHeader(HTTPTypes::HEADER_IF_MODIFIED_SINCE));
+ const std::string if_modified_since(request->get_header(types::HEADER_IF_MODIFIED_SINCE));
// check the cache for a corresponding entry (if enabled)
// note that m_cache_setting may equal 0 if m_scan_setting == 1
@@ -225,18 +226,18 @@ void FileService::operator()(HTTPRequest
// all requests must correspond with existing cache entries
// since no match was found, just return file not found
PION_LOG_WARN(m_logger, "Request for unknown file ("
- << getResource() << "): " << relative_path);
+ << get_resource() << "): " << relative_path);
response_type = RESPONSE_NOT_FOUND;
} else {
PION_LOG_DEBUG(m_logger, "No cache entry for request ("
- << getResource() << "): " << relative_path);
+ << get_resource() << "): " << relative_path);
}
} else {
// found an existing cache entry
PION_LOG_DEBUG(m_logger, "Found cache entry for request ("
- << getResource() << "): " << relative_path);
+ << get_resource() << "): " << relative_path);
if (m_cache_setting == 0) {
// cache is disabled
@@ -253,12 +254,12 @@ void FileService::operator()(HTTPRequest
// no need to read the file; the modified times match!
response_type = RESPONSE_NOT_MODIFIED;
} else {
- if (request->getMethod() == HTTPTypes::REQUEST_METHOD_HEAD) {
+ if (request->get_method() == types::REQUEST_METHOD_HEAD) {
response_type = RESPONSE_HEAD_OK;
} else {
response_type = RESPONSE_OK;
PION_LOG_DEBUG(m_logger, "Cache disabled, reading file ("
- << getResource() << "): " << relative_path);
+ << get_resource() << "): " << relative_path);
}
}
@@ -290,7 +291,7 @@ void FileService::operator()(HTTPRequest
// get the response type
if (cache_itr->second.getLastModifiedString() == if_modified_since) {
response_type = RESPONSE_NOT_MODIFIED;
- } else if (request->getMethod() == HTTPTypes::REQUEST_METHOD_HEAD) {
+ } else if (request->get_method() == types::REQUEST_METHOD_HEAD) {
response_type = RESPONSE_HEAD_OK;
} else {
response_type = RESPONSE_OK;
@@ -301,7 +302,7 @@ void FileService::operator()(HTTPRequest
PION_LOG_DEBUG(m_logger, (cache_was_updated ? "Updated" : "Using")
<< " cache entry for request ("
- << getResource() << "): " << relative_path);
+ << get_resource() << "): " << relative_path);
}
}
}
@@ -310,7 +311,7 @@ void FileService::operator()(HTTPRequest
// make sure that the file exists
if (! boost::filesystem::exists(file_path)) {
PION_LOG_WARN(m_logger, "File not found ("
- << getResource() << "): " << relative_path);
+ << get_resource() << "): " << relative_path);
sendNotFoundResponse(request, tcp_conn);
return;
}
@@ -318,7 +319,7 @@ void FileService::operator()(HTTPRequest
response_file.setFilePath(file_path);
PION_LOG_DEBUG(m_logger, "Found file for request ("
- << getResource() << "): " << relative_path);
+ << get_resource() << "): " << relative_path);
// determine the MIME type
response_file.setMimeType(findMIMEType( response_file.getFilePath().string() ));
@@ -330,7 +331,7 @@ void FileService::operator()(HTTPRequest
if (response_file.getLastModifiedString() == if_modified_since) {
// no need to read the file; the modified times match!
response_type = RESPONSE_NOT_MODIFIED;
- } else if (request->getMethod() == HTTPTypes::REQUEST_METHOD_HEAD) {
+ } else if (request->get_method() == types::REQUEST_METHOD_HEAD) {
response_type = RESPONSE_HEAD_OK;
} else {
response_type = RESPONSE_OK;
@@ -341,7 +342,7 @@ void FileService::operator()(HTTPRequest
}
// add new entry to the cache
PION_LOG_DEBUG(m_logger, "Adding cache entry for request ("
- << getResource() << "): " << relative_path);
+ << get_resource() << "): " << relative_path);
boost::mutex::scoped_lock cache_lock(m_cache_mutex);
m_cache_map.insert( std::make_pair(relative_path, response_file) );
}
@@ -360,43 +361,43 @@ void FileService::operator()(HTTPRequest
// sending headers only -> use our own response object
// prepare a response and set the Content-Type
- HTTPResponseWriterPtr writer(HTTPResponseWriter::create(tcp_conn, *request,
- boost::bind(&TCPConnection::finish, tcp_conn)));
- writer->getResponse().setContentType(response_file.getMimeType());
+ response_writer_ptr writer(response_writer::create(tcp_conn, *request,
+ boost::bind(&connection::finish, tcp_conn)));
+ writer->get_response().set_content_type(response_file.getMimeType());
// set Last-Modified header to enable client-side caching
- writer->getResponse().addHeader(HTTPTypes::HEADER_LAST_MODIFIED,
+ writer->get_response().add_header(types::HEADER_LAST_MODIFIED,
response_file.getLastModifiedString());
std::stringstream out;
out << response_file.getFileSize();
- writer->getResponse().addHeader(HTTPTypes::HEADER_CONTENT_LENGTH, out.str());
+ writer->get_response().add_header(types::HEADER_CONTENT_LENGTH, out.str());
switch(response_type) {
case RESPONSE_UNDEFINED:
case RESPONSE_NOT_FOUND:
case RESPONSE_OK:
// this should never happen
- throw UndefinedResponseException(request->getResource());
+ throw UndefinedResponseException(request->get_resource());
break;
case RESPONSE_NOT_MODIFIED:
// set "Not Modified" response
- writer->getResponse().setStatusCode(HTTPTypes::RESPONSE_CODE_NOT_MODIFIED);
- writer->getResponse().setStatusMessage(HTTPTypes::RESPONSE_MESSAGE_NOT_MODIFIED);
+ writer->get_response().set_status_code(types::RESPONSE_CODE_NOT_MODIFIED);
+ writer->get_response().set_status_message(types::RESPONSE_MESSAGE_NOT_MODIFIED);
break;
case RESPONSE_HEAD_OK:
// set "OK" response (not really necessary since this is the default)
- writer->getResponse().setStatusCode(HTTPTypes::RESPONSE_CODE_OK);
- writer->getResponse().setStatusMessage(HTTPTypes::RESPONSE_MESSAGE_OK);
+ writer->get_response().set_status_code(types::RESPONSE_CODE_OK);
+ writer->get_response().set_status_message(types::RESPONSE_MESSAGE_OK);
break;
}
// send the response
writer->send();
}
- } else if (request->getMethod() == HTTPTypes::REQUEST_METHOD_POST
- || request->getMethod() == HTTPTypes::REQUEST_METHOD_PUT
- || request->getMethod() == HTTPTypes::REQUEST_METHOD_DELETE)
+ } else if (request->get_method() == types::REQUEST_METHOD_POST
+ || request->get_method() == types::REQUEST_METHOD_PUT
+ || request->get_method() == types::REQUEST_METHOD_DELETE)
{
// If not writable, then send 405 (Method Not Allowed) response for POST, PUT or DELETE requests.
if (!m_writable) {
@@ -409,24 +410,24 @@ void FileService::operator()(HTTPRequest
static const std::string NOT_ALLOWED_HTML_FINISH =
" is not allowed on this server.</p>\n"
"</body></html>\n";
- HTTPResponseWriterPtr writer(HTTPResponseWriter::create(tcp_conn, *request,
- boost::bind(&TCPConnection::finish, tcp_conn)));
- writer->getResponse().setStatusCode(HTTPTypes::RESPONSE_CODE_METHOD_NOT_ALLOWED);
- writer->getResponse().setStatusMessage(HTTPTypes::RESPONSE_MESSAGE_METHOD_NOT_ALLOWED);
- writer->writeNoCopy(NOT_ALLOWED_HTML_START);
- writer << request->getMethod();
- writer->writeNoCopy(NOT_ALLOWED_HTML_FINISH);
- writer->getResponse().addHeader("Allow", "GET, HEAD");
+ response_writer_ptr writer(response_writer::create(tcp_conn, *request,
+ boost::bind(&connection::finish, tcp_conn)));
+ writer->get_response().set_status_code(types::RESPONSE_CODE_METHOD_NOT_ALLOWED);
+ writer->get_response().set_status_message(types::RESPONSE_MESSAGE_METHOD_NOT_ALLOWED);
+ writer->write_no_copy(NOT_ALLOWED_HTML_START);
+ writer << request->get_method();
+ writer->write_no_copy(NOT_ALLOWED_HTML_FINISH);
+ writer->get_response().add_header("Allow", "GET, HEAD");
writer->send();
} else {
- HTTPResponseWriterPtr writer(HTTPResponseWriter::create(tcp_conn, *request,
- boost::bind(&TCPConnection::finish, tcp_conn)));
- if (request->getMethod() == HTTPTypes::REQUEST_METHOD_POST
- || request->getMethod() == HTTPTypes::REQUEST_METHOD_PUT)
+ response_writer_ptr writer(response_writer::create(tcp_conn, *request,
+ boost::bind(&connection::finish, tcp_conn)));
+ if (request->get_method() == types::REQUEST_METHOD_POST
+ || request->get_method() == types::REQUEST_METHOD_PUT)
{
if (boost::filesystem::exists(file_path)) {
- writer->getResponse().setStatusCode(HTTPTypes::RESPONSE_CODE_NO_CONTENT);
- writer->getResponse().setStatusMessage(HTTPTypes::RESPONSE_MESSAGE_NO_CONTENT);
+ writer->get_response().set_status_code(types::RESPONSE_CODE_NO_CONTENT);
+ writer->get_response().set_status_message(types::RESPONSE_MESSAGE_NO_CONTENT);
} else {
// The file doesn't exist yet, so it will be created below, unless the
// directory of the requested file also doesn't exist.
@@ -440,11 +441,11 @@ void FileService::operator()(HTTPRequest
static const std::string NOT_FOUND_HTML_FINISH =
" was not found on this server.</p>\n"
"</body></html>\n";
- writer->getResponse().setStatusCode(HTTPTypes::RESPONSE_CODE_NOT_FOUND);
- writer->getResponse().setStatusMessage(HTTPTypes::RESPONSE_MESSAGE_NOT_FOUND);
- writer->writeNoCopy(NOT_FOUND_HTML_START);
- writer << request->getResource();
- writer->writeNoCopy(NOT_FOUND_HTML_FINISH);
+ writer->get_response().set_status_code(types::RESPONSE_CODE_NOT_FOUND);
+ writer->get_response().set_status_message(types::RESPONSE_MESSAGE_NOT_FOUND);
+ writer->write_no_copy(NOT_FOUND_HTML_START);
+ writer << request->get_resource();
+ writer->write_no_copy(NOT_FOUND_HTML_FINISH);
writer->send();
return;
}
@@ -457,17 +458,17 @@ void FileService::operator()(HTTPRequest
static const std::string CREATED_HTML_FINISH =
"</p>\n"
"</body></html>\n";
- writer->getResponse().setStatusCode(HTTPTypes::RESPONSE_CODE_CREATED);
- writer->getResponse().setStatusMessage(HTTPTypes::RESPONSE_MESSAGE_CREATED);
- writer->getResponse().addHeader(HTTPTypes::HEADER_LOCATION, request->getResource());
- writer->writeNoCopy(CREATED_HTML_START);
- writer << request->getResource();
- writer->writeNoCopy(CREATED_HTML_FINISH);
+ writer->get_response().set_status_code(types::RESPONSE_CODE_CREATED);
+ writer->get_response().set_status_message(types::RESPONSE_MESSAGE_CREATED);
+ writer->get_response().add_header(types::HEADER_LOCATION, request->get_resource());
+ writer->write_no_copy(CREATED_HTML_START);
+ writer << request->get_resource();
+ writer->write_no_copy(CREATED_HTML_FINISH);
}
- std::ios_base::openmode mode = request->getMethod() == HTTPTypes::REQUEST_METHOD_POST?
+ std::ios_base::openmode mode = request->get_method() == types::REQUEST_METHOD_POST?
std::ios::app : std::ios::out;
boost::filesystem::ofstream file_stream(file_path, mode);
- file_stream.write(request->getContent(), request->getContentLength());
+ file_stream.write(request->get_content(), request->get_content_length());
file_stream.close();
if (!boost::filesystem::exists(file_path)) {
static const std::string PUT_FAILED_HTML_START =
@@ -479,21 +480,21 @@ void FileService::operator()(HTTPRequest
static const std::string PUT_FAILED_HTML_FINISH =
".</p>\n"
"</body></html>\n";
- writer->getResponse().setStatusCode(HTTPTypes::RESPONSE_CODE_SERVER_ERROR);
- writer->getResponse().setStatusMessage(HTTPTypes::RESPONSE_MESSAGE_SERVER_ERROR);
- writer->writeNoCopy(PUT_FAILED_HTML_START);
- writer << request->getResource();
- writer->writeNoCopy(PUT_FAILED_HTML_FINISH);
+ writer->get_response().set_status_code(types::RESPONSE_CODE_SERVER_ERROR);
+ writer->get_response().set_status_message(types::RESPONSE_MESSAGE_SERVER_ERROR);
+ writer->write_no_copy(PUT_FAILED_HTML_START);
+ writer << request->get_resource();
+ writer->write_no_copy(PUT_FAILED_HTML_FINISH);
}
writer->send();
- } else if (request->getMethod() == HTTPTypes::REQUEST_METHOD_DELETE) {
+ } else if (request->get_method() == types::REQUEST_METHOD_DELETE) {
if (!boost::filesystem::exists(file_path)) {
sendNotFoundResponse(request, tcp_conn);
} else {
try {
boost::filesystem::remove(file_path);
- writer->getResponse().setStatusCode(HTTPTypes::RESPONSE_CODE_NO_CONTENT);
- writer->getResponse().setStatusMessage(HTTPTypes::RESPONSE_MESSAGE_NO_CONTENT);
+ writer->get_response().set_status_code(types::RESPONSE_CODE_NO_CONTENT);
+ writer->get_response().set_status_message(types::RESPONSE_MESSAGE_NO_CONTENT);
writer->send();
} catch (...) {
static const std::string DELETE_FAILED_HTML_START =
@@ -505,18 +506,18 @@ void FileService::operator()(HTTPRequest
static const std::string DELETE_FAILED_HTML_FINISH =
".</p>\n"
"</body></html>\n";
- writer->getResponse().setStatusCode(HTTPTypes::RESPONSE_CODE_SERVER_ERROR);
- writer->getResponse().setStatusMessage(HTTPTypes::RESPONSE_MESSAGE_SERVER_ERROR);
- writer->writeNoCopy(DELETE_FAILED_HTML_START);
- writer << request->getResource();
- writer->writeNoCopy(DELETE_FAILED_HTML_FINISH);
+ writer->get_response().set_status_code(types::RESPONSE_CODE_SERVER_ERROR);
+ writer->get_response().set_status_message(types::RESPONSE_MESSAGE_SERVER_ERROR);
+ writer->write_no_copy(DELETE_FAILED_HTML_START);
+ writer << request->get_resource();
+ writer->write_no_copy(DELETE_FAILED_HTML_FINISH);
writer->send();
}
}
} else {
// This should never be reached.
- writer->getResponse().setStatusCode(HTTPTypes::RESPONSE_CODE_SERVER_ERROR);
- writer->getResponse().setStatusMessage(HTTPTypes::RESPONSE_MESSAGE_SERVER_ERROR);
+ writer->get_response().set_status_code(types::RESPONSE_CODE_SERVER_ERROR);
+ writer->get_response().set_status_message(types::RESPONSE_MESSAGE_SERVER_ERROR);
writer->send();
}
}
@@ -532,19 +533,19 @@ void FileService::operator()(HTTPRequest
static const std::string NOT_IMPLEMENTED_HTML_FINISH =
" is not implemented on this server.</p>\n"
"</body></html>\n";
- HTTPResponseWriterPtr writer(HTTPResponseWriter::create(tcp_conn, *request,
- boost::bind(&TCPConnection::finish, tcp_conn)));
- writer->getResponse().setStatusCode(HTTPTypes::RESPONSE_CODE_NOT_IMPLEMENTED);
- writer->getResponse().setStatusMessage(HTTPTypes::RESPONSE_MESSAGE_NOT_IMPLEMENTED);
- writer->writeNoCopy(NOT_IMPLEMENTED_HTML_START);
- writer << request->getMethod();
- writer->writeNoCopy(NOT_IMPLEMENTED_HTML_FINISH);
+ response_writer_ptr writer(response_writer::create(tcp_conn, *request,
+ boost::bind(&connection::finish, tcp_conn)));
+ writer->get_response().set_status_code(types::RESPONSE_CODE_NOT_IMPLEMENTED);
+ writer->get_response().set_status_message(types::RESPONSE_MESSAGE_NOT_IMPLEMENTED);
+ writer->write_no_copy(NOT_IMPLEMENTED_HTML_START);
+ writer << request->get_method();
+ writer->write_no_copy(NOT_IMPLEMENTED_HTML_FINISH);
writer->send();
}
}
-void FileService::sendNotFoundResponse(HTTPRequestPtr& http_request,
- TCPConnectionPtr& tcp_conn)
+void FileService::sendNotFoundResponse(request_ptr& http_request,
+ connection_ptr& tcp_conn)
{
static const std::string NOT_FOUND_HTML_START =
"<html><head>\n"
@@ -555,21 +556,21 @@ void FileService::sendNotFoundResponse(H
static const std::string NOT_FOUND_HTML_FINISH =
" was not found on this server.</p>\n"
"</body></html>\n";
- HTTPResponseWriterPtr writer(HTTPResponseWriter::create(tcp_conn, *http_request,
- boost::bind(&TCPConnection::finish, tcp_conn)));
- writer->getResponse().setStatusCode(HTTPTypes::RESPONSE_CODE_NOT_FOUND);
- writer->getResponse().setStatusMessage(HTTPTypes::RESPONSE_MESSAGE_NOT_FOUND);
- if (http_request->getMethod() != HTTPTypes::REQUEST_METHOD_HEAD) {
- writer->writeNoCopy(NOT_FOUND_HTML_START);
- writer << http_request->getResource();
- writer->writeNoCopy(NOT_FOUND_HTML_FINISH);
+ response_writer_ptr writer(response_writer::create(tcp_conn, *http_request,
+ boost::bind(&connection::finish, tcp_conn)));
+ writer->get_response().set_status_code(types::RESPONSE_CODE_NOT_FOUND);
+ writer->get_response().set_status_message(types::RESPONSE_MESSAGE_NOT_FOUND);
+ if (http_request->get_method() != types::REQUEST_METHOD_HEAD) {
+ writer->write_no_copy(NOT_FOUND_HTML_START);
+ writer << http_request->get_resource();
+ writer->write_no_copy(NOT_FOUND_HTML_FINISH);
}
writer->send();
}
void FileService::start(void)
{
- PION_LOG_DEBUG(m_logger, "Starting up resource (" << getResource() << ')');
+ PION_LOG_DEBUG(m_logger, "Starting up resource (" << get_resource() << ')');
// scan directory/file if scan setting != 0
if (m_scan_setting != 0) {
@@ -594,7 +595,7 @@ void FileService::start(void)
void FileService::stop(void)
{
- PION_LOG_DEBUG(m_logger, "Shutting down resource (" << getResource() << ')');
+ PION_LOG_DEBUG(m_logger, "Shutting down resource (" << get_resource() << ')');
// clear cached files (if started again, it will re-scan)
boost::mutex::scoped_lock cache_lock(m_cache_mutex);
m_cache_map.clear();
@@ -602,7 +603,7 @@ void FileService::stop(void)
void FileService::scanDirectory(const boost::filesystem::path& dir_path)
{
- PION_LOG_DEBUG(m_logger, "Scanning directory (" << getResource() << "): "
+ PION_LOG_DEBUG(m_logger, "Scanning directory (" << get_resource() << "): "
<< dir_path.string());
// iterate through items in the directory
@@ -705,7 +706,7 @@ void DiskFile::update(void)
// set file_size and last_modified
m_file_size = QFileInfo(QString::fromStdString(m_file_path.string())).size();
m_last_modified = boost::filesystem::last_write_time( m_file_path );
- m_last_modified_string = HTTPTypes::get_date_string( m_last_modified );
+ m_last_modified_string = types::get_date_string( m_last_modified );
}
void DiskFile::read(void)
@@ -737,7 +738,7 @@ bool DiskFile::checkUpdated(void)
// update file_size and last_modified timestamp
m_file_size = cur_size;
m_last_modified = cur_modified;
- m_last_modified_string = HTTPTypes::get_date_string( m_last_modified );
+ m_last_modified_string = types::get_date_string( m_last_modified );
// read new contents
read();
@@ -748,11 +749,11 @@ bool DiskFile::checkUpdated(void)
// DiskFileSender member functions
-DiskFileSender::DiskFileSender(DiskFile& file, pion::net::HTTPRequestPtr& request,
- pion::net::TCPConnectionPtr& tcp_conn,
+DiskFileSender::DiskFileSender(DiskFile& file, pion::http::request_ptr& request,
+ pion::tcp::connection_ptr& tcp_conn,
unsigned long max_chunk_size)
: m_logger(PION_GET_LOGGER("pion.FileService.DiskFileSender")), m_disk_file(file),
- m_writer(pion::net::HTTPResponseWriter::create(tcp_conn, *request, boost::bind(&TCPConnection::finish, tcp_conn))),
+ m_writer(pion::http::response_writer::create(tcp_conn, *request, boost::bind(&connection::finish, tcp_conn))),
m_max_chunk_size(max_chunk_size), m_file_bytes_to_send(0), m_bytes_sent(0)
{
PION_LOG_DEBUG(m_logger, "Preparing to send file"
@@ -760,15 +761,15 @@ DiskFileSender::DiskFileSender(DiskFile&
<< m_disk_file.getFilePath().string());
// set the Content-Type HTTP header using the file's MIME type
- m_writer->getResponse().setContentType(m_disk_file.getMimeType());
+ m_writer->get_response().set_content_type(m_disk_file.getMimeType());
// set Last-Modified header to enable client-side caching
- m_writer->getResponse().addHeader(HTTPTypes::HEADER_LAST_MODIFIED,
+ m_writer->get_response().add_header(types::HEADER_LAST_MODIFIED,
m_disk_file.getLastModifiedString());
// use "200 OK" HTTP response
- m_writer->getResponse().setStatusCode(HTTPTypes::RESPONSE_CODE_OK);
- m_writer->getResponse().setStatusMessage(HTTPTypes::RESPONSE_MESSAGE_OK);
+ m_writer->get_response().set_status_code(types::RESPONSE_CODE_OK);
+ m_writer->get_response().set_status_message(types::RESPONSE_MESSAGE_OK);
}
void DiskFileSender::send(void)
@@ -827,13 +828,13 @@ void DiskFileSender::send(void)
}
// send the content
- m_writer->writeNoCopy(file_content_ptr, m_file_bytes_to_send);
+ m_writer->write_no_copy(file_content_ptr, m_file_bytes_to_send);
if (m_bytes_sent + m_file_bytes_to_send >= m_disk_file.getFileSize()) {
// this is the last piece of data to send
if (m_bytes_sent > 0) {
// send last chunk in a series
- m_writer->sendFinalChunk(boost::bind(&DiskFileSender::handleWrite,
+ m_writer->send_final_chunk(boost::bind(&DiskFileSender::handleWrite,
shared_from_this(),
boost::asio::placeholders::error,
boost::asio::placeholders::bytes_transferred));
@@ -846,7 +847,7 @@ void DiskFileSender::send(void)
}
} else {
// there will be more data -> send a chunk
- m_writer->sendChunk(boost::bind(&DiskFileSender::handleWrite,
+ m_writer->send_chunk(boost::bind(&DiskFileSender::handleWrite,
shared_from_this(),
boost::asio::placeholders::error,
boost::asio::placeholders::bytes_transferred));
@@ -860,7 +861,7 @@ void DiskFileSender::handleWrite(const b
if (write_error) {
// encountered error sending response data
- m_writer->getTCPConnection()->setLifecycle(TCPConnection::LIFECYCLE_CLOSE); // make sure it will get closed
+ m_writer->get_connection()->set_lifecycle(connection::LIFECYCLE_CLOSE); // make sure it will get closed
PION_LOG_WARN(m_logger, "Error sending file (" << write_error.message() << ')');
} else {
// response data sent OK
@@ -874,7 +875,7 @@ void DiskFileSender::handleWrite(const b
PION_LOG_DEBUG(m_logger, "Sent "
<< (m_file_bytes_to_send < m_disk_file.getFileSize() ? "file chunk" : "complete file")
<< " of " << m_file_bytes_to_send << " bytes (finished"
- << (m_writer->getTCPConnection()->getKeepAlive() ? ", keeping alive)" : ", closing)") );
+ << (m_writer->get_connection()->get_keep_alive() ? ", keeping alive)" : ", closing)") );
} else {
// NOT finished sending
PION_LOG_DEBUG(m_logger, "Sent file chunk of " << m_file_bytes_to_send << " bytes");
@@ -884,10 +885,10 @@ void DiskFileSender::handleWrite(const b
}
if (finished_sending) {
- // TCPConnection::finish() calls TCPServer::finishConnection, which will either:
+ // connection::finish() calls TCPServer::finishConnection, which will either:
// a) call HTTPServer::handleConnection again if keep-alive is true; or,
// b) close the socket and remove it from the server's connection pool
- m_writer->getTCPConnection()->finish();
+ m_writer->get_connection()->finish();
} else {
send();
}
@@ -897,7 +898,7 @@ void DiskFileSender::handleWrite(const b
} // end namespace plugins
} // end namespace pion
-
+#if 0
/// creates new FileService objects
extern "C" PION_SERVICE_API pion::plugins::FileService *pion_create_FileService(void)
{
@@ -909,3 +910,5 @@ extern "C" PION_SERVICE_API void pion_de
{
delete service_ptr;
}
+#endif
+
diff -rup fatrat-1.2.0_beta2/src/remote/pion/FileService.hpp fatrat-1.2.0_beta2.new/src/remote/pion/FileService.hpp
--- fatrat-1.2.0_beta2/src/remote/pion/FileService.hpp 2012-07-14 12:44:27.000000000 +0100
+++ fatrat-1.2.0_beta2.new/src/remote/pion/FileService.hpp 2013-04-29 19:17:17.079967487 +0100
@@ -16,13 +16,13 @@
#include <boost/thread/once.hpp>
#include <boost/thread/mutex.hpp>
#include <boost/shared_array.hpp>
-#include <pion/PionLogger.hpp>
-#include <pion/PionException.hpp>
-#include <pion/PionHashMap.hpp>
-#include <pion/net/WebService.hpp>
-#include <pion/net/HTTPRequest.hpp>
-#include <pion/net/HTTPResponseWriter.hpp>
-#include <pion/net/HTTPServer.hpp>
+#include <pion/logger.hpp>
+#include <pion/error.hpp>
+#include <pion/hash_map.hpp>
+#include <pion/http/plugin_service.hpp>
+#include <pion/http/request.hpp>
+#include <pion/http/response_writer.hpp>
+#include <pion/http/server.hpp>
#include <string>
#include <map>
@@ -144,8 +144,8 @@ public:
*/
static inline boost::shared_ptr<DiskFileSender>
create(DiskFile& file,
- pion::net::HTTPRequestPtr& request,
- pion::net::TCPConnectionPtr& tcp_conn,
+ pion::http::request_ptr& request,
+ pion::tcp::connection_ptr& tcp_conn,
unsigned long max_chunk_size = 0)
{
return boost::shared_ptr<DiskFileSender>(new DiskFileSender(file, request,
@@ -161,11 +161,11 @@ public:
void send(void);
/// sets the logger to be used
- inline void setLogger(PionLogger log_ptr) { m_logger = log_ptr; }
+ inline void setLogger(pion::logger log_ptr) { m_logger = log_ptr; }
/// returns the logger currently in use
- inline PionLogger getLogger(void) { return m_logger; }
- inline pion::net::HTTPResponseWriterPtr getWriter() { return m_writer; }
+ inline pion::logger getLogger(void) { return m_logger; }
+ inline pion::http::response_writer_ptr getWriter() { return m_writer; }
protected:
@@ -179,8 +179,8 @@ protected:
* @param max_chunk_size sets the maximum chunk size
*/
DiskFileSender(DiskFile& file,
- pion::net::HTTPRequestPtr& request,
- pion::net::TCPConnectionPtr& tcp_conn,
+ pion::http::request_ptr& request,
+ pion::tcp::connection_ptr& tcp_conn,
unsigned long max_chunk_size);
/**
@@ -194,7 +194,7 @@ protected:
/// primary logging interface used by this class
- PionLogger m_logger;
+ pion::logger m_logger;
private:
@@ -203,7 +203,7 @@ private:
DiskFile m_disk_file;
/// the HTTP response we are sending
- pion::net::HTTPResponseWriterPtr m_writer;
+ pion::http::response_writer_ptr m_writer;
/// used to read the file from disk if it is not already cached in memory
boost::filesystem::ifstream m_file_stream;
@@ -233,73 +233,78 @@ typedef boost::shared_ptr<DiskFileSender
/// FileService: web service that serves regular files
///
class FileService :
- public pion::net::WebService
+ public pion::http::plugin_service
{
public:
/// exception thrown if the directory configured is not found
- class DirectoryNotFoundException : public PionException {
+ class DirectoryNotFoundException : public pion::exception {
public:
DirectoryNotFoundException(const std::string& dir)
- : PionException("FileService directory not found: ", dir) {}
+ : pion::exception("FileService directory not found") {}
};
/// exception thrown if the directory configuration option is not a directory
- class NotADirectoryException : public PionException {
+ class NotADirectoryException : public pion::exception {
public:
NotADirectoryException(const std::string& dir)
- : PionException("FileService option is not a directory: ", dir) {}
+ : pion::exception("FileService option is not a directory") {}
};
/// exception thrown if the file configured is not found
- class FileNotFoundException : public PionException {
+ class FileNotFoundException : public pion::exception {
public:
FileNotFoundException(const std::string& file)
- : PionException("FileService file not found: ", file) {}
+ : pion::exception("FileService file not found") {}
};
/// exception thrown if the file configuration option is not a file
- class NotAFileException : public PionException {
+ class NotAFileException : public pion::exception {
public:
NotAFileException(const std::string& file)
- : PionException("FileService option is not a file: ", file) {}
+ : pion::exception("FileService option is not a file") {}
};
/// exception thrown if the cache option is set to an invalid value
- class InvalidCacheException : public PionException {
+ class InvalidCacheException : public pion::exception {
public:
InvalidCacheException(const std::string& value)
- : PionException("FileService invalid value for cache option: ", value) {}
+ : pion::exception("FileService invalid value for cache option") {}
};
/// exception thrown if the scan option is set to an invalid value
- class InvalidScanException : public PionException {
+ class InvalidScanException : public pion::exception {
public:
InvalidScanException(const std::string& value)
- : PionException("FileService invalid value for scan option: ", value) {}
+ : pion::exception("FileService invalid value for scan option") {}
};
/// exception thrown if an option is set to an invalid value
- class InvalidOptionValueException : public PionException {
+ class InvalidOptionValueException : public pion::exception {
public:
InvalidOptionValueException(const std::string& option, const std::string& value)
- : PionException("FileService invalid value for " + option + " option: ", value) {}
+ : pion::exception("FileService invalid value for " + option + " option") {}
};
/// exception thrown if we are unable to read a file from disk
- class FileReadException : public PionException {
+ class FileReadException : public pion::exception {
public:
FileReadException(const std::string& value)
- : PionException("FileService unable to read file: ", value) {}
+ : pion::exception("FileService unable to read file: "+value) {}
};
/// exception thrown if we do not know how to respond (should never happen)
- class UndefinedResponseException : public PionException {
+ class UndefinedResponseException : public pion::exception {
public:
UndefinedResponseException(const std::string& value)
- : PionException("FileService has an undefined response: ", value) {}
+ : pion::exception("FileService has an undefined response: "+value) {}
};
+ class UnknownOptionException : public pion::exception {
+ public:
+ UnknownOptionException(const std::string& value)
+ : pion::exception("FileService invalid option name: "+value) {}
+ };
// default constructor and destructor
FileService(void);
@@ -315,11 +320,11 @@ public:
* max_chunk_size:
* writable:
*/
- virtual void setOption(const std::string& name, const std::string& value);
+ virtual void set_option(const std::string& name, const std::string& value);
/// handles requests for FileService
- virtual void operator()(pion::net::HTTPRequestPtr& request,
- pion::net::TCPConnectionPtr& tcp_conn);
+ virtual void operator()(pion::http::request_ptr& request,
+ pion::tcp::connection_ptr& tcp_conn);
/// called when the web service's server is starting
virtual void start(void);
@@ -328,10 +333,10 @@ public:
virtual void stop(void);
/// sets the logger to be used
- inline void setLogger(PionLogger log_ptr) { m_logger = log_ptr; }
+ inline void setLogger(pion::logger log_ptr) { m_logger = log_ptr; }
/// returns the logger currently in use
- inline PionLogger getLogger(void) { return m_logger; }
+ inline pion::logger getLogger(void) { return m_logger; }
protected:
@@ -372,11 +377,11 @@ protected:
*/
static std::string findMIMEType(const std::string& file_name);
- void sendNotFoundResponse(pion::net::HTTPRequestPtr& http_request,
- pion::net::TCPConnectionPtr& tcp_conn);
+ void sendNotFoundResponse(pion::http::request_ptr& http_request,
+ pion::tcp::connection_ptr& tcp_conn);
/// primary logging interface used by this class
- PionLogger m_logger;
+ pion::logger m_logger;
private:
diff -rup fatrat-1.2.0_beta2/src/remote/XmlRpcService.cpp fatrat-1.2.0_beta2.new/src/remote/XmlRpcService.cpp
--- fatrat-1.2.0_beta2/src/remote/XmlRpcService.cpp 2012-07-14 12:44:27.000000000 +0100
+++ fatrat-1.2.0_beta2.new/src/remote/XmlRpcService.cpp 2013-04-29 19:17:17.079967487 +0100
@@ -37,10 +37,10 @@ respects for all of the code used other
#include <QStringList>
#include <QFileInfo>
#include <QTemporaryFile>
-#include <pion/net/HTTPResponseWriter.hpp>
+#include <pion/http/response_writer.hpp>
#include <QtDebug>
-using namespace pion::net;
+using namespace pion::http;
extern QList<Queue*> g_queues;
extern QReadWriteLock g_queuesLock;
@@ -151,9 +151,9 @@ void XmlRpcService::globalInit()
}
-void XmlRpcService::operator()(pion::net::HTTPRequestPtr &request, pion::net::TCPConnectionPtr &tcp_conn)
+void XmlRpcService::operator()(pion::http::request_ptr &request, pion::tcp::connection_ptr &tcp_conn)
{
- if (request->getMethod() != pion::net::HTTPTypes::REQUEST_METHOD_POST)
+ if (request->get_method() != pion::http::types::REQUEST_METHOD_POST)
{
static const std::string NOT_ALLOWED_HTML_START =
"<html><head>\n"
@@ -164,20 +164,20 @@ void XmlRpcService::operator()(pion::net
static const std::string NOT_ALLOWED_HTML_FINISH =
" is not allowed on this server.</p>\n"
"</body></html>\n";
- HTTPResponseWriterPtr writer(HTTPResponseWriter::create(tcp_conn, *request, boost::bind(&TCPConnection::finish, tcp_conn)));
- writer->getResponse().setStatusCode(HTTPTypes::RESPONSE_CODE_METHOD_NOT_ALLOWED);
- writer->getResponse().setStatusMessage(HTTPTypes::RESPONSE_MESSAGE_METHOD_NOT_ALLOWED);
- writer->writeNoCopy(NOT_ALLOWED_HTML_START);
- writer << request->getMethod();
- writer->writeNoCopy(NOT_ALLOWED_HTML_FINISH);
- writer->getResponse().addHeader("Allow", "GET, HEAD");
+ pion::http::response_writer_ptr writer(pion::http::response_writer::create(tcp_conn, *request, boost::bind(&pion::tcp::connection::finish, tcp_conn)));
+ writer->get_response().set_status_code(types::RESPONSE_CODE_METHOD_NOT_ALLOWED);
+ writer->get_response().set_status_message(types::RESPONSE_MESSAGE_METHOD_NOT_ALLOWED);
+ writer->write_no_copy(NOT_ALLOWED_HTML_START);
+ writer << request->get_method();
+ writer->write_no_copy(NOT_ALLOWED_HTML_FINISH);
+ writer->get_response().add_header("Allow", "GET, HEAD");
writer->send();
return;
}
QByteArray data;
- qDebug() << "XML-RPC call:" << request->getContent();
+ qDebug() << "XML-RPC call:" << request->get_content();
try
{
@@ -185,7 +185,7 @@ void XmlRpcService::operator()(pion::net
QList<QVariant> args;
QVariant returnValue;
- XmlRpc::parseCall(request->getContent(), function, args);
+ XmlRpc::parseCall(request->get_content(), function, args);
if(function == "Queue.getTransfers")
{
@@ -240,7 +240,7 @@ void XmlRpcService::operator()(pion::net
throw "400 Bad Request";
}
- HTTPResponseWriterPtr writer(HTTPResponseWriter::create(tcp_conn, *request, boost::bind(&TCPConnection::finish, tcp_conn)));
+ pion::http::response_writer_ptr writer(pion::http::response_writer::create(tcp_conn, *request, boost::bind(&pion::tcp::connection::finish, tcp_conn)));
writer->write(data.data(), data.size());
writer->send();
}
diff -rup fatrat-1.2.0_beta2/src/remote/XmlRpcService.h fatrat-1.2.0_beta2.new/src/remote/XmlRpcService.h
--- fatrat-1.2.0_beta2/src/remote/XmlRpcService.h 2012-07-14 12:44:27.000000000 +0100
+++ fatrat-1.2.0_beta2.new/src/remote/XmlRpcService.h 2013-04-29 19:17:17.079967487 +0100
@@ -34,7 +34,8 @@ respects for all of the code used other
#include <QVariantMap>
#include <QQueue>
#include <QPair>
-#include <pion/net/WebServer.hpp>
+#include <pion/http/server.hpp>
+#include <pion/http/plugin_service.hpp>
#ifndef WITH_WEBINTERFACE
# error This file is not supposed to be included!
@@ -43,12 +44,12 @@ respects for all of the code used other
class Queue;
class Transfer;
-class XmlRpcService : public QObject, public pion::net::WebService
+class XmlRpcService : public QObject, public pion::http::plugin_service
{
Q_OBJECT
public:
XmlRpcService();
- void operator()(pion::net::HTTPRequestPtr &request, pion::net::TCPConnectionPtr &tcp_conn);
+ void operator()(pion::http::request_ptr &request, pion::tcp::connection_ptr &tcp_conn);
static void globalInit();
static void registerFunction(QString name, QVariant (*func)(QList<QVariant>&), QVector<QVariant::Type> arguments);
static void deregisterFunction(QString name);
|