Skip to content

Commit a09ab6b

Browse files
committed
style: Style fixes.
1 parent f7728cf commit a09ab6b

File tree

7 files changed

+82
-68
lines changed

7 files changed

+82
-68
lines changed

Makefile

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ OBJS=$(SRCS:.cpp=.o)
55
TARGET=libi2psam.a
66

77
$(TARGET): $(OBJS)
8-
$(AR) $(ARFLAGS) $(TARGET) $(OBJS)
8+
$(AR) $(ARFLAGS) $(TARGET) $(OBJS)
99

1010
LOADLIBES=-L./ -li2psam
1111

1212
eepget: eepget.cpp $(TARGET)
1313

1414
clean:
15-
$(RM) $(TARGET) $(OBJS) eepget
15+
$(RM) $(TARGET) $(OBJS) eepget

README.md

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
[![License](https://img.shields.io/github/license/i2p/i2psam.svg)](https://github.com/i2p/i2psam/blob/master/LICENSE)
2+
13
# i2psam
24

35
A C++ library for the [SAM v3 API](https://geti2p.net/en/docs/api/samv3).

compat.h

+17-14
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* Distributed under the MIT software license, see the accompanying
77
* file COPYING or http://www.opensource.org/licenses/mit-license.php.
88
*
9-
* see full documentation about SAM at http://www.i2p2.i2p/samv3.html
9+
* See full documentation about SAM at http://www.i2p2.i2p/samv3.html
1010
*/
1111

1212
#ifndef I2PSAM_COMPAT_H
@@ -16,29 +16,30 @@
1616

1717
#ifdef _WIN32_WINNT
1818
#undef _WIN32_WINNT
19-
20-
#endif
19+
#endif // _WIN32_WINNT
2120

2221
#define _WIN32_WINNT 0x0501
2322
#ifndef WIN32_LEAN_AND_MEAN
2423
#define WIN32_LEAN_AND_MEAN 1
25-
#endif
24+
#endif // WIN32_LEAN_AND_MEAN
2625

2726
#ifndef NOMINMAX
2827
#define NOMINMAX
29-
#endif
28+
#endif // NOMINMAX
3029

3130
#ifdef FD_SETSIZE
3231
#undef FD_SETSIZE // prevent redefinition compiler warning
33-
#endif
32+
#endif // FD_SETSIZE
3433

3534
#define FD_SETSIZE 1024 // max number of fds in fd_set
3635

3736
#include <winsock2.h> // Must be included before mswsock.h and windows.h
3837
#include <mswsock.h>
3938
#include <windows.h>
4039
#include <ws2tcpip.h>
41-
#else // NO WIN32
40+
41+
#else // WIN32
42+
4243
#include <sys/fcntl.h>
4344
#include <sys/mman.h>
4445
#include <sys/socket.h>
@@ -54,7 +55,7 @@
5455

5556
#ifdef WIN32
5657
#define MSG_DONTWAIT 0
57-
#else
58+
#else // WIN32
5859
typedef u_int SOCKET;
5960
#include "errno.h"
6061
#define WSAGetLastError() errno
@@ -68,32 +69,34 @@ typedef u_int SOCKET;
6869
#define WSAENOTSOCK EBADF
6970
#define INVALID_SOCKET (SOCKET)(~0)
7071
#define SOCKET_ERROR -1
71-
#endif
72+
#endif // WIN32
7273

7374
#ifdef WIN32
7475
#ifndef S_IRUSR
7576
#define S_IRUSR 0400
7677
#define S_IWUSR 0200
77-
#endif
78-
#else
78+
#endif // S_IRUSR
79+
#else // WIN32
7980
#define MAX_PATH 1024
80-
#endif
81+
#endif // WIN32
8182

8283
// As Solaris does not have the MSG_NOSIGNAL flag for send(2) syscall, it is defined as 0
8384
#if !defined(HAVE_MSG_NOSIGNAL) && !defined(MSG_NOSIGNAL)
8485
#define MSG_NOSIGNAL 0
8586
#endif
8687

8788
#ifndef WIN32
89+
8890
// PRIO_MAX is not defined on Solaris
8991
#ifndef PRIO_MAX
9092
#define PRIO_MAX 20
91-
#endif
93+
#endif // PRIO_MAX
94+
9295
#define THREAD_PRIORITY_LOWEST PRIO_MAX
9396
#define THREAD_PRIORITY_BELOW_NORMAL 2
9497
#define THREAD_PRIORITY_NORMAL 0
9598
#define THREAD_PRIORITY_ABOVE_NORMAL (-2)
96-
#endif
99+
#endif // WIN32
97100

98101
size_t strnlen_int(const char *start, size_t max_len);
99102

eepget.cpp

+21-17
Original file line numberDiff line numberDiff line change
@@ -4,29 +4,33 @@
44
* Distributed under the MIT software license, see the accompanying
55
* file LICENSE or http://www.opensource.org/licenses/mit-license.php.
66
*
7-
* see full documentation about SAM at http://www.i2p2.i2p/samv3.html
7+
* See full documentation about SAM at http://www.i2p2.i2p/samv3.html
88
*/
99

1010
#include "i2psam.h"
1111

12-
#include <iostream>
13-
1412
int main(int argc, char **argv)
1513
{
16-
if (argc < 2) {
17-
std::cerr << "Usage: eepget <hostname.i2p>" << std::endl;
18-
return 1;
14+
if (argc < 2)
15+
{
16+
std::cerr << "Usage: eepget <hostname.i2p>" << std::endl;
17+
return 1;
1918
}
20-
std::string target(argv[1]);
21-
SAM::StreamSession s("eepget");
22-
auto lookupResult = s.namingLookup(target);
23-
auto connResult = s.connect(lookupResult.value, false);
24-
auto conn = connResult.value.get();
25-
conn->write("GET / HTTP/1.1\r\n\r\n");
26-
auto reply = conn->read();
27-
while (!reply.empty()) {
28-
std::cout << reply << std::flush;
29-
reply = conn->read();
19+
20+
std::string target(argv[1]);
21+
SAM::StreamSession s("eepget");
22+
auto lookupResult = s.namingLookup(target);
23+
auto connResult = s.connect(lookupResult.value, false);
24+
auto conn = connResult.value.get();
25+
conn->write("GET / HTTP/1.1\r\n\r\n");
26+
auto reply = conn->read();
27+
28+
while (!reply.empty())
29+
{
30+
std::cout << reply << std::flush;
31+
reply = conn->read();
3032
}
31-
conn->close();
33+
34+
std::cout << std::endl;
35+
conn->close();
3236
}

i2psam-c.h

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* c wrapper for i2psam
2+
* C wrapper for i2psam
33
* Author: jeff
44
* License: MIT
55
* probably contains bugs :-DDDD
@@ -15,7 +15,8 @@ struct i2psam_destination;
1515
struct i2psam_stream_session;
1616
struct i2psam_socket;
1717

18-
struct i2psam_stream_settings {
18+
struct i2psam_stream_settings
19+
{
1920
/**
2021
* hostname of sam interface
2122
*/

i2psam.cpp

+32-28
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Distributed under the MIT software license, see the accompanying
88
* file LICENSE or http://www.opensource.org/licenses/mit-license.php.
99
*
10-
* see full documentation about SAM at http://www.i2p2.i2p/samv3.html
10+
* See full documentation about SAM at http://www.i2p2.i2p/samv3.html
1111
*/
1212

1313
#include <ctime>
@@ -192,7 +192,7 @@ void I2pSocket::close()
192192
::closesocket(socket_);
193193
#else
194194
::close(socket_);
195-
#endif
195+
#endif // WIN32
196196
socket_ = INVALID_SOCKET;
197197
}
198198
}
@@ -223,7 +223,7 @@ SAMSession::SAMSession(
223223
{
224224
#ifdef DEBUG_ON_STDOUT
225225
std::cout << "Created a brand new SAM stream session (" << sessionID_ << ")" << std::endl;
226-
#endif
226+
#endif // DEBUG_ON_STDOUT
227227
}
228228

229229
SAMSession::SAMSession(SAMSession& rhs)
@@ -238,7 +238,7 @@ SAMSession::SAMSession(SAMSession& rhs)
238238
rhs.socket_.close();
239239
#ifdef DEBUG_ON_STDOUT
240240
std::cout << "Created a new SAM session (" << sessionID_ << ") from another (" << rhs.sessionID_ << ")" << std::endl;
241-
#endif
241+
#endif // DEBUG_ON_STDOUT
242242
}
243243

244244
/*static*/
@@ -260,7 +260,7 @@ std::string SAMSession::generateSessionID()
260260

261261
#ifdef DEBUG_ON_STDOUT
262262
std::cout << "Generated session ID: " << result << std::endl;
263-
#endif
263+
#endif // DEBUG_ON_STDOUT
264264
return result;
265265
}
266266

@@ -308,12 +308,12 @@ RequestResult<const FullDestination> SAMSession::destGenerate() const
308308

309309
FullDestination SAMSession::createSession(const std::string& destination)
310310
{
311-
return createSession(destination, SAM_SIGNATURE_TYPE);
311+
return createSession(destination, SAM_SIGNATURE_TYPE);
312312
}
313313

314314
FullDestination SAMSession::createSession(const std::string& destination, const std::string& sigType)
315315
{
316-
return createSession(destination, sigType, i2pOptions_);
316+
return createSession(destination, sigType, i2pOptions_);
317317
}
318318

319319
void SAMSession::fallSick() const { isSick_ = true; }
@@ -462,7 +462,7 @@ StreamSession::StreamSession(
462462
myDestination_ = createStreamSession(destination);
463463
#ifdef DEBUG_ON_STDOUT
464464
std::cout << "Created a brand new SAM stream session (" << sessionID_ << ")" << std::endl;
465-
#endif
465+
#endif // DEBUG_ON_STDOUT
466466
}
467467

468468
StreamSession::StreamSession(StreamSession &rhs)
@@ -477,15 +477,15 @@ StreamSession::StreamSession(StreamSession &rhs)
477477

478478
#ifdef DEBUG_ON_STDOUT
479479
std::cout << "Created a new SAM stream session (" << sessionID_ << ") from another (" << rhs.sessionID_ << ")" << std::endl;
480-
#endif
480+
#endif // DEBUG_ON_STDOUT
481481
}
482482

483483
StreamSession::~StreamSession()
484484
{
485485
stopForwardingAll();
486486
#ifdef DEBUG_ON_STDOUT
487487
std::cout << "Closing SAM stream session (" << sessionID_ << ") ..." << std::endl;
488-
#endif
488+
#endif // DEBUG_ON_STDOUT
489489
}
490490

491491
RequestResult<std::unique_ptr<I2pSocket>> StreamSession::accept(bool silent)
@@ -678,7 +678,7 @@ DatagramSession::DatagramSession(
678678
myDestination_ = createDatagramSession(destination);
679679
#ifdef DEBUG_ON_STDOUT
680680
std::cout << "Created a brand new SAM datagram session (" << sessionID_ << ")" << std::endl;
681-
#endif
681+
#endif // DEBUG_ON_STDOUT
682682
}
683683

684684
DatagramSession::DatagramSession(DatagramSession &rhs)
@@ -692,24 +692,24 @@ DatagramSession::DatagramSession(DatagramSession &rhs)
692692

693693
#ifdef DEBUG_ON_STDOUT
694694
std::cout << "Created a new SAM datagram session (" << sessionID_ << ") from another (" << rhs.sessionID_ << ")" << std::endl;
695-
#endif
695+
#endif // DEBUG_ON_STDOUT
696696
}
697697

698698
DatagramSession::~DatagramSession()
699699
{
700700
#ifdef DEBUG_ON_STDOUT
701701
std::cout << "Closing SAM datagram session (" << sessionID_ << ") ..." << std::endl;
702-
#endif
702+
#endif // DEBUG_ON_STDOUT
703703
}
704704

705705
FullDestination DatagramSession::createDatagramSession(const std::string& destination)
706706
{
707-
return createDatagramSession(destination, SAM_SIGNATURE_TYPE);
707+
return createDatagramSession(destination, SAM_SIGNATURE_TYPE);
708708
}
709709

710710
FullDestination DatagramSession::createDatagramSession(const std::string& destination, const std::string& sigType)
711711
{
712-
return createDatagramSession(destination, sigType, i2pOptions_);
712+
return createDatagramSession(destination, sigType, i2pOptions_);
713713
}
714714

715715
FullDestination DatagramSession::createDatagramSession(const std::string& destination, const std::string& sigType, const std::string& i2pOptions)
@@ -778,7 +778,7 @@ RawSession::RawSession(
778778
myDestination_ = createRawSession(destination);
779779
#ifdef DEBUG_ON_STDOUT
780780
std::cout << "Created a brand new SAM datagram session (" << sessionID_ << ")" << std::endl;
781-
#endif
781+
#endif // DEBUG_ON_STDOUT
782782
}
783783

784784
RawSession::RawSession(RawSession &rhs)
@@ -791,14 +791,14 @@ RawSession::RawSession(RawSession &rhs)
791791
(void) createRawSession(myDestination_.priv);
792792
#ifdef DEBUG_ON_STDOUT
793793
std::cout << "Created a new SAM datagram session (" << sessionID_ << ") from another (" << rhs.sessionID_ << ")" << std::endl;
794-
#endif
794+
#endif // DEBUG_ON_STDOUT
795795
}
796796

797797
RawSession::~RawSession()
798798
{
799799
#ifdef DEBUG_ON_STDOUT
800800
std::cout << "Closing SAM datagram session (" << sessionID_ << ") ..." << std::endl;
801-
#endif
801+
#endif // DEBUG_ON_STDOUT
802802
}
803803

804804
FullDestination RawSession::createRawSession(const std::string& destination)
@@ -1221,22 +1221,26 @@ int i2psam_is_sick(struct i2psam_stream_session *session)
12211221
struct i2psam_socket *i2psam_accept(struct i2psam_stream_session *session, int silent)
12221222
{
12231223
auto result = session->impl->accept(silent);
1224-
if (result.isOk) {
1225-
struct i2psam_socket *socket = new i2psam_socket;
1226-
socket->impl = std::move(result.value);
1227-
return socket;
1228-
} else
1224+
if (result.isOk)
1225+
{
1226+
struct i2psam_socket *socket = new i2psam_socket;
1227+
socket->impl = std::move(result.value);
1228+
return socket;
1229+
}
1230+
else
12291231
return nullptr;
12301232
}
12311233

12321234
struct i2psam_socket *i2psam_connect(struct i2psam_stream_session *session, const char *destination, int silent)
12331235
{
12341236
auto result = session->impl->connect(destination, silent != 0);
1235-
if (result.isOk) {
1236-
struct i2psam_socket *socket = new i2psam_socket;
1237-
socket->impl = std::move(result.value);
1238-
return socket;
1239-
} else
1237+
if (result.isOk)
1238+
{
1239+
struct i2psam_socket *socket = new i2psam_socket;
1240+
socket->impl = std::move(result.value);
1241+
return socket;
1242+
}
1243+
else
12401244
return nullptr;
12411245
}
12421246

0 commit comments

Comments
 (0)