Skip to content
This repository was archived by the owner on Mar 19, 2020. It is now read-only.

Commit 9b5233d

Browse files
committed
initial commit of project
1 parent 95d5c00 commit 9b5233d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+14178
-0
lines changed

Diff for: CMakeLists.txt

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
cmake_minimum_required(VERSION 2.7)
2+
project(xdccget)
3+
4+
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wfatal-errors -Os -std=gnu11")
5+
6+
find_package(PkgConfig REQUIRED)
7+
pkg_search_module(OPENSSL REQUIRED openssl)
8+
9+
if( OPENSSL_FOUND )
10+
include_directories(${OPENSSL_INCLUDE_DIRS})
11+
message(STATUS "Using OpenSSL ${OPENSSL_VERSION}")
12+
else()
13+
# Error; with REQUIRED, pkg_search_module() will throw an error by it's own
14+
endif()
15+
16+
find_package (Threads)
17+
18+
add_definitions(-DENABLE_SSL)
19+
add_definitions(-DDEBUG)
20+
add_definitions(-DFILE_API)
21+
add_definitions(-DENABLE_IPV6)
22+
include_directories(libircclient-include)
23+
24+
set(SOURCE_FILES
25+
libircclient-src/libircclient.c
26+
argument_parser.c
27+
argument_parser.h
28+
config.c
29+
config.h
30+
dirs.c
31+
dirs.h
32+
file.c
33+
file.h
34+
helper.c
35+
helper.h
36+
sds.c
37+
sds.h
38+
xdccget.c
39+
xdccget.h
40+
hashing_algo.c
41+
sph_md5.c)
42+
43+
add_executable(xdccget ${SOURCE_FILES} libircclient-src/portable_endian.h)
44+
target_link_libraries(xdccget ${OPENSSL_LIBRARIES})
45+
target_link_libraries (xdccget ${CMAKE_THREAD_LIBS_INIT})

Diff for: Makefile

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
CFLAGS =-std=gnu11 -DENABLE_SSL -DDEBUG -DENABLE_IPV6 -Wall -Wfatal-errors -Os -I libircclient-include/
2+
LIBS = -lssl -lcrypto -lpthread
3+
PROG = xdccget
4+
5+
SRCS = xdccget.c config.c helper.c argument_parser.c libircclient-src/libircclient.c sds.c dirs.c file.c hashing_algo.c sph_md5.c
6+
OBJ_FILES =
7+
8+
all: gcc
9+
10+
gcc: $(SRCS)
11+
gcc $(CFLAGS) -o $(PROG) $(SRCS) $(OBJ_FILES) $(LIBS)
12+
13+
clang: $(SRCS)
14+
clang $(CFLAGS) -o $(PROG) $(SRCS) $(OBJ_FILES) $(LIBS)
15+
16+
install:
17+
cp ./xdccget /usr/bin/
18+
19+
clean:
20+
rm -f $(PROG)

Diff for: Makefile.FreeBSD

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
CFLAGS = -DENABLE_SSL -DFILE_API -DDEBUG -Wall -Wfatal-errors -g -I libircclient-include/ -I /usr/local/include -L /usr/local/lib
2+
LIBS = -lssl -lcrypto -lpthread -largp
3+
PROG = xdccget
4+
5+
SRCS = xdccget.c config.c helper.c argument_parser.c libircclient-src/libircclient.c sds.c dirs.c file.c hashing_algo.c sph_md5.c
6+
OBJ_FILES =
7+
8+
all: gcc
9+
10+
gcc: $(SRCS)
11+
gcc48 $(CFLAGS) -o $(PROG) $(SRCS) $(OBJ_FILES) $(LIBS)
12+
13+
clang: $(SRCS)
14+
clang $(CFLAGS) -o $(PROG) $(SRCS) $(OBJ_FILES) $(LIBS)
15+
16+
install:
17+
cp ./xdccget /usr/bin/
18+
19+
clean:
20+
rm -f $(PROG)

Diff for: argument_parser.c

+220
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,220 @@
1+
#include <argp.h>
2+
#include <strings.h>
3+
#include <stdlib.h>
4+
#include "helper.h"
5+
6+
#include "argument_parser.h"
7+
8+
9+
const char *argp_program_version = "xdccget 1.0";
10+
const char *argp_program_bug_address ="<[email protected]>";
11+
12+
/* Program documentation. */
13+
static char doc[] =
14+
"xdccgget -- download from cmd with xdcc";
15+
16+
/* A description of the arguments we accept. */
17+
static char args_doc[] = "<server> <channel(s)> <bot cmds>";
18+
19+
/* The options we understand. */
20+
static struct argp_option options[] = {
21+
{"verbose", 'v', 0, 0, "Produce verbose output" },
22+
{"quiet", 'q', 0, 0, "Don't produce any output" },
23+
{"information", 'i', 0, 0, "Produce information output." },
24+
#ifdef ENABLE_IPV6
25+
{"ipv6", '6', 0, 0, "Use ipv6 instead of ipv4 to connect to irc server." },
26+
#endif
27+
{"port", 'p', "<port number>", 0, "Use the following port to connect to server. default is 6667." },
28+
{"directory", 'd', "<download-directory>", 0, "Directory, where to place the files." },
29+
{ 0 }
30+
};
31+
32+
static error_t parse_opt (int key, char *arg, struct argp_state *state);
33+
34+
/* Our argp parser. */
35+
static struct argp argp = { options, parse_opt, args_doc, doc };
36+
37+
/* Parse a single option. */
38+
static error_t parse_opt(int key, char *arg, struct argp_state *state) {
39+
/* Get the input argument from argp_parse, which we
40+
know is a pointer to our arguments structure. */
41+
struct xdccGetConfig *cfg = state->input;
42+
43+
switch (key) {
44+
case 'q':
45+
DBG_OK("setting log-level as quiet.");
46+
cfg->logLevel = LOG_QUIET;
47+
break;
48+
49+
case 'v':
50+
DBG_OK("setting log-level as warn.");
51+
cfg->logLevel = LOG_WARN;
52+
break;
53+
54+
case 'i':
55+
DBG_OK("setting log-level as info.");
56+
cfg->logLevel = LOG_INFO;
57+
break;
58+
59+
case 'd':
60+
DBG_OK("setting target dir as %s.", arg);
61+
cfg->targetDir = sdsnew(arg);
62+
break;
63+
64+
case 'p':
65+
cfg->port = (unsigned short) strtoul(arg, NULL, 0);
66+
DBG_OK("setting port as %u", cfg->port);
67+
break;
68+
69+
#ifdef ENABLE_IPV6
70+
case '6':
71+
cfg_set_bit(cfg, USE_IPV6_FLAG);
72+
break;
73+
#endif
74+
75+
case ARGP_KEY_ARG:
76+
{
77+
if (state->arg_num >= 3)
78+
/* Too many arguments. */
79+
argp_usage(state);
80+
81+
cfg->args[state->arg_num] = arg;
82+
}
83+
break;
84+
85+
case ARGP_KEY_END:
86+
if (state->arg_num < 3)
87+
/* Not enough arguments. */
88+
argp_usage(state);
89+
break;
90+
91+
default:
92+
return ARGP_ERR_UNKNOWN;
93+
}
94+
return 0;
95+
}
96+
97+
void parseArguments(int argc, char **argv, struct xdccGetConfig *cfg) {
98+
/* Parse our arguments; every option seen by parse_opt will
99+
be reflected in arguments. */
100+
int ret = argp_parse(&argp, argc, argv, 0, 0, cfg);
101+
102+
if (ret != 0) {
103+
logprintf(LOG_ERR, "the parsing of the command line options failed");
104+
}
105+
}
106+
107+
struct dccDownload* newDccDownload(sds botNick, sds xdccCmd) {
108+
struct dccDownload *t = (struct dccDownload*) Malloc(sizeof (struct dccDownload));
109+
t->botNick = botNick;
110+
t->xdccCmd = xdccCmd;
111+
return t;
112+
}
113+
114+
void freeDccDownload(struct dccDownload *t) {
115+
sdsfree(t->botNick);
116+
sdsfree(t->xdccCmd);
117+
FREE(t);
118+
}
119+
120+
struct dccDownloadProgress* newDccProgress(char *completePath, irc_dcc_size_t complFileSize) {
121+
struct dccDownloadProgress *t = (struct dccDownloadProgress*) Malloc(sizeof (struct dccDownloadProgress));
122+
t->completeFileSize = complFileSize;
123+
t->sizeRcvd = 0;
124+
t->sizeNow = 0;
125+
t->sizeLast = 0;
126+
t->completePath = completePath;
127+
return t;
128+
129+
}
130+
131+
void freeDccProgress(struct dccDownloadProgress *progress) {
132+
sdsfree(progress->completePath);
133+
FREE(progress);
134+
}
135+
136+
void parseDccDownload(char *dccDownloadString, sds *nick, sds *xdccCmd) {
137+
size_t i;
138+
size_t strLen = strlen(dccDownloadString);
139+
size_t spaceFound = 0;
140+
141+
for (i = 0; i < strLen; i++) {
142+
if (dccDownloadString[i] == ' ') {
143+
spaceFound = i;
144+
break;
145+
}
146+
}
147+
148+
size_t nickLen = spaceFound + 1;
149+
size_t cmdLen = (strLen - spaceFound) + 1;
150+
151+
DBG_OK("nickLen = %zu, cmdLen = %zu", nickLen, cmdLen);
152+
153+
sds nickPtr = sdsnewlen(NULL, nickLen);
154+
sds xdccPtr = sdsnewlen(NULL, cmdLen);
155+
156+
nickPtr = sdscpylen(nickPtr, dccDownloadString, nickLen - 1);
157+
xdccPtr = sdscpylen(xdccPtr, dccDownloadString + (spaceFound + 1), cmdLen - 1);
158+
159+
*nick = nickPtr;
160+
*xdccCmd = xdccPtr;
161+
}
162+
163+
sds* parseChannels(char *channelString, int *numChannels) {
164+
int numFound = 0;
165+
char *seperator = ",";
166+
sds *splittedString = sdssplitlen(channelString, strlen(channelString), seperator, strlen(seperator), &numFound);
167+
if (splittedString == NULL) {
168+
DBG_ERR("splittedString = NULL, cant continue from here.");
169+
}
170+
int i = 0;
171+
172+
for (i = 0; i < numFound; i++) {
173+
sdstrim(splittedString[i], " \t");
174+
DBG_OK("%d: '%s'", i, splittedString[i]);
175+
}
176+
177+
*numChannels = numFound;
178+
179+
return splittedString;
180+
}
181+
182+
struct dccDownload** parseDccDownloads(char *dccDownloadString, unsigned int *numDownloads) {
183+
int numFound = 0;
184+
int i = 0, j = 0;
185+
char *seperator = ",";
186+
187+
sds *splittedString = sdssplitlen(dccDownloadString, strlen(dccDownloadString), seperator, strlen(seperator), &numFound);
188+
189+
if (splittedString == NULL) {
190+
DBG_ERR("splittedString = NULL, cant continue from here.");
191+
}
192+
193+
struct dccDownload **dccDownloadArray = (struct dccDownload**) Calloc(numFound + 1, sizeof (struct dccDownload*));
194+
195+
*numDownloads = numFound;
196+
197+
for (i = 0; i < numFound; i++) {
198+
sdstrim(splittedString[i], " \t");
199+
sds nick = NULL;
200+
sds xdccCmd = NULL;
201+
DBG_OK("%d: '%s'\n", i, splittedString[i]);
202+
parseDccDownload(splittedString[i], &nick, &xdccCmd);
203+
DBG_OK("%d: '%s' '%s'\n", i, nick, xdccCmd);
204+
if (nick != NULL && xdccCmd != NULL) {
205+
dccDownloadArray[j] = newDccDownload(nick, xdccCmd);
206+
j++;
207+
}
208+
else {
209+
if (nick != NULL)
210+
sdsfree(nick);
211+
212+
if (xdccCmd != NULL)
213+
sdsfree(xdccCmd);
214+
}
215+
sdsfree(splittedString[i]);
216+
}
217+
218+
FREE(splittedString);
219+
return dccDownloadArray;
220+
}

Diff for: argument_parser.h

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#ifndef ARGUMENT_PARSER_H
2+
#define ARGUMENT_PARSER_H
3+
4+
#include "sds.h"
5+
#include "helper.h"
6+
7+
struct dccDownload {
8+
sds botNick;
9+
sds xdccCmd;
10+
};
11+
12+
struct dccDownloadProgress {
13+
unsigned long key;
14+
irc_dcc_size_t completeFileSize;
15+
irc_dcc_size_t sizeRcvd;
16+
irc_dcc_size_t sizeNow;
17+
irc_dcc_size_t sizeLast;
18+
sds completePath;
19+
};
20+
21+
void parseArguments(int argc, char **argv, struct xdccGetConfig *args);
22+
23+
struct dccDownload* newDccDownload(char *botNick, char *xdccCmd);
24+
25+
void freeDccDownload(struct dccDownload *t);
26+
27+
struct dccDownloadProgress* newDccProgress(char *filename, irc_dcc_size_t complFileSize);
28+
29+
void freeDccProgress(struct dccDownloadProgress *progress);
30+
31+
void parseDccDownload (char *dccDownloadString, char **nick, char **xdccCmd);
32+
33+
sds* parseChannels(char *channelString, int *numChannels);
34+
35+
struct dccDownload** parseDccDownloads(char *dccDownloadString, unsigned int *numDownloads);
36+
37+
#endif

0 commit comments

Comments
 (0)