Start attempting to actually do IRC
This commit is contained in:
parent
65d123ce2c
commit
a66071288a
5 changed files with 75 additions and 5 deletions
|
@ -11,7 +11,7 @@ find_package(Qt5Widgets REQUIRED)
|
||||||
|
|
||||||
include_directories(${NSPR_INCLUDE_DIRS} ${NSS_INCLUDE_DIRS})
|
include_directories(${NSPR_INCLUDE_DIRS} ${NSS_INCLUDE_DIRS})
|
||||||
|
|
||||||
set(SOURCE_FILES main.cpp dns.cpp ui.cpp)
|
set(SOURCE_FILES main.cpp dns.cpp ui.cpp irc.cpp)
|
||||||
add_executable(oksirc ${SOURCE_FILES})
|
add_executable(oksirc ${SOURCE_FILES})
|
||||||
|
|
||||||
target_link_libraries(oksirc ${NSPR_LIBRARIES} ${NSS_LIBRARIES} Qt5::Widgets)
|
target_link_libraries(oksirc ${NSPR_LIBRARIES} ${NSS_LIBRARIES} Qt5::Widgets)
|
33
irc.cpp
Normal file
33
irc.cpp
Normal file
|
@ -0,0 +1,33 @@
|
||||||
|
//
|
||||||
|
// Created by onekopaka on 12/8/18.
|
||||||
|
//
|
||||||
|
|
||||||
|
#include <memory.h>
|
||||||
|
#include "irc.h"
|
||||||
|
|
||||||
|
irc::irc(PRFileDesc* fileDesc, char* netName, ui* uiInstance) {
|
||||||
|
this->fd = fileDesc;
|
||||||
|
this->netName = strdup(netName);
|
||||||
|
this->uiInst = uiInstance;
|
||||||
|
}
|
||||||
|
|
||||||
|
void irc::run() {
|
||||||
|
PRPollDesc pollDesc;
|
||||||
|
pollDesc.fd = this->fd;
|
||||||
|
pollDesc.in_flags = PR_POLL_READ | PR_POLL_WRITE | PR_POLL_EXCEPT;
|
||||||
|
pollDesc.out_flags = 0;
|
||||||
|
|
||||||
|
PRInt32 result = PR_Poll(&pollDesc, 1, PR_INTERVAL_NO_TIMEOUT);
|
||||||
|
while(result != -1) {
|
||||||
|
if(result > 0) {
|
||||||
|
if(pollDesc.out_flags & PR_POLL_READ) {
|
||||||
|
char* buf = new char[1024];
|
||||||
|
PRInt32 bytesRead = PR_Read(this->fd, buf, 1024);
|
||||||
|
uiInst->mainLog->appendPlainText(buf);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
result = PR_Poll(&pollDesc, 1, PR_INTERVAL_NO_TIMEOUT);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
26
irc.h
Normal file
26
irc.h
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
//
|
||||||
|
// Created by onekopaka on 12/8/18.
|
||||||
|
//
|
||||||
|
|
||||||
|
#ifndef OKSIRC_IRC_H
|
||||||
|
#define OKSIRC_IRC_H
|
||||||
|
#include <ctime>
|
||||||
|
#include <nspr.h>
|
||||||
|
#include "ui.h"
|
||||||
|
|
||||||
|
|
||||||
|
class irc {
|
||||||
|
public:
|
||||||
|
irc(PRFileDesc*, char*, ui*);
|
||||||
|
void run(void);
|
||||||
|
|
||||||
|
private:
|
||||||
|
char* netName;
|
||||||
|
time_t lastPing;
|
||||||
|
PRFileDesc* fd;
|
||||||
|
ui* uiInst;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
#endif //OKSIRC_IRC_H
|
15
main.cpp
15
main.cpp
|
@ -1,7 +1,6 @@
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include "dns.h"
|
#include "dns.h"
|
||||||
|
|
||||||
|
|
||||||
// NSPR include files
|
// NSPR include files
|
||||||
#include <prerror.h>
|
#include <prerror.h>
|
||||||
#include <prinit.h>
|
#include <prinit.h>
|
||||||
|
@ -19,6 +18,7 @@
|
||||||
|
|
||||||
// Qt-dependent Include Files, should come after NSPR / NSS
|
// Qt-dependent Include Files, should come after NSPR / NSS
|
||||||
#include "ui.h"
|
#include "ui.h"
|
||||||
|
#include "irc.h"
|
||||||
|
|
||||||
NSSInitContext *nssContext;
|
NSSInitContext *nssContext;
|
||||||
SECMODModule *builtInRootsMod;
|
SECMODModule *builtInRootsMod;
|
||||||
|
@ -87,6 +87,11 @@ void init() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void runIrc(void* args) {
|
||||||
|
irc* ircInst = (irc *) args;
|
||||||
|
ircInst->run();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
int main(int argc, char *argv[]) {
|
int main(int argc, char *argv[]) {
|
||||||
init();
|
init();
|
||||||
|
@ -105,7 +110,7 @@ int main(int argc, char *argv[]) {
|
||||||
|
|
||||||
PRFileDesc *tcpSocket = PR_OpenTCPSocket(PR_AF_INET6);
|
PRFileDesc *tcpSocket = PR_OpenTCPSocket(PR_AF_INET6);
|
||||||
PRFileDesc *model = PR_NewTCPSocket();
|
PRFileDesc *model = PR_NewTCPSocket();
|
||||||
theAddr.ipv6.port = PR_htons(443);
|
theAddr.ipv6.port = PR_htons(6697);
|
||||||
theAddr.raw.family = PR_AF_INET6;
|
theAddr.raw.family = PR_AF_INET6;
|
||||||
PRFileDesc *nssSocket;
|
PRFileDesc *nssSocket;
|
||||||
PRFileDesc *sslModel = SSL_ImportFD(NULL, model);
|
PRFileDesc *sslModel = SSL_ImportFD(NULL, model);
|
||||||
|
@ -175,6 +180,11 @@ int main(int argc, char *argv[]) {
|
||||||
|
|
||||||
char netBuf[8192];
|
char netBuf[8192];
|
||||||
|
|
||||||
|
irc *ircInst = new irc(nssSocket, "OKSnet", uiInstance);
|
||||||
|
|
||||||
|
PRThread* ircThread = PR_CreateThread(PR_SYSTEM_THREAD, runIrc, ircInst, PR_PRIORITY_NORMAL, PR_LOCAL_THREAD,
|
||||||
|
PR_JOINABLE_THREAD, 0);
|
||||||
|
|
||||||
// TEMP: Retreiving test file from HTTP daemon w/ TLS
|
// TEMP: Retreiving test file from HTTP daemon w/ TLS
|
||||||
// Send the request
|
// Send the request
|
||||||
snprintf(netBuf, sizeof(netBuf), "GET /junk/testfile.txt HTTP/1.0\r\nHost: buyvm.theoks.net\r\nUser-Agent: oksirc-testing\r\n\r\n");
|
snprintf(netBuf, sizeof(netBuf), "GET /junk/testfile.txt HTTP/1.0\r\nHost: buyvm.theoks.net\r\nUser-Agent: oksirc-testing\r\n\r\n");
|
||||||
|
@ -219,3 +229,4 @@ int main(int argc, char *argv[]) {
|
||||||
|
|
||||||
return qAppRetCode;
|
return qAppRetCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
2
ui.cpp
2
ui.cpp
|
@ -5,7 +5,7 @@ ui::ui(int argc, char **argv) {
|
||||||
this->argv = argv;
|
this->argv = argv;
|
||||||
app = new QApplication(this->argc, this->argv);
|
app = new QApplication(this->argc, this->argv);
|
||||||
mainWindow = new QWidget();
|
mainWindow = new QWidget();
|
||||||
mainWindow->resize(1280, 720);
|
mainWindow->resize(1600, 900);
|
||||||
mainWindow->setWindowTitle("oksirc - early Qt test");
|
mainWindow->setWindowTitle("oksirc - early Qt test");
|
||||||
|
|
||||||
mainLog = new QPlainTextEdit();
|
mainLog = new QPlainTextEdit();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue