Separate UI to new file, still not quite complete.

Also fixed code style in files, and settings used by CLion.
This commit is contained in:
Darren VanBuren 2017-07-09 15:17:24 -07:00
parent 4d6ff1e9f8
commit 851c2f79e3
6 changed files with 184 additions and 105 deletions

35
.idea/codeStyleSettings.xml generated Normal file
View file

@ -0,0 +1,35 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectCodeStyleSettingsManager">
<option name="PER_PROJECT_SETTINGS">
<value>
<Objective-C-extensions>
<file>
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Import" />
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Macro" />
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Typedef" />
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Enum" />
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Constant" />
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Global" />
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Struct" />
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="FunctionPredecl" />
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Function" />
</file>
<class>
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Property" />
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Synthesize" />
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="InitMethod" />
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="StaticMethod" />
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="InstanceMethod" />
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="DeallocMethod" />
</class>
<extensions>
<pair source="cpp" header="h" />
<pair source="c" header="h" />
</extensions>
</Objective-C-extensions>
</value>
</option>
<option name="PREFERRED_PROJECT_CODE_STYLE" value="Default (1)" />
</component>
</project>

View file

@ -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) set(SOURCE_FILES main.cpp dns.cpp ui.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)

View file

@ -10,7 +10,7 @@ PRErrorCode LookupName(char *hostname, PRNetAddr *result) {
iter = PR_EnumerateAddrInfo(iter, addrInfos, 0, result); iter = PR_EnumerateAddrInfo(iter, addrInfos, 0, result);
char ipString[80]; char ipString[80];
PRStatus status = PR_NetAddrToString(result, ipString, 75); PRStatus status = PR_NetAddrToString(result, ipString, 75);
if(status == PR_FAILURE) { if (status == PR_FAILURE) {
const PRErrorCode err = PR_GetError(); const PRErrorCode err = PR_GetError();
fprintf(stderr, "Error: Converting PRNetAddr to string %d: %s\n", fprintf(stderr, "Error: Converting PRNetAddr to string %d: %s\n",
err, PR_ErrorToName(err)); err, PR_ErrorToName(err));

View file

@ -1,10 +1,12 @@
#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>
#include <prnetdb.h> #include <prnetdb.h>
#include <prthread.h>
#include <nspr.h> #include <nspr.h>
// NSS include files // NSS include files
@ -15,9 +17,8 @@
#include <sslproto.h> #include <sslproto.h>
#include <prio.h> #include <prio.h>
// Qt Include Files, should come after NSPR / NSS // Qt-dependent Include Files, should come after NSPR / NSS
#include <QtWidgets> #include "ui.h"
#include <QPlainTextEdit>
NSSInitContext *nssContext; NSSInitContext *nssContext;
SECMODModule *builtInRootsMod; SECMODModule *builtInRootsMod;
@ -36,7 +37,7 @@ void init() {
nssContext = nssContext =
NSS_InitContext("sql:/etc/pki/nssdb", "", "", "", NULL, NSS_INIT_READONLY | NSS_INIT_PK11RELOAD); NSS_InitContext("sql:/etc/pki/nssdb", "", "", "", NULL, NSS_INIT_READONLY | NSS_INIT_PK11RELOAD);
if(nssContext == NULL) { if (nssContext == NULL) {
const PRErrorCode err = PR_GetError(); const PRErrorCode err = PR_GetError();
fprintf(stderr, "NSSInitContext failed: Error code %d: %s\n", err, PR_ErrorToName(err)); fprintf(stderr, "NSSInitContext failed: Error code %d: %s\n", err, PR_ErrorToName(err));
exit(1); exit(1);
@ -50,15 +51,15 @@ void init() {
}; };
PRBool foundGoodCipher = PR_FALSE; PRBool foundGoodCipher = PR_FALSE;
for(const PRUint16 *p = goodCiphers; *p != SSL_NULL_WITH_NULL_NULL; ++p) { for (const PRUint16 *p = goodCiphers; *p != SSL_NULL_WITH_NULL_NULL; ++p) {
PRInt32 policy; PRInt32 policy;
if(SSL_CipherPolicyGet(*p, &policy) != SECSuccess) { if (SSL_CipherPolicyGet(*p, &policy) != SECSuccess) {
const PRErrorCode err = PR_GetError(); const PRErrorCode err = PR_GetError();
fprintf(stderr, "Error: Policy for cipher %u: error %d: %s\n", fprintf(stderr, "Error: Policy for cipher %u: error %d: %s\n",
(unsigned)*p, err, PR_ErrorToName(err)); (unsigned) *p, err, PR_ErrorToName(err));
exit(1); exit(1);
} }
if(policy == SSL_ALLOWED) { if (policy == SSL_ALLOWED) {
// Policy allowed this cipher choice // Policy allowed this cipher choice
fprintf(stderr, "Info: found cipher %x\n", (unsigned) *p); fprintf(stderr, "Info: found cipher %x\n", (unsigned) *p);
foundGoodCipher = PR_TRUE; foundGoodCipher = PR_TRUE;
@ -66,8 +67,8 @@ void init() {
} }
} }
if(!foundGoodCipher) { if (!foundGoodCipher) {
if(NSS_SetDomesticPolicy() != SECSuccess) { if (NSS_SetDomesticPolicy() != SECSuccess) {
const PRErrorCode err = PR_GetError(); const PRErrorCode err = PR_GetError();
fprintf(stderr, "Error: NSS_SetDomesticPolicy: error %d: %s\n", fprintf(stderr, "Error: NSS_SetDomesticPolicy: error %d: %s\n",
err, PR_ErrorToName(err)); err, PR_ErrorToName(err));
@ -78,7 +79,7 @@ void init() {
// Initialize trusted certificate store // Initialize trusted certificate store
char module_name[] = "library=libnssckbi.so name=\"Root Certs\""; char module_name[] = "library=libnssckbi.so name=\"Root Certs\"";
builtInRootsMod = SECMOD_LoadUserModule(module_name, NULL, PR_FALSE); builtInRootsMod = SECMOD_LoadUserModule(module_name, NULL, PR_FALSE);
if(builtInRootsMod == NULL || !builtInRootsMod->loaded) { if (builtInRootsMod == NULL || !builtInRootsMod->loaded) {
const PRErrorCode err = PR_GetError(); const PRErrorCode err = PR_GetError();
fprintf(stderr, "Error: Loading built in roots module failed, code %d: %s\n", fprintf(stderr, "Error: Loading built in roots module failed, code %d: %s\n",
err, PR_ErrorToName(err)); err, PR_ErrorToName(err));
@ -86,15 +87,16 @@ void init() {
} }
} }
int main(int argc, char* argv[]) {
int main(int argc, char *argv[]) {
init(); init();
PRNetAddr theAddr; PRNetAddr theAddr;
LookupName((char *)"buyvm.theoks.net", &theAddr); LookupName((char *) "buyvm.theoks.net", &theAddr);
char ipString[80]; char ipString[80];
PRStatus status = PR_NetAddrToString(&theAddr, ipString, 75); PRStatus status = PR_NetAddrToString(&theAddr, ipString, 75);
if(status == PR_FAILURE) { if (status == PR_FAILURE) {
const PRErrorCode err = PR_GetError(); const PRErrorCode err = PR_GetError();
fprintf(stderr, "Error: Converting PRNetAddr to string %d: %s\n", fprintf(stderr, "Error: Converting PRNetAddr to string %d: %s\n",
err, PR_ErrorToName(err)); err, PR_ErrorToName(err));
@ -107,33 +109,16 @@ int main(int argc, char* argv[]) {
PRFileDesc *nssSocket; PRFileDesc *nssSocket;
SSL_ImportFD(NULL, tcpSocket); SSL_ImportFD(NULL, tcpSocket);
QApplication app(argc, argv);
QWidget mainWindow;
mainWindow.resize(1280, 720);
mainWindow.setWindowTitle("oksirc - early Qt test");
QPlainTextEdit *mainLog = new QPlainTextEdit();
mainLog->setReadOnly(true);
QLineEdit *textEntry = new QLineEdit();
QPushButton *sendButton = new QPushButton(QApplication::translate("send", "Send"));
QHBoxLayout *entryLineLayout = new QHBoxLayout(); ui *uiInstance = new ui(argc, argv);
entryLineLayout->addWidget(textEntry); int qAppRetCode = uiInstance->exec();
entryLineLayout->addWidget(sendButton);
QVBoxLayout *mainLogAndLineLayout = new QVBoxLayout();
mainLogAndLineLayout->addWidget(mainLog);
mainLogAndLineLayout->addLayout(entryLineLayout);
mainWindow.setLayout(mainLogAndLineLayout);
mainWindow.show();
textEntry->setFocus();
char messageBuf[1024]; char messageBuf[1024];
sprintf(messageBuf, "Found IP Address: %s", ipString); sprintf(messageBuf, "Found IP Address: %s", ipString);
mainLog->appendPlainText(messageBuf); uiInstance->mainLog->appendPlainText(messageBuf);
SECMOD_DestroyModule(builtInRootsMod); SECMOD_DestroyModule(builtInRootsMod);
NSS_ShutdownContext(nssContext); NSS_ShutdownContext(nssContext);
return app.exec(); return qAppRetCode;
} }

35
ui.cpp Normal file
View file

@ -0,0 +1,35 @@
#include "ui.h"
ui::ui(int argc, char **argv) {
app = new QApplication(argc, argv);
mainWindow = new QWidget();
mainWindow->resize(1280, 720);
mainWindow->setWindowTitle("oksirc - early Qt test");
mainLog = new QPlainTextEdit();
mainLog->setReadOnly(true);
textEntry = new QLineEdit();
QPushButton *sendButton = new QPushButton(QApplication::translate("send", "Send"));
QObject::connect(sendButton, &QPushButton::clicked, this, &ui::sendButtonClicked);
QHBoxLayout *entryLineLayout = new QHBoxLayout();
entryLineLayout->addWidget(textEntry);
entryLineLayout->addWidget(sendButton);
QVBoxLayout *mainLogAndLineLayout = new QVBoxLayout();
mainLogAndLineLayout->addWidget(mainLog);
mainLogAndLineLayout->addLayout(entryLineLayout);
mainWindow->setLayout(mainLogAndLineLayout);
mainWindow->show();
textEntry->setFocus();
}
int ui::exec() {
return app->exec();
}
void ui::sendButtonClicked(bool checked) {
this->mainLog->appendPlainText("Send button clicked!");
this->mainLog->appendPlainText(textEntry->text());
textEntry->clear();
}

24
ui.h Normal file
View file

@ -0,0 +1,24 @@
#ifndef OKSIRC_UI_H
#define OKSIRC_UI_H
#include <QtWidgets>
class ui : public QObject {
public:
ui(int, char **);
int exec();
void sendButtonClicked(bool);
QPlainTextEdit *mainLog;
private:
QApplication *app;
QWidget *mainWindow;
QLineEdit *textEntry;
};
#endif //OKSIRC_UI_H