Start attempting to actually do IRC

This commit is contained in:
Darren VanBuren 2018-12-11 03:15:54 -08:00
parent 65d123ce2c
commit a66071288a
5 changed files with 75 additions and 5 deletions

View file

@ -11,7 +11,7 @@ find_package(Qt5Widgets REQUIRED)
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})
target_link_libraries(oksirc ${NSPR_LIBRARIES} ${NSS_LIBRARIES} Qt5::Widgets)

33
irc.cpp Normal file
View 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
View 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

View file

@ -1,7 +1,6 @@
#include <iostream>
#include "dns.h"
// NSPR include files
#include <prerror.h>
#include <prinit.h>
@ -19,6 +18,7 @@
// Qt-dependent Include Files, should come after NSPR / NSS
#include "ui.h"
#include "irc.h"
NSSInitContext *nssContext;
SECMODModule *builtInRootsMod;
@ -87,6 +87,11 @@ void init() {
}
}
void runIrc(void* args) {
irc* ircInst = (irc *) args;
ircInst->run();
}
int main(int argc, char *argv[]) {
init();
@ -105,7 +110,7 @@ int main(int argc, char *argv[]) {
PRFileDesc *tcpSocket = PR_OpenTCPSocket(PR_AF_INET6);
PRFileDesc *model = PR_NewTCPSocket();
theAddr.ipv6.port = PR_htons(443);
theAddr.ipv6.port = PR_htons(6697);
theAddr.raw.family = PR_AF_INET6;
PRFileDesc *nssSocket;
PRFileDesc *sslModel = SSL_ImportFD(NULL, model);
@ -175,6 +180,11 @@ int main(int argc, char *argv[]) {
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
// 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");
@ -218,4 +228,5 @@ int main(int argc, char *argv[]) {
NSS_ShutdownContext(nssContext);
return qAppRetCode;
}
}

2
ui.cpp
View file

@ -5,7 +5,7 @@ ui::ui(int argc, char **argv) {
this->argv = argv;
app = new QApplication(this->argc, this->argv);
mainWindow = new QWidget();
mainWindow->resize(1280, 720);
mainWindow->resize(1600, 900);
mainWindow->setWindowTitle("oksirc - early Qt test");
mainLog = new QPlainTextEdit();