Some SFTP stuff

This commit is contained in:
Tim Warren 2015-04-06 15:42:05 -04:00
parent 0682db31a2
commit aaff81f6bb
9 changed files with 104 additions and 71 deletions

View File

@ -1,6 +1,6 @@
CXX = $(shell wx-config --cxx) -Wno-c++11-compat-deprecated-writable-strings CXX = $(shell wx-config --cxx) -Wno-c++11-compat-deprecated-writable-strings
TARGET = build/Tyro TARGET = build/Tyro
LDLIBS = $(shell wx-config --libs all) LDLIBS = $(shell wx-config --libs all) -lssh2
WX_CXXFLAGS = -I./src -I./include -static $(shell wx-config --cxxflags) WX_CXXFLAGS = -I./src -I./include -static $(shell wx-config --cxxflags)
DEV_CXXFLAGS = -g -Wall -Wextra $(WX_CXXFLAGS) DEV_CXXFLAGS = -g -Wall -Wextra $(WX_CXXFLAGS)
CXXFLAGS = -Os -s $(WX_CXXFLAGS) CXXFLAGS = -Os -s $(WX_CXXFLAGS)

View File

@ -1,47 +0,0 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<CodeBlocks_project_file>
<FileVersion major="1" minor="6" />
<Project>
<Option title="Tyro" />
<Option pch_mode="2" />
<Option compiler="clang" />
<Build>
<Target title="Debug">
<Option output="bin/Debug/Tyro" prefix_auto="1" extension_auto="1" />
<Option object_output="obj/Debug/" />
<Option type="0" />
<Option compiler="gcc" />
<Compiler>
<Add option="-Wextra" />
<Add option="-g" />
</Compiler>
</Target>
<Target title="Release">
<Option output="bin/Release/Tyro" prefix_auto="1" extension_auto="1" />
<Option object_output="obj/Release/" />
<Option type="0" />
<Option compiler="gccs" />
<Option projectLinkerOptionsRelation="2" />
<Compiler>
<Add option="-Os" />
</Compiler>
</Target>
</Build>
<Compiler>
<Add option="`wx-config --cflags`" />
</Compiler>
<Linker>
<Add option="`wx-config --libs all`" />
</Linker>
<Unit filename="src/DocFrame.cpp" />
<Unit filename="src/DocFrame.h" />
<Unit filename="src/Main.cpp" />
<Unit filename="src/Main.h" />
<Unit filename="src/TyroApp.cpp" />
<Unit filename="src/TyroApp.h" />
<Extensions>
<code_completion />
<debugger />
</Extensions>
</Project>
</CodeBlocks_project_file>

View File

@ -25,3 +25,18 @@ EditPane::EditPane(
} }
EditPane::~EditPane() {} EditPane::~EditPane() {}
void EditPane::OnMenuFileOpen(wxCommandEvent &WXUNUSED(event))
{
wxFileDialog *OpenDialog = new wxFileDialog(this, _T("Choose a file"), _(""), _(""), _("*.*"), wxFD_OPEN);
if (OpenDialog->ShowModal() == wxID_OK)
{
// Load the file into a new notebook tab and styled text control
}
OpenDialog->Close();
}
void EditPane::OnMenuFileSave(wxCommandEvent &WXUNUSED(event))
{
}

View File

@ -19,6 +19,8 @@ public:
wxVSCROLL wxVSCROLL
); );
~EditPane(); ~EditPane();
void OnMenuFileOpen(wxCommandEvent &event);
void OnMenuFileSave(wxCommandEvent &event);
private: private:
DECLARE_EVENT_TABLE() DECLARE_EVENT_TABLE()
}; };

View File

@ -12,8 +12,8 @@
BEGIN_EVENT_TABLE(MainFrame, wxFrame) BEGIN_EVENT_TABLE(MainFrame, wxFrame)
EVT_CLOSE(MainFrame::OnClose) EVT_CLOSE(MainFrame::OnClose)
EVT_MENU(wxID_NEW, MainFrame::OnMenuFileNew) EVT_MENU(wxID_NEW, MainFrame::OnMenuFileNew)
EVT_MENU(wxID_OPEN, MainFrame::OnMenuFileOpen) EVT_MENU(wxID_OPEN, EditPane::OnMenuFileOpen)
EVT_MENU(wxID_SAVE, MainFrame::OnMenuFileSave) EVT_MENU(wxID_SAVE, EditPane::OnMenuFileSave)
EVT_MENU(wxID_EXIT, MainFrame::OnQuit) EVT_MENU(wxID_EXIT, MainFrame::OnQuit)
EVT_MENU(wxID_ABOUT, MainFrame::OnAbout) EVT_MENU(wxID_ABOUT, MainFrame::OnAbout)
END_EVENT_TABLE() END_EVENT_TABLE()
@ -108,9 +108,9 @@ void MainFrame::SetupMenu()
helpMenu->Append(wxID_ABOUT, _T("&About...\tF1"), _T("Show info about this application")); helpMenu->Append(wxID_ABOUT, _T("&About...\tF1"), _T("Show info about this application"));
// Add the menus to the menubar // Add the menus to the menubar
mbar->Append(fileMenu, _("&File")); mbar->Append(fileMenu, _T("&File"));
mbar->Append(editMenu, _("&Edit")); mbar->Append(editMenu, _T("&Edit"));
mbar->Append(helpMenu, _("&Help")); mbar->Append(helpMenu, _T("&Help"));
#ifdef __WXMAC__ #ifdef __WXMAC__
wxMenuBar::MacSetCommonMenuBar(mbar); wxMenuBar::MacSetCommonMenuBar(mbar);
@ -135,21 +135,6 @@ void MainFrame::OnMenuFileNew(wxCommandEvent &WXUNUSED(event))
notebook->AddTab(); notebook->AddTab();
} }
void MainFrame::OnMenuFileOpen(wxCommandEvent &WXUNUSED(event))
{
wxFileDialog *OpenDialog = new wxFileDialog(this, _T("Choose a file"), _(""), _(""), _("*.*"), wxFD_OPEN);
if (OpenDialog->ShowModal() == wxID_OK)
{
// Load the file into a new notebook tab and styled text control
}
OpenDialog->Close();
}
void MainFrame::OnMenuFileSave(wxCommandEvent &WXUNUSED(event))
{
}
void MainFrame::OnQuit(wxCommandEvent &WXUNUSED(event)) void MainFrame::OnQuit(wxCommandEvent &WXUNUSED(event))
{ {
Destroy(); Destroy();

View File

@ -25,8 +25,6 @@ class MainFrame: public wxFrame
void SetupToolbar(); void SetupToolbar();
void SetupStatusBar(); void SetupStatusBar();
void OnMenuFileNew(wxCommandEvent &event); void OnMenuFileNew(wxCommandEvent &event);
void OnMenuFileOpen(wxCommandEvent &event);
void OnMenuFileSave(wxCommandEvent &event);
void OnClose(wxCloseEvent &event); void OnClose(wxCloseEvent &event);
void OnQuit(wxCommandEvent &event); void OnQuit(wxCommandEvent &event);
void OnAbout(wxCommandEvent &event); void OnAbout(wxCommandEvent &event);

45
src/SFTP.cpp Normal file
View File

@ -0,0 +1,45 @@
#include "SFTP.h"
SFTP::SFTP(const char *host, string user, string pass) {
struct addrinfo host_info;
struct addrinfo *host_info_list;
int sock;
int status;
int rc;
// Clear out memory in addr structure
memset(&host_info, 0, sizeof host_info);
host_info.ai_family = AF_UNSPEC;
host_info.ai_socktype = SOCK_STREAM;
status = getaddrinfo(host, "22", &host_info, &host_info_list);
if (status != 0)
{
cout << "getaddrinfo error" << gai_strerror(status) << endl;
}
// Start libssh2
rc = libssh2_init(0);
if (rc != 0)
{
cout << "Libssh2 initialization failed " << "(" << rc << ")" << endl;
return;
}
sock = socket(AF_INET, SOCK_STREAM, 0);
session = libssh2_session_init();
/* Since we have set non-blocking, tell libssh2 we are blocking */
libssh2_session_set_blocking(session, 1);
// Actually do the ssh handshake
rc = libssh2_session_handshake(session, sock);
};
SFTP::~SFTP() {
};

34
src/SFTP.h Normal file
View File

@ -0,0 +1,34 @@
/*
* File: SFTP.h
* Author: twarren
*
* Created on April 6, 2015, 2:22 PM
*/
#ifndef SFTP_H
#define SFTP_H
#define LIBSSH_STATIC 1
#include "common.h"
// libssh2 includes
#include <libssh2.h>
#include <libssh2_sftp.h>
// Socket includes
#include <cstring>
#include <sys/socket.h>
#include <netdb.h>
class SFTP {
public:
SFTP(const char *host, string user, string pass);
~SFTP();
private:
LIBSSH2_SESSION *session;
LIBSSH2_SFTP *sftp_session;
unsigned long hostaddr;
};
#endif /* SFTP_H */

View File

@ -13,6 +13,7 @@
using namespace std; using namespace std;
#include <iostream>
#include <string> #include <string>
#endif // TYRO_COMMON_H #endif // TYRO_COMMON_H