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
|
@ -7,11 +7,11 @@ list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake/modules/")
|
||||||
|
|
||||||
find_package(NSPR REQUIRED)
|
find_package(NSPR REQUIRED)
|
||||||
find_package(NSS REQUIRED)
|
find_package(NSS REQUIRED)
|
||||||
find_package(FOX REQUIRED)
|
find_package(Qt5Widgets REQUIRED)
|
||||||
|
|
||||||
include_directories(${NSPR_INCLUDE_DIRS} ${NSS_INCLUDE_DIRS} ${FOX_INCLUDE_DIR})
|
include_directories(${NSPR_INCLUDE_DIRS} ${NSS_INCLUDE_DIRS})
|
||||||
|
|
||||||
set(SOURCE_FILES main.cpp)
|
set(SOURCE_FILES main.cpp dns.cpp)
|
||||||
add_executable(oksirc ${SOURCE_FILES})
|
add_executable(oksirc ${SOURCE_FILES})
|
||||||
|
|
||||||
target_link_libraries(oksirc ${NSPR_LIBRARIES} ${NSS_LIBRARIES} ${FOX_LIBRARY})
|
target_link_libraries(oksirc ${NSPR_LIBRARIES} ${NSS_LIBRARIES} Qt5::Widgets)
|
|
@ -1,62 +0,0 @@
|
||||||
# Locate gdal
|
|
||||||
# This module defines
|
|
||||||
# FOX_LIBRARY
|
|
||||||
# FOX_FOUND, if false, do not try to link to gdal
|
|
||||||
# FOX_INCLUDE_DIR, where to find the headers
|
|
||||||
#
|
|
||||||
# $FOX_DIR is an environment variable that would
|
|
||||||
# correspond to the ./configure --prefix=$FOX_DIR
|
|
||||||
#
|
|
||||||
# Created by Robert Osfield.
|
|
||||||
|
|
||||||
FIND_PATH(FOX_INCLUDE_DIR fx.h
|
|
||||||
$ENV{FOX_DIR}/include/fox-1.6
|
|
||||||
$ENV{FOX_DIR}/fox-1.6
|
|
||||||
~/Library/Frameworks/fox-1.6
|
|
||||||
/Library/Frameworks/fox-1.6
|
|
||||||
/usr/local/include/fox-1.6
|
|
||||||
/usr/include/fox-1.6
|
|
||||||
/sw/include/fox-1.6 # Fink
|
|
||||||
/opt/local/include/fox-1.6 # DarwinPorts
|
|
||||||
/opt/csw/include/fox-1.6 # Blastwave
|
|
||||||
/opt/include/fox-1.6
|
|
||||||
/usr/freeware/include/fox-1.6
|
|
||||||
$ENV{FOX_DIR}/include
|
|
||||||
$ENV{FOX_DIR}
|
|
||||||
~/Library/Frameworks
|
|
||||||
/Library/Frameworks
|
|
||||||
/usr/local/include
|
|
||||||
/usr/include
|
|
||||||
/sw/include # Fink
|
|
||||||
/opt/local/include # DarwinPorts
|
|
||||||
/opt/csw/include # Blastwave
|
|
||||||
/opt/include
|
|
||||||
/usr/freeware/include
|
|
||||||
)
|
|
||||||
|
|
||||||
MACRO(FIND_FOX_LIBRARY MYLIBRARY MYLIBRARYNAME)
|
|
||||||
|
|
||||||
FIND_LIBRARY(${MYLIBRARY}
|
|
||||||
NAMES ${MYLIBRARYNAME}
|
|
||||||
PATHS
|
|
||||||
$ENV{FOX_DIR}/lib
|
|
||||||
$ENV{FOX_DIR}
|
|
||||||
~/Library/Frameworks
|
|
||||||
/Library/Frameworks
|
|
||||||
/usr/local/lib
|
|
||||||
/usr/lib
|
|
||||||
/sw/lib
|
|
||||||
/opt/local/lib
|
|
||||||
/opt/csw/lib
|
|
||||||
/opt/lib
|
|
||||||
/usr/freeware/lib64
|
|
||||||
)
|
|
||||||
|
|
||||||
ENDMACRO(FIND_FOX_LIBRARY LIBRARY LIBRARYNAME)
|
|
||||||
|
|
||||||
FIND_FOX_LIBRARY(FOX_LIBRARY FOX-1.6)
|
|
||||||
|
|
||||||
SET(FOX_FOUND "NO")
|
|
||||||
IF(FOX_LIBRARY AND FOX_INCLUDE_DIR)
|
|
||||||
SET(FOX_FOUND "YES")
|
|
||||||
ENDIF(FOX_LIBRARY AND FOX_INCLUDE_DIR)
|
|
23
dns.cpp
Normal file
23
dns.cpp
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
#include "dns.h"
|
||||||
|
|
||||||
|
PRErrorCode LookupName(char *hostname, PRNetAddr *result) {
|
||||||
|
// Attempt to resolve a name.
|
||||||
|
PRAddrInfo *addrInfos = PR_GetAddrInfoByName(hostname, PR_AF_UNSPEC, PR_AI_ADDRCONFIG);
|
||||||
|
void *iter = nullptr;
|
||||||
|
// PRNetAddr firstAddr;
|
||||||
|
// PRNetAddr tempAddr;
|
||||||
|
// do {
|
||||||
|
iter = PR_EnumerateAddrInfo(iter, addrInfos, 0, result);
|
||||||
|
char ipString[80];
|
||||||
|
PRStatus status = PR_NetAddrToString(result, 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));
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
printf("Found IP Address: %s\n", ipString);
|
||||||
|
return 0;
|
||||||
|
// break;
|
||||||
|
// } while(iter);
|
||||||
|
}
|
9
dns.h
Normal file
9
dns.h
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
#ifndef OKSIRC_DNS_H
|
||||||
|
#define OKSIRC_DNS_H
|
||||||
|
#include <prio.h>
|
||||||
|
#include <prnetdb.h>
|
||||||
|
#include <nspr.h>
|
||||||
|
|
||||||
|
PRErrorCode LookupName(char *, PRNetAddr *);
|
||||||
|
|
||||||
|
#endif //OKSIRC_DNS_H
|
71
main.cpp
71
main.cpp
|
@ -1,5 +1,5 @@
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <fox-1.6/fx.h>
|
#include "dns.h"
|
||||||
|
|
||||||
// NSPR include files
|
// NSPR include files
|
||||||
#include <prerror.h>
|
#include <prerror.h>
|
||||||
|
@ -15,18 +15,25 @@
|
||||||
#include <sslproto.h>
|
#include <sslproto.h>
|
||||||
#include <prio.h>
|
#include <prio.h>
|
||||||
|
|
||||||
|
// Qt Include Files, should come after NSPR / NSS
|
||||||
|
#include <QtWidgets>
|
||||||
|
#include <QPlainTextEdit>
|
||||||
|
|
||||||
|
NSSInitContext *nssContext;
|
||||||
|
SECMODModule *builtInRootsMod;
|
||||||
|
|
||||||
// PK11 Password Function typedef
|
// PK11 Password Function typedef
|
||||||
typedef char *(*PK11PasswordFunc)(
|
typedef char *(*PK11PasswordFunc)(
|
||||||
PK11SlotInfo *slot,
|
PK11SlotInfo *slot,
|
||||||
PRBool retry,
|
PRBool retry,
|
||||||
void *arg);
|
void *arg);
|
||||||
|
|
||||||
int main(int argc, char* argv[]) {
|
void init() {
|
||||||
// NSPR Init
|
// NSPR Init
|
||||||
PR_Init(PR_USER_THREAD, PR_PRIORITY_NORMAL, 0);
|
PR_Init(PR_USER_THREAD, PR_PRIORITY_NORMAL, 0);
|
||||||
|
|
||||||
// NSS Init
|
// NSS Init
|
||||||
NSSInitContext *const 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) {
|
||||||
|
@ -70,53 +77,63 @@ int main(int argc, char* argv[]) {
|
||||||
|
|
||||||
// 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\"";
|
||||||
SECMODModule *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));
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(int argc, char* argv[]) {
|
||||||
|
init();
|
||||||
|
|
||||||
|
PRNetAddr theAddr;
|
||||||
|
LookupName((char *)"buyvm.theoks.net", &theAddr);
|
||||||
|
|
||||||
// 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];
|
char ipString[80];
|
||||||
PRStatus status = PR_NetAddrToString(&tempAddr, 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));
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
printf("Found IP Address: %s\n", ipString);
|
|
||||||
firstAddr = tempAddr;
|
|
||||||
} while(iter);
|
|
||||||
|
|
||||||
PRFileDesc *tcpSocket = PR_NewTCPSocket();
|
PRFileDesc *tcpSocket = PR_NewTCPSocket();
|
||||||
firstAddr.inet.port = 443;
|
theAddr.inet.port = 443;
|
||||||
PRFileDesc *nssSocket;
|
PRFileDesc *nssSocket;
|
||||||
SSL_ImportFD(NULL, tcpSocket);
|
SSL_ImportFD(NULL, tcpSocket);
|
||||||
|
|
||||||
char *sendBuf = (char *)PR_MALLOC( 65536 * sizeof(char));
|
QApplication app(argc, argv);
|
||||||
char *toSend = (char *) "GET / HTTP/1.0\r\nHost: buyvm.theoks.net\r\nUser-Agent: oksirc_net_test\r\n\r\n";
|
QWidget mainWindow;
|
||||||
PR_Send(tcpSocket, sendBuf, null, 0, PR_INTERVAL_NO_TIMEOUT);
|
mainWindow.resize(1280, 720);
|
||||||
|
mainWindow.setWindowTitle("oksirc - early Qt test");
|
||||||
|
|
||||||
FXApp app("Hello", "FoxTest");
|
QPlainTextEdit *mainLog = new QPlainTextEdit();
|
||||||
app.init(argc, argv);
|
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);
|
QHBoxLayout *entryLineLayout = new QHBoxLayout();
|
||||||
new FXButton(mainWindow, "&Hello World!", NULL, &app, FXApp::ID_QUIT);
|
entryLineLayout->addWidget(textEntry);
|
||||||
app.create();
|
entryLineLayout->addWidget(sendButton);
|
||||||
mainWindow->show(PLACEMENT_SCREEN);
|
|
||||||
int foxRetCode = app.run();
|
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);
|
SECMOD_DestroyModule(builtInRootsMod);
|
||||||
NSS_ShutdownContext(nssContext);
|
NSS_ShutdownContext(nssContext);
|
||||||
|
|
||||||
return app.run();
|
return app.exec();
|
||||||
}
|
}
|
Loading…
Add table
Add a link
Reference in a new issue