Got a barebones Qt UI up, and got stuff writing in the message log.
This commit is contained in:
parent
88f29def56
commit
4d6ff1e9f8
5 changed files with 88 additions and 101 deletions
87
main.cpp
87
main.cpp
|
@ -1,5 +1,5 @@
|
|||
#include <iostream>
|
||||
#include <fox-1.6/fx.h>
|
||||
#include "dns.h"
|
||||
|
||||
// NSPR include files
|
||||
#include <prerror.h>
|
||||
|
@ -15,18 +15,25 @@
|
|||
#include <sslproto.h>
|
||||
#include <prio.h>
|
||||
|
||||
// Qt Include Files, should come after NSPR / NSS
|
||||
#include <QtWidgets>
|
||||
#include <QPlainTextEdit>
|
||||
|
||||
NSSInitContext *nssContext;
|
||||
SECMODModule *builtInRootsMod;
|
||||
|
||||
// PK11 Password Function typedef
|
||||
typedef char *(*PK11PasswordFunc)(
|
||||
PK11SlotInfo *slot,
|
||||
PRBool retry,
|
||||
void *arg);
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
void init() {
|
||||
// NSPR Init
|
||||
PR_Init(PR_USER_THREAD, PR_PRIORITY_NORMAL, 0);
|
||||
|
||||
// NSS Init
|
||||
NSSInitContext *const nssContext =
|
||||
nssContext =
|
||||
NSS_InitContext("sql:/etc/pki/nssdb", "", "", "", NULL, NSS_INIT_READONLY | NSS_INIT_PK11RELOAD);
|
||||
|
||||
if(nssContext == NULL) {
|
||||
|
@ -70,53 +77,63 @@ int main(int argc, char* argv[]) {
|
|||
|
||||
// Initialize trusted certificate store
|
||||
char module_name[] = "library=libnssckbi.so name=\"Root Certs\"";
|
||||
SECMODModule *builtInRootsMod = SECMOD_LoadUserModule(module_name, NULL, PR_FALSE);
|
||||
builtInRootsMod = SECMOD_LoadUserModule(module_name, NULL, PR_FALSE);
|
||||
if(builtInRootsMod == NULL || !builtInRootsMod->loaded) {
|
||||
const PRErrorCode err = PR_GetError();
|
||||
fprintf(stderr, "Error: Loading built in roots module failed, code %d: %s\n",
|
||||
err, PR_ErrorToName(err));
|
||||
err, PR_ErrorToName(err));
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
init();
|
||||
|
||||
PRNetAddr theAddr;
|
||||
LookupName((char *)"buyvm.theoks.net", &theAddr);
|
||||
|
||||
char ipString[80];
|
||||
PRStatus status = PR_NetAddrToString(&theAddr, ipString, 75);
|
||||
if(status == PR_FAILURE) {
|
||||
const PRErrorCode err = PR_GetError();
|
||||
fprintf(stderr, "Error: Converting PRNetAddr to string %d: %s\n",
|
||||
err, PR_ErrorToName(err));
|
||||
exit(1);
|
||||
}
|
||||
|
||||
// Attempt to resolve a name.
|
||||
PRAddrInfo *addrInfos = PR_GetAddrInfoByName("buyvm.theoks.net", PR_AF_UNSPEC, PR_AI_ADDRCONFIG);
|
||||
void *iter = nullptr;
|
||||
PRNetAddr firstAddr;
|
||||
PRNetAddr tempAddr;
|
||||
do {
|
||||
iter = PR_EnumerateAddrInfo(iter, addrInfos, 0, &tempAddr);
|
||||
char ipString[80];
|
||||
PRStatus status = PR_NetAddrToString(&tempAddr, ipString, 75);
|
||||
if(status == PR_FAILURE) {
|
||||
const PRErrorCode err = PR_GetError();
|
||||
fprintf(stderr, "Error: Converting PRNetAddr to string %d: %s\n",
|
||||
err, PR_ErrorToName(err));
|
||||
exit(1);
|
||||
}
|
||||
printf("Found IP Address: %s\n", ipString);
|
||||
firstAddr = tempAddr;
|
||||
} while(iter);
|
||||
|
||||
PRFileDesc *tcpSocket = PR_NewTCPSocket();
|
||||
firstAddr.inet.port = 443;
|
||||
theAddr.inet.port = 443;
|
||||
PRFileDesc *nssSocket;
|
||||
SSL_ImportFD(NULL, tcpSocket);
|
||||
|
||||
char *sendBuf = (char *)PR_MALLOC( 65536 * sizeof(char));
|
||||
char *toSend = (char *) "GET / HTTP/1.0\r\nHost: buyvm.theoks.net\r\nUser-Agent: oksirc_net_test\r\n\r\n";
|
||||
PR_Send(tcpSocket, sendBuf, null, 0, PR_INTERVAL_NO_TIMEOUT);
|
||||
QApplication app(argc, argv);
|
||||
QWidget mainWindow;
|
||||
mainWindow.resize(1280, 720);
|
||||
mainWindow.setWindowTitle("oksirc - early Qt test");
|
||||
|
||||
FXApp app("Hello", "FoxTest");
|
||||
app.init(argc, argv);
|
||||
QPlainTextEdit *mainLog = new QPlainTextEdit();
|
||||
mainLog->setReadOnly(true);
|
||||
QLineEdit *textEntry = new QLineEdit();
|
||||
QPushButton *sendButton = new QPushButton(QApplication::translate("send", "Send"));
|
||||
|
||||
FXMainWindow *mainWindow = new FXMainWindow(&app, "Hello", NULL, NULL, DECOR_ALL);
|
||||
new FXButton(mainWindow, "&Hello World!", NULL, &app, FXApp::ID_QUIT);
|
||||
app.create();
|
||||
mainWindow->show(PLACEMENT_SCREEN);
|
||||
int foxRetCode = app.run();
|
||||
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();
|
||||
|
||||
char messageBuf[1024];
|
||||
sprintf(messageBuf, "Found IP Address: %s", ipString);
|
||||
mainLog->appendPlainText(messageBuf);
|
||||
|
||||
SECMOD_DestroyModule(builtInRootsMod);
|
||||
NSS_ShutdownContext(nssContext);
|
||||
|
||||
return app.run();
|
||||
return app.exec();
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue