CodyCam: Style Fixes, Make Resource File Verbose
No functional change intended, added some copyrights in the process. Change-Id: Ic6ebe276bb939c425d65aff1b3b07c7c2e27a33a Reviewed-on: https://review.haiku-os.org/c/1698 Reviewed-by: waddlesplash <[email protected]>
This commit is contained in:
committed by
waddlesplash
parent
f5953f6155
commit
6a739773fc
@@ -1,3 +1,10 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 1998-1999 Be, Inc. All Rights Reserved.
|
||||||
|
* Copyright 2003-2019 Haiku, Inc. All rights reserved.
|
||||||
|
* Distributed under the terms of the MIT License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
#include "CodyCam.h"
|
#include "CodyCam.h"
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
@@ -23,6 +30,7 @@
|
|||||||
#include <TextControl.h>
|
#include <TextControl.h>
|
||||||
#include <TimeSource.h>
|
#include <TimeSource.h>
|
||||||
#include <TranslationUtils.h>
|
#include <TranslationUtils.h>
|
||||||
|
#include <TranslatorFormats.h>
|
||||||
|
|
||||||
#undef B_TRANSLATION_CONTEXT
|
#undef B_TRANSLATION_CONTEXT
|
||||||
#define B_TRANSLATION_CONTEXT "CodyCam"
|
#define B_TRANSLATION_CONTEXT "CodyCam"
|
||||||
@@ -147,7 +155,7 @@ CodyCam::QuitRequested()
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
CodyCam::MessageReceived(BMessage *message)
|
CodyCam::MessageReceived(BMessage* message)
|
||||||
{
|
{
|
||||||
switch (message->what) {
|
switch (message->what) {
|
||||||
case msg_start:
|
case msg_start:
|
||||||
@@ -233,7 +241,7 @@ CodyCam::_SetUpNodes()
|
|||||||
fVideoConsumer = new VideoConsumer("CodyCam",
|
fVideoConsumer = new VideoConsumer("CodyCam",
|
||||||
((VideoWindow*)fWindow)->VideoView(),
|
((VideoWindow*)fWindow)->VideoView(),
|
||||||
((VideoWindow*)fWindow)->StatusLine(), NULL, 0);
|
((VideoWindow*)fWindow)->StatusLine(), NULL, 0);
|
||||||
if (!fVideoConsumer) {
|
if (fVideoConsumer == NULL) {
|
||||||
fWindow->ErrorAlert(B_TRANSLATE("Cannot create a video window"),
|
fWindow->ErrorAlert(B_TRANSLATE("Cannot create a video window"),
|
||||||
B_ERROR);
|
B_ERROR);
|
||||||
return B_ERROR;
|
return B_ERROR;
|
||||||
@@ -254,8 +262,8 @@ CodyCam::_SetUpNodes()
|
|||||||
&cnt, B_MEDIA_RAW_VIDEO);
|
&cnt, B_MEDIA_RAW_VIDEO);
|
||||||
if (status != B_OK || cnt < 1) {
|
if (status != B_OK || cnt < 1) {
|
||||||
status = B_RESOURCE_UNAVAILABLE;
|
status = B_RESOURCE_UNAVAILABLE;
|
||||||
fWindow->ErrorAlert(B_TRANSLATE("Cannot find an available video stream"),
|
fWindow->ErrorAlert(
|
||||||
status);
|
B_TRANSLATE("Cannot find an available video stream"), status);
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -369,7 +377,7 @@ void
|
|||||||
CodyCam::_TearDownNodes()
|
CodyCam::_TearDownNodes()
|
||||||
{
|
{
|
||||||
CALL("CodyCam::_TearDownNodes\n");
|
CALL("CodyCam::_TearDownNodes\n");
|
||||||
if (!fMediaRoster)
|
if (fMediaRoster == NULL)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (fVideoConsumer) {
|
if (fVideoConsumer) {
|
||||||
@@ -497,7 +505,7 @@ void
|
|||||||
VideoWindow::MessageReceived(BMessage* message)
|
VideoWindow::MessageReceived(BMessage* message)
|
||||||
{
|
{
|
||||||
BControl* control = NULL;
|
BControl* control = NULL;
|
||||||
message->FindPointer((const char*)"source", (void **)&control);
|
message->FindPointer((const char*)"source", (void**)&control);
|
||||||
|
|
||||||
switch (message->what) {
|
switch (message->what) {
|
||||||
case msg_filename:
|
case msg_filename:
|
||||||
@@ -515,7 +523,7 @@ VideoWindow::MessageReceived(BMessage* message)
|
|||||||
FTPINFO("never\n");
|
FTPINFO("never\n");
|
||||||
fFtpInfo.rate = (bigtime_t)(B_INFINITE_TIMEOUT);
|
fFtpInfo.rate = (bigtime_t)(B_INFINITE_TIMEOUT);
|
||||||
} else {
|
} else {
|
||||||
FTPINFO("%ld seconds\n", (long)seconds);
|
FTPINFO("%" B_PRId32 " seconds\n", seconds);
|
||||||
fFtpInfo.rate = (bigtime_t)(seconds * 1000000LL);
|
fFtpInfo.rate = (bigtime_t)(seconds * 1000000LL);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@@ -609,7 +617,7 @@ VideoWindow::_BuildCaptureControls()
|
|||||||
fErrorView->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
|
fErrorView->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
|
||||||
|
|
||||||
// Capture controls
|
// Capture controls
|
||||||
BGridLayout *controlsLayout = new BGridLayout(B_USE_DEFAULT_SPACING,
|
BGridLayout* controlsLayout = new BGridLayout(B_USE_DEFAULT_SPACING,
|
||||||
B_USE_SMALL_SPACING);
|
B_USE_SMALL_SPACING);
|
||||||
controlsLayout->SetInsets(B_USE_SMALL_SPACING);
|
controlsLayout->SetInsets(B_USE_SMALL_SPACING);
|
||||||
|
|
||||||
@@ -627,7 +635,8 @@ VideoWindow::_BuildCaptureControls()
|
|||||||
|
|
||||||
// format menu
|
// format menu
|
||||||
fImageFormatMenu = new BPopUpMenu(B_TRANSLATE("Image Format Menu"));
|
fImageFormatMenu = new BPopUpMenu(B_TRANSLATE("Image Format Menu"));
|
||||||
BTranslationUtils::AddTranslationItems(fImageFormatMenu, B_TRANSLATOR_BITMAP);
|
BTranslationUtils::AddTranslationItems(fImageFormatMenu,
|
||||||
|
B_TRANSLATOR_BITMAP);
|
||||||
fImageFormatMenu->SetTargetForItems(this);
|
fImageFormatMenu->SetTargetForItems(this);
|
||||||
|
|
||||||
if (fImageFormatSettings->Value()
|
if (fImageFormatSettings->Value()
|
||||||
@@ -679,7 +688,7 @@ VideoWindow::_BuildCaptureControls()
|
|||||||
|
|
||||||
fUploadClientMenu = new BPopUpMenu(B_TRANSLATE("Send to" B_UTF8_ELLIPSIS));
|
fUploadClientMenu = new BPopUpMenu(B_TRANSLATE("Send to" B_UTF8_ELLIPSIS));
|
||||||
for (int i = 0; i < kUploadClientsCount; i++) {
|
for (int i = 0; i < kUploadClientsCount; i++) {
|
||||||
BMessage *m = new BMessage(msg_upl_client);
|
BMessage* m = new BMessage(msg_upl_client);
|
||||||
m->AddInt32("client", i);
|
m->AddInt32("client", i);
|
||||||
fUploadClientMenu->AddItem(new BMenuItem(kUploadClients[i], m));
|
fUploadClientMenu->AddItem(new BMenuItem(kUploadClients[i], m));
|
||||||
}
|
}
|
||||||
@@ -843,7 +852,8 @@ VideoWindow::_QuitSettings()
|
|||||||
fFilenameSetting->ValueChanged(fFileName->Text());
|
fFilenameSetting->ValueChanged(fFileName->Text());
|
||||||
fImageFormatSettings->ValueChanged(fImageFormatMenu->FindMarked()->Label());
|
fImageFormatSettings->ValueChanged(fImageFormatMenu->FindMarked()->Label());
|
||||||
fCaptureRateSetting->ValueChanged(fCaptureRateMenu->FindMarked()->Label());
|
fCaptureRateSetting->ValueChanged(fCaptureRateMenu->FindMarked()->Label());
|
||||||
fUploadClientSetting->ValueChanged(fUploadClientMenu->FindMarked()->Label());
|
fUploadClientSetting->ValueChanged(
|
||||||
|
fUploadClientMenu->FindMarked()->Label());
|
||||||
|
|
||||||
fSettings->SaveSettings();
|
fSettings->SaveSettings();
|
||||||
delete fSettings;
|
delete fSettings;
|
||||||
@@ -933,9 +943,9 @@ ControlWindow::QuitRequested()
|
|||||||
// #pragma mark -
|
// #pragma mark -
|
||||||
|
|
||||||
|
|
||||||
int main() {
|
int main()
|
||||||
|
{
|
||||||
CodyCam app;
|
CodyCam app;
|
||||||
app.Run();
|
app.Run();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,10 +1,12 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 1998-1999 Be, Inc. All Rights Reserved.
|
||||||
|
* Copyright 2003-2019 Haiku, Inc. All rights reserved.
|
||||||
|
* Distributed under the terms of the MIT License.
|
||||||
|
*/
|
||||||
#ifndef CODYCAM_H
|
#ifndef CODYCAM_H
|
||||||
#define CODYCAM_H
|
#define CODYCAM_H
|
||||||
|
|
||||||
|
|
||||||
#include "Settings.h"
|
|
||||||
#include "VideoConsumer.h"
|
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include <Application.h>
|
#include <Application.h>
|
||||||
@@ -18,6 +20,9 @@
|
|||||||
#include <TextControl.h>
|
#include <TextControl.h>
|
||||||
#include <Window.h>
|
#include <Window.h>
|
||||||
|
|
||||||
|
#include "Settings.h"
|
||||||
|
#include "VideoConsumer.h"
|
||||||
|
|
||||||
|
|
||||||
class BMediaRoster;
|
class BMediaRoster;
|
||||||
|
|
||||||
@@ -143,7 +148,7 @@ private:
|
|||||||
port_id* fPortPtr;
|
port_id* fPortPtr;
|
||||||
|
|
||||||
BView* fVideoView;
|
BView* fVideoView;
|
||||||
BTextView* fErrorView;
|
BTextView* fErrorView;
|
||||||
|
|
||||||
BTextControl* fFileName;
|
BTextControl* fFileName;
|
||||||
BBox* fCaptureSetupBox;
|
BBox* fCaptureSetupBox;
|
||||||
@@ -194,4 +199,3 @@ private:
|
|||||||
};
|
};
|
||||||
|
|
||||||
#endif // CODYCAM_H
|
#endif // CODYCAM_H
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
|
|
||||||
resource(1, "BEOS:FILE_TYPES") message;
|
resource file_types message;
|
||||||
|
|
||||||
resource vector_icon {
|
resource vector_icon array {
|
||||||
$"6E6369660B03010000020002023A00000000000000004000004BC00000000000"
|
$"6E6369660B03010000020002023A00000000000000004000004BC00000000000"
|
||||||
$"010000FFFF01000000020006023CC0000000000000003D000048000048800040"
|
$"010000FFFF01000000020006023CC0000000000000003D000048000048800040"
|
||||||
$"010101FFC1ACAC040168020106023A26EC38CA29B828213953DB48968D4B2BC6"
|
$"010101FFC1ACAC040168020106023A26EC38CA29B828213953DB48968D4B2BC6"
|
||||||
@@ -27,31 +27,16 @@ resource app_signature "application/x-vnd.Haiku-CodyCam";
|
|||||||
|
|
||||||
resource app_name_catalog_entry "x-vnd.Haiku-CodyCam:System name:CodyCam";
|
resource app_name_catalog_entry "x-vnd.Haiku-CodyCam:System name:CodyCam";
|
||||||
|
|
||||||
resource(1, "BEOS:APP_VERSION") #'APPV' array
|
resource app_version {
|
||||||
{
|
major = 1,
|
||||||
$"0100000000000000000000000000000001000000312E30643100000000000000"
|
middle = 0,
|
||||||
$"0000000000000000000000000000000000000000000000000000000000000000"
|
minor = 0,
|
||||||
$"000000000000000000000000000000000000000052342E3520C2A9313939312D"
|
|
||||||
$"3139393920426520496E636F72706F7261746564000000000000000000000000"
|
variety = B_APPV_DEVELOPMENT,
|
||||||
$"0000000000000000000000000000000000000000000000000000000000000000"
|
internal = 1,
|
||||||
$"0000000000000000000000000000000000000000000000000000000000000000"
|
|
||||||
$"0000000000000000000000000000000000000000000000000000000000000000"
|
short_info = "1.0d1",
|
||||||
$"0000000000000000000000000000000000000000000000000000000000000000"
|
long_info = "©1991-1999 Be, Inc., ©2003-2019 Haiku, Inc."
|
||||||
$"0000000000000000000000000000000000000000000000000000000000000000"
|
|
||||||
$"0000000000000000000000000000000000000000000000000000000000000000"
|
|
||||||
$"0000000000000000000000000000000000000000000000000000000000000000"
|
|
||||||
$"0000000000000000000000000000000000000000000000000000000000000000"
|
|
||||||
$"0000000000000000000000000000000000000000000000000000000000000000"
|
|
||||||
$"0000000000000000000000000000000000000000000000000000000000000000"
|
|
||||||
$"0000000000000000000000000000000000000000000000000000000000000000"
|
|
||||||
$"0000000000000000000000000000000000000000000000000000000000000000"
|
|
||||||
$"0000000000000000000000000000000000000000000000000000000000000000"
|
|
||||||
$"0000000000000000000000000000000000000000000000000000000000000000"
|
|
||||||
$"0000000000000000000000000000000000000000000000000000000000000000"
|
|
||||||
$"0000000000000000000000000000000000000000000000000000000000000000"
|
|
||||||
$"0000000000000000000000000000000000000000000000000000000000000000"
|
|
||||||
$"0000000000000000"
|
|
||||||
};
|
};
|
||||||
|
|
||||||
resource(1, "BEOS:APP_FLAGS") #'APPF' $"00000000";
|
resource app_flags B_SINGLE_LAUNCH;
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,13 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 1998-1999 Be, Inc. All Rights Reserved.
|
||||||
|
* Copyright 2003-2019 Haiku, Inc. All rights reserved.
|
||||||
|
* Distributed under the terms of the MIT License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
#include "FileUploadClient.h"
|
#include "FileUploadClient.h"
|
||||||
|
|
||||||
|
|
||||||
FileUploadClient::FileUploadClient()
|
FileUploadClient::FileUploadClient()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
@@ -13,48 +21,45 @@ FileUploadClient::~FileUploadClient()
|
|||||||
bool
|
bool
|
||||||
FileUploadClient::ChangeDir(const string& dir)
|
FileUploadClient::ChangeDir(const string& dir)
|
||||||
{
|
{
|
||||||
bool rc = false;
|
return false;
|
||||||
return rc;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool
|
bool
|
||||||
FileUploadClient::ListDirContents(string& listing)
|
FileUploadClient::ListDirContents(string& listing)
|
||||||
{
|
{
|
||||||
bool rc = false;
|
return false;
|
||||||
return rc;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool
|
bool
|
||||||
FileUploadClient::PrintWorkingDir(string& dir)
|
FileUploadClient::PrintWorkingDir(string& dir)
|
||||||
{
|
{
|
||||||
bool rc = false;
|
return false;
|
||||||
return rc;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool
|
bool
|
||||||
FileUploadClient::Connect(const string& server, const string& login, const string& passwd)
|
FileUploadClient::Connect(const string& server, const string& login,
|
||||||
|
const string& passwd)
|
||||||
{
|
{
|
||||||
bool rc = false;
|
return false;
|
||||||
return rc;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool
|
bool
|
||||||
FileUploadClient::PutFile(const string& local, const string& remote, ftp_mode mode)
|
FileUploadClient::PutFile(const string& local, const string& remote,
|
||||||
|
ftp_mode mode)
|
||||||
{
|
{
|
||||||
bool rc = false;
|
return false;
|
||||||
return rc;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool
|
bool
|
||||||
FileUploadClient::GetFile(const string& remote, const string& local, ftp_mode mode)
|
FileUploadClient::GetFile(const string& remote, const string& local,
|
||||||
|
ftp_mode mode)
|
||||||
{
|
{
|
||||||
bool rc = false;
|
return false;
|
||||||
return rc;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -63,16 +68,14 @@ FileUploadClient::GetFile(const string& remote, const string& local, ftp_mode mo
|
|||||||
bool
|
bool
|
||||||
FileUploadClient::MoveFile(const string& oldPath, const string& newPath)
|
FileUploadClient::MoveFile(const string& oldPath, const string& newPath)
|
||||||
{
|
{
|
||||||
bool rc = false;
|
return false;
|
||||||
return rc;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool
|
bool
|
||||||
FileUploadClient::Chmod(const string& path, const string& mod)
|
FileUploadClient::Chmod(const string& path, const string& mod)
|
||||||
{
|
{
|
||||||
bool rc = false;
|
return false;
|
||||||
return rc;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -80,5 +83,3 @@ void
|
|||||||
FileUploadClient::SetPassive(bool on)
|
FileUploadClient::SetPassive(bool on)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,8 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 1998-1999 Be, Inc. All Rights Reserved.
|
||||||
|
* Copyright 2003-2019 Haiku, Inc. All rights reserved.
|
||||||
|
* Distributed under the terms of the MIT License.
|
||||||
|
*/
|
||||||
#ifndef FILE_UPLOAD_CLIENT_H
|
#ifndef FILE_UPLOAD_CLIENT_H
|
||||||
#define FILE_UPLOAD_CLIENT_H
|
#define FILE_UPLOAD_CLIENT_H
|
||||||
|
|
||||||
@@ -9,31 +14,35 @@ using std::string;
|
|||||||
|
|
||||||
|
|
||||||
class FileUploadClient {
|
class FileUploadClient {
|
||||||
public:
|
public:
|
||||||
FileUploadClient();
|
FileUploadClient();
|
||||||
virtual ~FileUploadClient();
|
virtual ~FileUploadClient();
|
||||||
|
|
||||||
enum ftp_mode {
|
enum ftp_mode {
|
||||||
binary_mode,
|
binary_mode,
|
||||||
ascii_mode
|
ascii_mode
|
||||||
};
|
};
|
||||||
|
|
||||||
virtual bool Connect(const string& server, const string& login,
|
virtual bool Connect(const string& server,
|
||||||
const string& passwd);
|
const string& login,
|
||||||
|
const string& passwd);
|
||||||
|
|
||||||
virtual bool PutFile(const string& local, const string& remote,
|
virtual bool PutFile(const string& local,
|
||||||
ftp_mode mode = binary_mode);
|
const string& remote,
|
||||||
|
ftp_mode mode = binary_mode);
|
||||||
|
|
||||||
virtual bool GetFile(const string& remote, const string& local,
|
virtual bool GetFile(const string& remote,
|
||||||
ftp_mode mode = binary_mode);
|
const string& local,
|
||||||
|
ftp_mode mode = binary_mode);
|
||||||
|
|
||||||
virtual bool MoveFile(const string& oldPath, const string& newPath);
|
virtual bool MoveFile(const string& oldPath,
|
||||||
virtual bool ChangeDir(const string& dir);
|
const string& newPath);
|
||||||
virtual bool PrintWorkingDir(string& dir);
|
virtual bool ChangeDir(const string& dir);
|
||||||
virtual bool ListDirContents(string& listing);
|
virtual bool PrintWorkingDir(string& dir);
|
||||||
virtual bool Chmod(const string& path, const string& mod);
|
virtual bool ListDirContents(string& listing);
|
||||||
|
virtual bool Chmod(const string& path, const string& mod);
|
||||||
|
|
||||||
virtual void SetPassive(bool on);
|
virtual void SetPassive(bool on);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // FILE_UPLOAD_CLIENT_H
|
#endif // FILE_UPLOAD_CLIENT_H
|
||||||
|
|||||||
@@ -1,3 +1,10 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 1998-1999 Be, Inc. All Rights Reserved.
|
||||||
|
* Copyright 2003-2019 Haiku, Inc. All rights reserved.
|
||||||
|
* Distributed under the terms of the MIT License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
#include "FtpClient.h"
|
#include "FtpClient.h"
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
@@ -12,7 +19,8 @@
|
|||||||
|
|
||||||
|
|
||||||
FtpClient::FtpClient()
|
FtpClient::FtpClient()
|
||||||
: FileUploadClient(),
|
:
|
||||||
|
FileUploadClient(),
|
||||||
fState(0),
|
fState(0),
|
||||||
fControl(NULL),
|
fControl(NULL),
|
||||||
fData(NULL)
|
fData(NULL)
|
||||||
@@ -32,7 +40,8 @@ FtpClient::ChangeDir(const string& dir)
|
|||||||
{
|
{
|
||||||
bool rc = false;
|
bool rc = false;
|
||||||
int code, codeType;
|
int code, codeType;
|
||||||
string cmd = "CWD ", replyString;
|
string cmd = "CWD ";
|
||||||
|
string replyString;
|
||||||
|
|
||||||
cmd += dir;
|
cmd += dir;
|
||||||
|
|
||||||
@@ -87,7 +96,7 @@ FtpClient::ListDirContents(string& listing)
|
|||||||
}
|
}
|
||||||
|
|
||||||
delete fData;
|
delete fData;
|
||||||
fData = 0;
|
fData = NULL;
|
||||||
|
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
@@ -98,7 +107,8 @@ FtpClient::PrintWorkingDir(string& dir)
|
|||||||
{
|
{
|
||||||
bool rc = false;
|
bool rc = false;
|
||||||
int code, codeType;
|
int code, codeType;
|
||||||
string cmd = "PWD", replyString;
|
string cmd = "PWD";
|
||||||
|
string replyString;
|
||||||
long i;
|
long i;
|
||||||
|
|
||||||
if (_SendRequest(cmd) == true) {
|
if (_SendRequest(cmd) == true) {
|
||||||
@@ -119,7 +129,8 @@ FtpClient::PrintWorkingDir(string& dir)
|
|||||||
|
|
||||||
|
|
||||||
bool
|
bool
|
||||||
FtpClient::Connect(const string& server, const string& login, const string& passwd)
|
FtpClient::Connect(const string& server, const string& login,
|
||||||
|
const string& passwd)
|
||||||
{
|
{
|
||||||
bool rc = false;
|
bool rc = false;
|
||||||
int code, codeType;
|
int code, codeType;
|
||||||
@@ -129,7 +140,7 @@ FtpClient::Connect(const string& server, const string& login, const string& pass
|
|||||||
delete fControl;
|
delete fControl;
|
||||||
delete fData;
|
delete fData;
|
||||||
|
|
||||||
fControl = new BNetEndpoint;
|
fControl = new BNetEndpoint();
|
||||||
|
|
||||||
if (fControl->InitCheck() != B_NO_ERROR)
|
if (fControl->InitCheck() != B_NO_ERROR)
|
||||||
return false;
|
return false;
|
||||||
@@ -174,7 +185,7 @@ FtpClient::Connect(const string& server, const string& login, const string& pass
|
|||||||
_SetState(ftp_connected);
|
_SetState(ftp_connected);
|
||||||
else {
|
else {
|
||||||
delete fControl;
|
delete fControl;
|
||||||
fControl = 0;
|
fControl = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
return rc;
|
return rc;
|
||||||
@@ -188,7 +199,9 @@ FtpClient::PutFile(const string& local, const string& remote, ftp_mode mode)
|
|||||||
string cmd, replyString;
|
string cmd, replyString;
|
||||||
int code, codeType, rlen, slen, i;
|
int code, codeType, rlen, slen, i;
|
||||||
BFile infile(local.c_str(), B_READ_ONLY);
|
BFile infile(local.c_str(), B_READ_ONLY);
|
||||||
char buf[8192], sbuf[16384], *stmp;
|
char buf[8192];
|
||||||
|
char sbuf[16384];
|
||||||
|
char* stmp;
|
||||||
|
|
||||||
if (infile.InitCheck() != B_NO_ERROR)
|
if (infile.InitCheck() != B_NO_ERROR)
|
||||||
return false;
|
return false;
|
||||||
@@ -251,7 +264,7 @@ FtpClient::PutFile(const string& local, const string& remote, ftp_mode mode)
|
|||||||
}
|
}
|
||||||
|
|
||||||
delete fData;
|
delete fData;
|
||||||
fData = 0;
|
fData = NULL;
|
||||||
|
|
||||||
if (rc) {
|
if (rc) {
|
||||||
_GetReply(replyString, code, codeType);
|
_GetReply(replyString, code, codeType);
|
||||||
@@ -269,7 +282,9 @@ FtpClient::GetFile(const string& remote, const string& local, ftp_mode mode)
|
|||||||
string cmd, replyString;
|
string cmd, replyString;
|
||||||
int code, codeType, rlen, slen, i;
|
int code, codeType, rlen, slen, i;
|
||||||
BFile outfile(local.c_str(), B_READ_WRITE | B_CREATE_FILE);
|
BFile outfile(local.c_str(), B_READ_WRITE | B_CREATE_FILE);
|
||||||
char buf[8192], sbuf[16384], *stmp;
|
char buf[8192];
|
||||||
|
char sbuf[16384];
|
||||||
|
char* stmp;
|
||||||
bool writeError = false;
|
bool writeError = false;
|
||||||
|
|
||||||
if (outfile.InitCheck() != B_NO_ERROR)
|
if (outfile.InitCheck() != B_NO_ERROR)
|
||||||
@@ -328,7 +343,7 @@ FtpClient::GetFile(const string& remote, const string& local, ftp_mode mode)
|
|||||||
}
|
}
|
||||||
|
|
||||||
delete fData;
|
delete fData;
|
||||||
fData = 0;
|
fData = NULL;
|
||||||
|
|
||||||
if (rc) {
|
if (rc) {
|
||||||
_GetReply(replyString, code, codeType);
|
_GetReply(replyString, code, codeType);
|
||||||
@@ -373,7 +388,8 @@ FtpClient::Chmod(const string& path, const string& mod)
|
|||||||
{
|
{
|
||||||
bool rc = false;
|
bool rc = false;
|
||||||
int code, codeType;
|
int code, codeType;
|
||||||
string cmd = "SITE CHMOD ", replyString;
|
string cmd = "SITE CHMOD ";
|
||||||
|
string replyString;
|
||||||
|
|
||||||
cmd += mod;
|
cmd += mod;
|
||||||
cmd += " ";
|
cmd += " ";
|
||||||
@@ -381,10 +397,11 @@ FtpClient::Chmod(const string& path, const string& mod)
|
|||||||
|
|
||||||
if (path.length() == 0)
|
if (path.length() == 0)
|
||||||
cmd += '/';
|
cmd += '/';
|
||||||
printf(B_TRANSLATE("cmd: '%s'\n"), cmd.c_str());
|
printf(B_TRANSLATE("cmd: '%s'\n"), cmd.c_str());
|
||||||
|
|
||||||
if (_SendRequest(cmd) == true) {
|
if (_SendRequest(cmd) == true) {
|
||||||
if (_GetReply(replyString, code, codeType) == true) {
|
if (_GetReply(replyString, code, codeType) == true) {
|
||||||
printf(B_TRANSLATE("reply: %d, %d\n"), code, codeType);
|
printf(B_TRANSLATE("reply: %d, %d\n"), code, codeType);
|
||||||
if (codeType == 2)
|
if (codeType == 2)
|
||||||
rc = true;
|
rc = true;
|
||||||
}
|
}
|
||||||
@@ -452,9 +469,10 @@ FtpClient::_GetReplyLine(string& line)
|
|||||||
int c = 0;
|
int c = 0;
|
||||||
bool done = false;
|
bool done = false;
|
||||||
|
|
||||||
line = ""; // Thanks to Stephen van Egmond for catching a bug here
|
line = "";
|
||||||
|
// Thanks to Stephen van Egmond for catching a bug here
|
||||||
|
|
||||||
if (fControl != 0) {
|
if (fControl != NULL) {
|
||||||
rc = true;
|
rc = true;
|
||||||
while (done == false && fControl->Receive(&c, 1) > 0) {
|
while (done == false && fControl->Receive(&c, 1) > 0) {
|
||||||
if (c == EOF || c == xEOF || c == '\n') {
|
if (c == EOF || c == xEOF || c == '\n') {
|
||||||
@@ -528,7 +546,8 @@ FtpClient::_GetReply(string& outString, int& outCode, int& codeType)
|
|||||||
* 123 The last line
|
* 123 The last line
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if ((rc = _GetReplyLine(line)) == true) {
|
rc = _GetReplyLine(line);
|
||||||
|
if (rc == true) {
|
||||||
outString = line;
|
outString = line;
|
||||||
outString += '\n';
|
outString += '\n';
|
||||||
printf(outString.c_str());
|
printf(outString.c_str());
|
||||||
@@ -536,13 +555,16 @@ FtpClient::_GetReply(string& outString, int& outCode, int& codeType)
|
|||||||
outCode = atoi(tempString.c_str());
|
outCode = atoi(tempString.c_str());
|
||||||
|
|
||||||
if (line[3] == '-') {
|
if (line[3] == '-') {
|
||||||
while ((rc = _GetReplyLine(line)) == true) {
|
rc = _GetReplyLine(line);
|
||||||
|
while (rc == true) {
|
||||||
outString += line;
|
outString += line;
|
||||||
outString += '\n';
|
outString += '\n';
|
||||||
printf(outString.c_str());
|
printf(outString.c_str());
|
||||||
// we're done with nnn when we get to a "nnn blahblahblah"
|
// we're done with nnn when we get to a "nnn blahblahblah"
|
||||||
if ((line.find(tempString) == 0) && line[3] == ' ')
|
if ((line.find(tempString) == 0) && line[3] == ' ')
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
rc = _GetReplyLine(line);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -554,7 +576,7 @@ FtpClient::_GetReply(string& outString, int& outCode, int& codeType)
|
|||||||
|
|
||||||
if (outCode == 421) {
|
if (outCode == 421) {
|
||||||
delete fControl;
|
delete fControl;
|
||||||
fControl = 0;
|
fControl = NULL;
|
||||||
_ClearState(ftp_connected);
|
_ClearState(ftp_connected);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -575,9 +597,9 @@ FtpClient::_OpenDataConnection()
|
|||||||
struct sockaddr_in sa;
|
struct sockaddr_in sa;
|
||||||
|
|
||||||
delete fData;
|
delete fData;
|
||||||
fData = 0;
|
fData = NULL;
|
||||||
|
|
||||||
fData = new BNetEndpoint;
|
fData = new BNetEndpoint();
|
||||||
|
|
||||||
if (_TestState(ftp_passive)) {
|
if (_TestState(ftp_passive)) {
|
||||||
// Here we send a "pasv" command and connect to the remote server
|
// Here we send a "pasv" command and connect to the remote server
|
||||||
@@ -595,13 +617,15 @@ FtpClient::_OpenDataConnection()
|
|||||||
i = replyString.find('(');
|
i = replyString.find('(');
|
||||||
i++;
|
i++;
|
||||||
|
|
||||||
replyString = replyString.substr(i, replyString.find(')') - i);
|
replyString = replyString.substr(i,
|
||||||
|
replyString.find(')') - i);
|
||||||
if (sscanf(replyString.c_str(), "%d,%d,%d,%d,%d,%d",
|
if (sscanf(replyString.c_str(), "%d,%d,%d,%d,%d,%d",
|
||||||
&paddr[0], &paddr[1], &paddr[2], &paddr[3],
|
&paddr[0], &paddr[1], &paddr[2], &paddr[3],
|
||||||
&paddr[4], &paddr[5]) != 6) {
|
&paddr[4], &paddr[5]) != 6) {
|
||||||
// cannot do passive. Do a little harmless rercursion here
|
// Cannot do passive.
|
||||||
_ClearState(ftp_passive);
|
// Do a little harmless rercursion here.
|
||||||
return _OpenDataConnection();
|
_ClearState(ftp_passive);
|
||||||
|
return _OpenDataConnection();
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; i < 6; i++)
|
for (i = 0; i < 6; i++)
|
||||||
@@ -661,9 +685,9 @@ FtpClient::_AcceptDataConnection()
|
|||||||
bool rc = false;
|
bool rc = false;
|
||||||
|
|
||||||
if (_TestState(ftp_passive) == false) {
|
if (_TestState(ftp_passive) == false) {
|
||||||
if (fData != 0) {
|
if (fData != NULL) {
|
||||||
endPoint = fData->Accept();
|
endPoint = fData->Accept();
|
||||||
if (endPoint != 0) {
|
if (endPoint != NULL) {
|
||||||
delete fData;
|
delete fData;
|
||||||
fData = endPoint;
|
fData = endPoint;
|
||||||
rc = true;
|
rc = true;
|
||||||
|
|||||||
@@ -1,3 +1,8 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 1998-1999 Be, Inc. All Rights Reserved.
|
||||||
|
* Copyright 2003-2019 Haiku, Inc. All rights reserved.
|
||||||
|
* Distributed under the terms of the MIT License.
|
||||||
|
*/
|
||||||
#ifndef FTP_CLIENT_H
|
#ifndef FTP_CLIENT_H
|
||||||
#define FTP_CLIENT_H
|
#define FTP_CLIENT_H
|
||||||
|
|
||||||
@@ -6,7 +11,9 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#include <File.h>
|
#include <File.h>
|
||||||
#include <NetworkKit.h>
|
#include <NetAddress.h>
|
||||||
|
#include <NetEndpoint.h>
|
||||||
|
|
||||||
#include "FileUploadClient.h"
|
#include "FileUploadClient.h"
|
||||||
|
|
||||||
using std::string;
|
using std::string;
|
||||||
@@ -24,47 +31,52 @@ using std::string;
|
|||||||
|
|
||||||
|
|
||||||
class FtpClient : public FileUploadClient {
|
class FtpClient : public FileUploadClient {
|
||||||
public:
|
public:
|
||||||
FtpClient();
|
FtpClient();
|
||||||
~FtpClient();
|
~FtpClient();
|
||||||
|
|
||||||
bool Connect(const string& server, const string& login,
|
bool Connect(const string& server,
|
||||||
const string& passwd);
|
const string& login,
|
||||||
|
const string& passwd);
|
||||||
|
|
||||||
bool PutFile(const string& local, const string& remote,
|
bool PutFile(const string& local,
|
||||||
ftp_mode mode = binary_mode);
|
const string& remote,
|
||||||
|
ftp_mode mode = binary_mode);
|
||||||
|
|
||||||
bool GetFile(const string& remote, const string& local,
|
bool GetFile(const string& remote,
|
||||||
ftp_mode mode = binary_mode);
|
const string& local,
|
||||||
|
ftp_mode mode = binary_mode);
|
||||||
|
|
||||||
bool MoveFile(const string& oldPath, const string& newPath);
|
bool MoveFile(const string& oldPath,
|
||||||
bool ChangeDir(const string& dir);
|
const string& newPath);
|
||||||
bool PrintWorkingDir(string& dir);
|
bool ChangeDir(const string& dir);
|
||||||
bool ListDirContents(string& listing);
|
bool PrintWorkingDir(string& dir);
|
||||||
bool Chmod(const string& path, const string& mod);
|
bool ListDirContents(string& listing);
|
||||||
|
bool Chmod(const string& path, const string& mod);
|
||||||
|
|
||||||
void SetPassive(bool on);
|
void SetPassive(bool on);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
enum {
|
enum {
|
||||||
ftp_complete = 1UL,
|
ftp_complete = 1UL,
|
||||||
ftp_connected = 2,
|
ftp_connected = 2,
|
||||||
ftp_passive = 4
|
ftp_passive = 4
|
||||||
};
|
};
|
||||||
|
|
||||||
bool _TestState(unsigned long state);
|
bool _TestState(unsigned long state);
|
||||||
void _SetState(unsigned long state);
|
void _SetState(unsigned long state);
|
||||||
void _ClearState(unsigned long state);
|
void _ClearState(unsigned long state);
|
||||||
|
|
||||||
bool _SendRequest(const string& cmd);
|
bool _SendRequest(const string& cmd);
|
||||||
bool _GetReply(string& outString, int& outCode, int& codeType);
|
bool _GetReply(string& outString, int& outCode,
|
||||||
bool _GetReplyLine(string& line);
|
int& codeType);
|
||||||
bool _OpenDataConnection();
|
bool _GetReplyLine(string& line);
|
||||||
bool _AcceptDataConnection();
|
bool _OpenDataConnection();
|
||||||
|
bool _AcceptDataConnection();
|
||||||
|
|
||||||
unsigned long fState;
|
unsigned long fState;
|
||||||
BNetEndpoint* fControl;
|
BNetEndpoint* fControl;
|
||||||
BNetEndpoint* fData;
|
BNetEndpoint* fData;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,10 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 1998-1999 Be, Inc. All Rights Reserved.
|
||||||
|
* Copyright 2003-2019 Haiku, Inc. All rights reserved.
|
||||||
|
* Distributed under the terms of the MIT License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
#include "Settings.h"
|
#include "Settings.h"
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
@@ -71,9 +78,9 @@ StringValueSetting::NeedsSaving() const
|
|||||||
|
|
||||||
|
|
||||||
const char*
|
const char*
|
||||||
StringValueSetting::Handle(const char *const *argv)
|
StringValueSetting::Handle(const char* const *argv)
|
||||||
{
|
{
|
||||||
if (!*++argv)
|
if (*++argv == NULL)
|
||||||
return fValueExpectedErrorString;
|
return fValueExpectedErrorString;
|
||||||
|
|
||||||
ValueChanged(*argv);
|
ValueChanged(*argv);
|
||||||
@@ -108,9 +115,9 @@ EnumeratedStringValueSetting::ValueChanged(const char* newValue)
|
|||||||
|
|
||||||
|
|
||||||
const char*
|
const char*
|
||||||
EnumeratedStringValueSetting::Handle(const char *const *argv)
|
EnumeratedStringValueSetting::Handle(const char* const *argv)
|
||||||
{
|
{
|
||||||
if (!*++argv)
|
if (*++argv == NULL)
|
||||||
return fValueExpectedErrorString;
|
return fValueExpectedErrorString;
|
||||||
|
|
||||||
printf("---EnumeratedStringValueSetting::Handle %s %s\n", *(argv-1), *argv);
|
printf("---EnumeratedStringValueSetting::Handle %s %s\n", *(argv-1), *argv);
|
||||||
@@ -127,7 +134,7 @@ EnumeratedStringValueSetting::_ValidateString(const char* string)
|
|||||||
{
|
{
|
||||||
for (int32 i = 0;; i++) {
|
for (int32 i = 0;; i++) {
|
||||||
const char* enumString = fEnumerator(i);
|
const char* enumString = fEnumerator(i);
|
||||||
if (!enumString)
|
if (enumString == NULL)
|
||||||
return false;
|
return false;
|
||||||
if (strcmp(enumString, string) == 0)
|
if (strcmp(enumString, string) == 0)
|
||||||
return true;
|
return true;
|
||||||
@@ -142,7 +149,8 @@ EnumeratedStringValueSetting::_ValidateString(const char* string)
|
|||||||
ScalarValueSetting::ScalarValueSetting(const char* name, int32 defaultValue,
|
ScalarValueSetting::ScalarValueSetting(const char* name, int32 defaultValue,
|
||||||
const char* valueExpectedErrorString, const char* wrongValueErrorString,
|
const char* valueExpectedErrorString, const char* wrongValueErrorString,
|
||||||
int32 min, int32 max)
|
int32 min, int32 max)
|
||||||
: SettingsArgvDispatcher(name),
|
:
|
||||||
|
SettingsArgvDispatcher(name),
|
||||||
fDefaultValue(defaultValue),
|
fDefaultValue(defaultValue),
|
||||||
fValue(defaultValue),
|
fValue(defaultValue),
|
||||||
fMax(max),
|
fMax(max),
|
||||||
@@ -182,9 +190,9 @@ ScalarValueSetting::GetValueAsString(char* buffer) const
|
|||||||
|
|
||||||
|
|
||||||
const char*
|
const char*
|
||||||
ScalarValueSetting::Handle(const char *const *argv)
|
ScalarValueSetting::Handle(const char* const *argv)
|
||||||
{
|
{
|
||||||
if (!*++argv)
|
if (*++argv == NULL)
|
||||||
return fValueExpectedErrorString;
|
return fValueExpectedErrorString;
|
||||||
|
|
||||||
int32 newValue = atoi(*argv);
|
int32 newValue = atoi(*argv);
|
||||||
@@ -199,7 +207,7 @@ ScalarValueSetting::Handle(const char *const *argv)
|
|||||||
void
|
void
|
||||||
ScalarValueSetting::SaveSettingValue(Settings* settings)
|
ScalarValueSetting::SaveSettingValue(Settings* settings)
|
||||||
{
|
{
|
||||||
settings->Write("%d", fValue);
|
settings->Write("%" B_PRId32, fValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -214,7 +222,8 @@ ScalarValueSetting::NeedsSaving() const
|
|||||||
|
|
||||||
|
|
||||||
BooleanValueSetting::BooleanValueSetting(const char* name, bool defaultValue)
|
BooleanValueSetting::BooleanValueSetting(const char* name, bool defaultValue)
|
||||||
: ScalarValueSetting(name, defaultValue, 0, 0)
|
:
|
||||||
|
ScalarValueSetting(name, defaultValue, 0, 0)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -232,9 +241,9 @@ BooleanValueSetting::Value() const
|
|||||||
|
|
||||||
|
|
||||||
const char*
|
const char*
|
||||||
BooleanValueSetting::Handle(const char *const *argv)
|
BooleanValueSetting::Handle(const char* const *argv)
|
||||||
{
|
{
|
||||||
if (!*++argv) {
|
if (*++argv == NULL) {
|
||||||
return B_TRANSLATE_COMMENT("on or off expected","Do not translate "
|
return B_TRANSLATE_COMMENT("on or off expected","Do not translate "
|
||||||
"'on' and 'off'");
|
"'on' and 'off'");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,3 +1,8 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 1998-1999 Be, Inc. All Rights Reserved.
|
||||||
|
* Copyright 2003-2019 Haiku, Inc. All rights reserved.
|
||||||
|
* Distributed under the terms of the MIT License.
|
||||||
|
*/
|
||||||
#ifndef SETTINGS_H
|
#ifndef SETTINGS_H
|
||||||
#define SETTINGS_H
|
#define SETTINGS_H
|
||||||
|
|
||||||
@@ -18,7 +23,7 @@ public:
|
|||||||
|
|
||||||
void ValueChanged(const char* newValue);
|
void ValueChanged(const char* newValue);
|
||||||
const char* Value() const;
|
const char* Value() const;
|
||||||
virtual const char* Handle(const char *const *argv);
|
virtual const char* Handle(const char* const *argv);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void SaveSettingValue(Settings*);
|
virtual void SaveSettingValue(Settings*);
|
||||||
@@ -46,7 +51,7 @@ public:
|
|||||||
const char* wrongValueErrorString);
|
const char* wrongValueErrorString);
|
||||||
|
|
||||||
void ValueChanged(const char* newValue);
|
void ValueChanged(const char* newValue);
|
||||||
virtual const char* Handle(const char *const *argv);
|
virtual const char* Handle(const char* const *argv);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool _ValidateString(const char* string);
|
bool _ValidateString(const char* string);
|
||||||
@@ -61,13 +66,14 @@ public:
|
|||||||
int32 defaultValue,
|
int32 defaultValue,
|
||||||
const char* valueExpectedErrorString,
|
const char* valueExpectedErrorString,
|
||||||
const char* wrongValueErrorString,
|
const char* wrongValueErrorString,
|
||||||
int32 min = INT32_MIN, int32 max = INT32_MAX);
|
int32 min = INT32_MIN,
|
||||||
|
int32 max = INT32_MAX);
|
||||||
virtual ~ScalarValueSetting();
|
virtual ~ScalarValueSetting();
|
||||||
|
|
||||||
void ValueChanged(int32 newValue);
|
void ValueChanged(int32 newValue);
|
||||||
int32 Value() const;
|
int32 Value() const;
|
||||||
void GetValueAsString(char*) const;
|
void GetValueAsString(char*) const;
|
||||||
virtual const char* Handle(const char *const *argv);
|
virtual const char* Handle(const char* const *argv);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void SaveSettingValue(Settings*);
|
virtual void SaveSettingValue(Settings*);
|
||||||
@@ -89,10 +95,10 @@ public:
|
|||||||
virtual ~BooleanValueSetting();
|
virtual ~BooleanValueSetting();
|
||||||
|
|
||||||
bool Value() const;
|
bool Value() const;
|
||||||
virtual const char* Handle(const char *const *argv);
|
virtual const char* Handle(const char* const *argv);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void SaveSettingValue(Settings *);
|
virtual void SaveSettingValue(Settings*);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // SETTINGS_H
|
#endif // SETTINGS_H
|
||||||
|
|||||||
@@ -1,10 +1,20 @@
|
|||||||
#include <String.h>
|
/*
|
||||||
#include <unistd.h>
|
* Copyright 1998-1999 Be, Inc. All Rights Reserved.
|
||||||
|
* Copyright 2003-2019 Haiku, Inc. All rights reserved.
|
||||||
|
* Distributed under the terms of the MIT License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
#include "SftpClient.h"
|
#include "SftpClient.h"
|
||||||
|
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
|
#include <String.h>
|
||||||
|
|
||||||
|
|
||||||
SftpClient::SftpClient()
|
SftpClient::SftpClient()
|
||||||
: SpawningUploadClient()
|
:
|
||||||
|
SpawningUploadClient()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -19,33 +29,37 @@ SftpClient::~SftpClient()
|
|||||||
bool
|
bool
|
||||||
SftpClient::ChangeDir(const string& dir)
|
SftpClient::ChangeDir(const string& dir)
|
||||||
{
|
{
|
||||||
bool rc = false;
|
|
||||||
int len;
|
int len;
|
||||||
BString cmd("cd");
|
BString cmd("cd");
|
||||||
BString reply;
|
BString reply;
|
||||||
|
|
||||||
cmd << " " << dir.c_str() << "\n";
|
cmd << " " << dir.c_str() << "\n";
|
||||||
SendCommand(cmd.String());
|
SendCommand(cmd.String());
|
||||||
if ((len = ReadReply(&reply)) < 0) {
|
|
||||||
|
len = ReadReply(&reply);
|
||||||
|
if (len < 0) {
|
||||||
fprintf(stderr, _GetReadText(), len);
|
fprintf(stderr, _GetReadText(), len);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
fprintf(stderr, _GetReplyText(), reply.String());
|
fprintf(stderr, _GetReplyText(), reply.String());
|
||||||
if (reply.FindFirst("sftp>") < 0)
|
if (reply.FindFirst("sftp>") < 0)
|
||||||
return false;
|
return false;
|
||||||
rc = true;
|
|
||||||
return rc;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool
|
bool
|
||||||
SftpClient::ListDirContents(string& listing)
|
SftpClient::ListDirContents(string& listing)
|
||||||
{
|
{
|
||||||
bool rc = false;
|
|
||||||
int len;
|
int len;
|
||||||
SendCommand("ls\n");
|
|
||||||
BString reply;
|
BString reply;
|
||||||
|
|
||||||
|
SendCommand("ls\n");
|
||||||
do {
|
do {
|
||||||
if ((len = ReadReply(&reply)) < 0) {
|
len = ReadReply(&reply);
|
||||||
|
if (len < 0) {
|
||||||
fprintf(stderr, _GetReadText(), len);
|
fprintf(stderr, _GetReadText(), len);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -54,17 +68,16 @@ SftpClient::ListDirContents(string& listing)
|
|||||||
if (reply.FindFirst("sftp>") == 0)
|
if (reply.FindFirst("sftp>") == 0)
|
||||||
return true;
|
return true;
|
||||||
} while (true);
|
} while (true);
|
||||||
return rc;
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool
|
bool
|
||||||
SftpClient::PrintWorkingDir(string& dir)
|
SftpClient::PrintWorkingDir(string& dir)
|
||||||
{
|
{
|
||||||
bool rc = false;
|
|
||||||
SendCommand("pwd\n");
|
SendCommand("pwd\n");
|
||||||
BString reply;
|
return false;
|
||||||
return rc;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -72,24 +85,30 @@ bool
|
|||||||
SftpClient::Connect(const string& server, const string& login,
|
SftpClient::Connect(const string& server, const string& login,
|
||||||
const string& passwd)
|
const string& passwd)
|
||||||
{
|
{
|
||||||
bool rc = false;
|
|
||||||
BString cmd("sftp ");
|
BString cmd("sftp ");
|
||||||
BString host(server.c_str());
|
BString host(server.c_str());
|
||||||
BString port;
|
BString port;
|
||||||
|
|
||||||
if (host.FindFirst(':'))
|
if (host.FindFirst(':'))
|
||||||
host.MoveInto(port, host.FindFirst(':'), host.Length());
|
host.MoveInto(port, host.FindFirst(':'), host.Length());
|
||||||
port.RemoveAll(":");
|
port.RemoveAll(":");
|
||||||
|
|
||||||
if (port.Length())
|
if (port.Length())
|
||||||
cmd << "-oPort=" << port << " ";
|
cmd << "-oPort=" << port << " ";
|
||||||
|
|
||||||
cmd << login.c_str();
|
cmd << login.c_str();
|
||||||
cmd << "@" << host.String();
|
cmd << "@" << host.String();
|
||||||
printf("COMMAND: '%s'\n", cmd.String());
|
printf("COMMAND: '%s'\n", cmd.String());
|
||||||
SetCommandLine(cmd.String());
|
SetCommandLine(cmd.String());
|
||||||
rc = SpawningUploadClient::Connect(server, login, passwd);
|
|
||||||
|
if (!SpawningUploadClient::Connect(server, login, passwd))
|
||||||
|
return false;
|
||||||
|
|
||||||
BString reply;
|
BString reply;
|
||||||
ssize_t len;
|
ssize_t len;
|
||||||
|
|
||||||
if ((len = ReadReply(&reply)) < 0) {
|
len = ReadReply(&reply);
|
||||||
|
if (len < 0) {
|
||||||
fprintf(stderr, _GetLongReadText(), len);
|
fprintf(stderr, _GetLongReadText(), len);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -97,10 +116,12 @@ SftpClient::Connect(const string& server, const string& login,
|
|||||||
if (reply.FindFirst("Connecting to ") != 0)
|
if (reply.FindFirst("Connecting to ") != 0)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if ((len = ReadReply(&reply)) < 0) {
|
len = ReadReply(&reply);
|
||||||
|
if (len < 0) {
|
||||||
fprintf(stderr, _GetLongReadText(), len);
|
fprintf(stderr, _GetLongReadText(), len);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
fprintf(stderr, _GetReplyText(), reply.String());
|
fprintf(stderr, _GetReplyText(), reply.String());
|
||||||
if (reply.FindFirst(/*[pP]*/"assword:") < 0)
|
if (reply.FindFirst(/*[pP]*/"assword:") < 0)
|
||||||
return false;
|
return false;
|
||||||
@@ -108,63 +129,70 @@ SftpClient::Connect(const string& server, const string& login,
|
|||||||
write(OutputPipe(), passwd.c_str(), strlen(passwd.c_str()));
|
write(OutputPipe(), passwd.c_str(), strlen(passwd.c_str()));
|
||||||
write(OutputPipe(), "\n", 1);
|
write(OutputPipe(), "\n", 1);
|
||||||
|
|
||||||
if ((len = ReadReply(&reply)) < 0) {
|
len = ReadReply(&reply);
|
||||||
|
if (len < 0) {
|
||||||
fprintf(stderr, _GetLongReadText(), len);
|
fprintf(stderr, _GetLongReadText(), len);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
fprintf(stderr, _GetReplyText(), reply.String());
|
fprintf(stderr, _GetReplyText(), reply.String());
|
||||||
if (reply != "\n")
|
if (reply != "\n")
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if ((len = ReadReply(&reply)) < 0) {
|
len = ReadReply(&reply);
|
||||||
|
if (len < 0) {
|
||||||
fprintf(stderr, _GetLongReadText(), len);
|
fprintf(stderr, _GetLongReadText(), len);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
fprintf(stderr, _GetReplyText(), reply.String());
|
fprintf(stderr, _GetReplyText(), reply.String());
|
||||||
if (reply.FindFirst("sftp>") < 0)
|
if (reply.FindFirst("sftp>") < 0)
|
||||||
return false;
|
return false;
|
||||||
return rc;
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool
|
bool
|
||||||
SftpClient::PutFile(const string& local, const string& remote, ftp_mode mode)
|
SftpClient::PutFile(const string& local, const string& remote, ftp_mode mode)
|
||||||
{
|
{
|
||||||
bool rc = false;
|
|
||||||
int len;
|
int len;
|
||||||
//XXX: handle mode ?
|
//XXX: handle mode ?
|
||||||
BString cmd("put");
|
BString cmd("put");
|
||||||
cmd << " " << local.c_str() << " " << remote.c_str() << "\n";
|
cmd << " " << local.c_str() << " " << remote.c_str() << "\n";
|
||||||
SendCommand(cmd.String());
|
SendCommand(cmd.String());
|
||||||
|
|
||||||
BString reply;
|
BString reply;
|
||||||
|
|
||||||
if ((len = ReadReply(&reply)) < 0) {
|
len = ReadReply(&reply);
|
||||||
|
if (len < 0) {
|
||||||
fprintf(stderr, _GetReadText(), len);
|
fprintf(stderr, _GetReadText(), len);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
fprintf(stderr, _GetReplyText(), reply.String());
|
fprintf(stderr, _GetReplyText(), reply.String());
|
||||||
if (reply.FindFirst("Uploading") < 0)
|
if (reply.FindFirst("Uploading") < 0)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if ((len = ReadReply(&reply)) < 0) {
|
len = ReadReply(&reply);
|
||||||
|
if (len < 0) {
|
||||||
fprintf(stderr, _GetReadText(), len);
|
fprintf(stderr, _GetReadText(), len);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
fprintf(stderr, _GetReplyText(), reply.String());
|
fprintf(stderr, _GetReplyText(), reply.String());
|
||||||
if (reply.FindFirst("sftp>") < 0)
|
if (reply.FindFirst("sftp>") < 0)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
rc = true;
|
return true;
|
||||||
return rc;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool
|
bool
|
||||||
SftpClient::GetFile(const string& remote, const string& local, ftp_mode mode)
|
SftpClient::GetFile(const string& remote, const string& local, ftp_mode mode)
|
||||||
{
|
{
|
||||||
bool rc = false;
|
|
||||||
//XXX
|
//XXX
|
||||||
return rc;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -173,7 +201,6 @@ SftpClient::GetFile(const string& remote, const string& local, ftp_mode mode)
|
|||||||
bool
|
bool
|
||||||
SftpClient::MoveFile(const string& oldPath, const string& newPath)
|
SftpClient::MoveFile(const string& oldPath, const string& newPath)
|
||||||
{
|
{
|
||||||
bool rc = false;
|
|
||||||
int len;
|
int len;
|
||||||
|
|
||||||
// sftpd can't rename to an existing file...
|
// sftpd can't rename to an existing file...
|
||||||
@@ -183,19 +210,23 @@ SftpClient::MoveFile(const string& oldPath, const string& newPath)
|
|||||||
SendCommand(cmd.String());
|
SendCommand(cmd.String());
|
||||||
BString reply;
|
BString reply;
|
||||||
|
|
||||||
if ((len = ReadReply(&reply)) < 0) {
|
len = ReadReply(&reply);
|
||||||
|
if (len < 0) {
|
||||||
fprintf(stderr, _GetReadText(), len);
|
fprintf(stderr, _GetReadText(), len);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
fprintf(stderr, _GetReplyText(), reply.String());
|
fprintf(stderr, _GetReplyText(), reply.String());
|
||||||
// we don't care if it worked or not.
|
// we don't care if it worked or not.
|
||||||
//if (reply.FindFirst("Removing") != 0 && reply.FindFirst("Couldn't") )
|
//if (reply.FindFirst("Removing") != 0 && reply.FindFirst("Couldn't") )
|
||||||
// return false;
|
// return false;
|
||||||
|
|
||||||
if ((len = ReadReply(&reply)) < 0) {
|
len = ReadReply(&reply);
|
||||||
|
if (len < 0) {
|
||||||
fprintf(stderr, _GetReadText(), len);
|
fprintf(stderr, _GetReadText(), len);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
fprintf(stderr, _GetReplyText(), reply.String());
|
fprintf(stderr, _GetReplyText(), reply.String());
|
||||||
if (reply.FindFirst("sftp>") < 0)
|
if (reply.FindFirst("sftp>") < 0)
|
||||||
return false;
|
return false;
|
||||||
@@ -203,47 +234,53 @@ SftpClient::MoveFile(const string& oldPath, const string& newPath)
|
|||||||
cmd = "rename";
|
cmd = "rename";
|
||||||
cmd << " " << oldPath.c_str() << " " << newPath.c_str() << "\n";
|
cmd << " " << oldPath.c_str() << " " << newPath.c_str() << "\n";
|
||||||
SendCommand(cmd.String());
|
SendCommand(cmd.String());
|
||||||
if ((len = ReadReply(&reply)) < 0) {
|
|
||||||
|
len = ReadReply(&reply);
|
||||||
|
if (len < 0) {
|
||||||
fprintf(stderr, _GetReadText(), len);
|
fprintf(stderr, _GetReadText(), len);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
fprintf(stderr, _GetReplyText(), reply.String());
|
fprintf(stderr, _GetReplyText(), reply.String());
|
||||||
if (reply.FindFirst("sftp>") < 0)
|
if (reply.FindFirst("sftp>") < 0)
|
||||||
return false;
|
return false;
|
||||||
rc = true;
|
|
||||||
return rc;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool
|
bool
|
||||||
SftpClient::Chmod(const string& path, const string& mod)
|
SftpClient::Chmod(const string& path, const string& mod)
|
||||||
{
|
{
|
||||||
bool rc = false;
|
|
||||||
int len;
|
int len;
|
||||||
//XXX: handle mode ?
|
//XXX: handle mode ?
|
||||||
BString cmd("chmod");
|
BString cmd("chmod");
|
||||||
cmd << " " << mod.c_str() << " " << path.c_str() << "\n";
|
cmd << " " << mod.c_str() << " " << path.c_str() << "\n";
|
||||||
SendCommand(cmd.String());
|
SendCommand(cmd.String());
|
||||||
|
|
||||||
BString reply;
|
BString reply;
|
||||||
|
|
||||||
if ((len = ReadReply(&reply)) < 0) {
|
len = ReadReply(&reply);
|
||||||
|
if (len < 0) {
|
||||||
fprintf(stderr, _GetReadText(), len);
|
fprintf(stderr, _GetReadText(), len);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
fprintf(stderr, _GetReplyText(), reply.String());
|
fprintf(stderr, _GetReplyText(), reply.String());
|
||||||
if (reply.FindFirst("Changing") < 0)
|
if (reply.FindFirst("Changing") < 0)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if ((len = ReadReply(&reply)) < 0) {
|
len = ReadReply(&reply);
|
||||||
|
if (len < 0) {
|
||||||
fprintf(stderr, _GetReadText(), len);
|
fprintf(stderr, _GetReadText(), len);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
fprintf(stderr, _GetReplyText(), reply.String());
|
fprintf(stderr, _GetReplyText(), reply.String());
|
||||||
if (reply.FindFirst("sftp>") < 0)
|
if (reply.FindFirst("sftp>") < 0)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
rc = true;
|
return true;
|
||||||
return rc;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -272,5 +309,3 @@ SftpClient::_GetReplyText() const
|
|||||||
{
|
{
|
||||||
return B_TRANSLATE("reply: '%s'\n");
|
return B_TRANSLATE("reply: '%s'\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,8 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 1998-1999 Be, Inc. All Rights Reserved.
|
||||||
|
* Copyright 2003-2019 Haiku, Inc. All rights reserved.
|
||||||
|
* Distributed under the terms of the MIT License.
|
||||||
|
*/
|
||||||
#ifndef SFTP_CLIENT_H
|
#ifndef SFTP_CLIENT_H
|
||||||
#define SFTP_CLIENT_H
|
#define SFTP_CLIENT_H
|
||||||
|
|
||||||
|
|||||||
@@ -1,18 +1,27 @@
|
|||||||
#include <errno.h>
|
/*
|
||||||
#include <image.h>
|
* Copyright 1998-1999 Be, Inc. All Rights Reserved.
|
||||||
#include <unistd.h>
|
* Copyright 2003-2019 Haiku, Inc. All rights reserved.
|
||||||
#include <signal.h>
|
* Distributed under the terms of the MIT License.
|
||||||
#include <stdlib.h>
|
*/
|
||||||
|
|
||||||
#include <String.h>
|
|
||||||
|
|
||||||
#include "SpawningUploadClient.h"
|
#include "SpawningUploadClient.h"
|
||||||
|
|
||||||
|
#include <errno.h>
|
||||||
|
#include <signal.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
|
#include <image.h>
|
||||||
|
#include <String.h>
|
||||||
|
|
||||||
|
|
||||||
SpawningUploadClient::SpawningUploadClient()
|
SpawningUploadClient::SpawningUploadClient()
|
||||||
: FileUploadClient()
|
:
|
||||||
, fCommand()
|
FileUploadClient(),
|
||||||
, fCommandPid(-1)
|
fCommand(),
|
||||||
, fPty(-1)
|
fCommandPid(-1),
|
||||||
|
fPty(-1)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -22,18 +31,21 @@ SpawningUploadClient::~SpawningUploadClient()
|
|||||||
close(fPty);
|
close(fPty);
|
||||||
kill(fCommandPid, SIGTERM);
|
kill(fCommandPid, SIGTERM);
|
||||||
kill(fCommandPid, SIGKILL);
|
kill(fCommandPid, SIGKILL);
|
||||||
|
|
||||||
status_t ret;
|
status_t ret;
|
||||||
wait_for_thread(fCommandPid, &ret);
|
wait_for_thread(fCommandPid, &ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool
|
bool
|
||||||
SpawningUploadClient::Connect(const string& server, const string& login, const string& passwd)
|
SpawningUploadClient::Connect(const string& server, const string& login,
|
||||||
|
const string& passwd)
|
||||||
{
|
{
|
||||||
bool rc = false;
|
bool rc = false;
|
||||||
// fCommand += " ";
|
// fCommand += " ";
|
||||||
// fCommand += server;
|
// fCommand += server;
|
||||||
rc = SpawnCommand();
|
rc = SpawnCommand();
|
||||||
|
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -58,18 +70,19 @@ SpawningUploadClient::SpawnCommand()
|
|||||||
shellcmd << "export LC_ALL=C; export LANG=C; ";
|
shellcmd << "export LC_ALL=C; export LANG=C; ";
|
||||||
shellcmd << "exec ";
|
shellcmd << "exec ";
|
||||||
shellcmd << fCommand.c_str();
|
shellcmd << fCommand.c_str();
|
||||||
printf("spawning: '%s'\n", shellcmd.String());
|
printf("spawning: '%s'\n", shellcmd.String());
|
||||||
args[2] = shellcmd.String();
|
args[2] = shellcmd.String();
|
||||||
fCommandPid = load_image(3, args, (const char **)environ);
|
fCommandPid = load_image(3, args, (const char**)environ);
|
||||||
if (fCommandPid < 0)
|
if (fCommandPid < 0)
|
||||||
return false;
|
return false;
|
||||||
resume_thread(fCommandPid);
|
resume_thread(fCommandPid);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
status_t
|
status_t
|
||||||
SpawningUploadClient::SetCommandLine(const char *command)
|
SpawningUploadClient::SetCommandLine(const char* command)
|
||||||
{
|
{
|
||||||
fCommand = command;
|
fCommand = command;
|
||||||
return B_OK;
|
return B_OK;
|
||||||
@@ -77,22 +90,24 @@ SpawningUploadClient::SetCommandLine(const char *command)
|
|||||||
|
|
||||||
|
|
||||||
ssize_t
|
ssize_t
|
||||||
SpawningUploadClient::SendCommand(const char *cmd)
|
SpawningUploadClient::SendCommand(const char* cmd)
|
||||||
{
|
{
|
||||||
return write(InputPipe(), cmd, strlen(cmd));
|
return write(InputPipe(), cmd, strlen(cmd));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
ssize_t
|
ssize_t
|
||||||
SpawningUploadClient::ReadReply(BString *to)
|
SpawningUploadClient::ReadReply(BString* to)
|
||||||
{
|
{
|
||||||
char buff[1024];
|
char buff[1024];
|
||||||
ssize_t len;
|
ssize_t len;
|
||||||
|
|
||||||
to->Truncate(0);
|
to->Truncate(0);
|
||||||
len = read(OutputPipe(), buff, 1024);
|
len = read(OutputPipe(), buff, 1024);
|
||||||
if (len < 0)
|
if (len < 0)
|
||||||
return errno;
|
return errno;
|
||||||
to->Append(buff, len);
|
to->Append(buff, len);
|
||||||
|
|
||||||
return len;
|
return len;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -105,7 +120,7 @@ SpawningUploadClient::ParseReply()
|
|||||||
|
|
||||||
|
|
||||||
int
|
int
|
||||||
SpawningUploadClient::getpty(char *pty, char *tty)
|
SpawningUploadClient::getpty(char* pty, char* tty)
|
||||||
{
|
{
|
||||||
static const char major[] = "pqrs";
|
static const char major[] = "pqrs";
|
||||||
static const char minor[] = "0123456789abcdef";
|
static const char minor[] = "0123456789abcdef";
|
||||||
@@ -120,9 +135,7 @@ SpawningUploadClient::getpty(char *pty, char *tty)
|
|||||||
sprintf(tty, "/dev/tt/%c%c", major[i], minor[j]);
|
sprintf(tty, "/dev/tt/%c%c", major[i], minor[j]);
|
||||||
fd = open(pty, O_RDWR|O_NOCTTY);
|
fd = open(pty, O_RDWR|O_NOCTTY);
|
||||||
if (fd >= 0)
|
if (fd >= 0)
|
||||||
{
|
|
||||||
return fd;
|
return fd;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -136,40 +149,37 @@ SpawningUploadClient::getpty(char *pty, char *tty)
|
|||||||
bool
|
bool
|
||||||
SpawningUploadClient::ChangeDir(const string& dir)
|
SpawningUploadClient::ChangeDir(const string& dir)
|
||||||
{
|
{
|
||||||
bool rc = false;
|
return false;
|
||||||
return rc;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool
|
bool
|
||||||
SpawningUploadClient::ListDirContents(string& listing)
|
SpawningUploadClient::ListDirContents(string& listing)
|
||||||
{
|
{
|
||||||
bool rc = false;
|
return false;
|
||||||
return rc;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool
|
bool
|
||||||
SpawningUploadClient::PrintWorkingDir(string& dir)
|
SpawningUploadClient::PrintWorkingDir(string& dir)
|
||||||
{
|
{
|
||||||
bool rc = false;
|
return false;
|
||||||
return rc;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool
|
bool
|
||||||
SpawningUploadClient::PutFile(const string& local, const string& remote, ftp_mode mode)
|
SpawningUploadClient::PutFile(const string& local, const string& remote,
|
||||||
|
ftp_mode mode)
|
||||||
{
|
{
|
||||||
bool rc = false;
|
return false;
|
||||||
return rc;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool
|
bool
|
||||||
SpawningUploadClient::GetFile(const string& remote, const string& local, ftp_mode mode)
|
SpawningUploadClient::GetFile(const string& remote, const string& local,
|
||||||
|
ftp_mode mode)
|
||||||
{
|
{
|
||||||
bool rc = false;
|
return false;
|
||||||
return rc;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -178,16 +188,14 @@ SpawningUploadClient::GetFile(const string& remote, const string& local, ftp_mod
|
|||||||
bool
|
bool
|
||||||
SpawningUploadClient::MoveFile(const string& oldPath, const string& newPath)
|
SpawningUploadClient::MoveFile(const string& oldPath, const string& newPath)
|
||||||
{
|
{
|
||||||
bool rc = false;
|
return false;
|
||||||
return rc;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool
|
bool
|
||||||
SpawningUploadClient::Chmod(const string& path, const string& mod)
|
SpawningUploadClient::Chmod(const string& path, const string& mod)
|
||||||
{
|
{
|
||||||
bool rc = false;
|
return false;
|
||||||
return rc;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -195,5 +203,3 @@ void
|
|||||||
SpawningUploadClient::SetPassive(bool on)
|
SpawningUploadClient::SetPassive(bool on)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,50 +1,63 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 1998-1999 Be, Inc. All Rights Reserved.
|
||||||
|
* Copyright 2003-2019 Haiku, Inc. All rights reserved.
|
||||||
|
* Distributed under the terms of the MIT License.
|
||||||
|
*/
|
||||||
#ifndef SPAWNING_UPLOAD_CLIENT_H
|
#ifndef SPAWNING_UPLOAD_CLIENT_H
|
||||||
#define SPAWNING_UPLOAD_CLIENT_H
|
#define SPAWNING_UPLOAD_CLIENT_H
|
||||||
|
|
||||||
#include "FileUploadClient.h"
|
#include "FileUploadClient.h"
|
||||||
|
|
||||||
#include <OS.h>
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string>
|
#include <string.h>
|
||||||
|
|
||||||
|
#include <OS.h>
|
||||||
|
#include <String.h>
|
||||||
|
|
||||||
|
|
||||||
class SpawningUploadClient : public FileUploadClient {
|
class SpawningUploadClient : public FileUploadClient {
|
||||||
public:
|
public:
|
||||||
SpawningUploadClient();
|
SpawningUploadClient();
|
||||||
virtual ~SpawningUploadClient();
|
virtual ~SpawningUploadClient();
|
||||||
|
|
||||||
virtual bool Connect(const string& server, const string& login,
|
virtual bool Connect(const string& server,
|
||||||
const string& passwd);
|
const string& login,
|
||||||
|
const string& passwd);
|
||||||
|
|
||||||
virtual bool PutFile(const string& local, const string& remote,
|
virtual bool PutFile(const string& local,
|
||||||
ftp_mode mode = binary_mode);
|
const string& remote,
|
||||||
|
ftp_mode mode = binary_mode);
|
||||||
|
|
||||||
virtual bool GetFile(const string& remote, const string& local,
|
virtual bool GetFile(const string& remote,
|
||||||
ftp_mode mode = binary_mode);
|
const string& local,
|
||||||
|
ftp_mode mode = binary_mode);
|
||||||
|
|
||||||
virtual bool MoveFile(const string& oldPath, const string& newPath);
|
virtual bool MoveFile(const string& oldPath,
|
||||||
virtual bool ChangeDir(const string& dir);
|
const string& newPath);
|
||||||
virtual bool PrintWorkingDir(string& dir);
|
virtual bool ChangeDir(const string& dir);
|
||||||
virtual bool ListDirContents(string& listing);
|
virtual bool PrintWorkingDir(string& dir);
|
||||||
virtual bool Chmod(const string& path, const string& mod);
|
virtual bool ListDirContents(string& listing);
|
||||||
|
virtual bool Chmod(const string& path, const string& mod);
|
||||||
|
|
||||||
virtual void SetPassive(bool on);
|
virtual void SetPassive(bool on);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
status_t SetCommandLine(const char *command);
|
status_t SetCommandLine(const char* command);
|
||||||
ssize_t SendCommand(const char *cmd);
|
ssize_t SendCommand(const char* cmd);
|
||||||
ssize_t ReadReply(BString *to);
|
ssize_t ReadReply(BString* to);
|
||||||
virtual status_t ParseReply();
|
virtual status_t ParseReply();
|
||||||
int getpty(char *pty, char *tty);
|
int getpty(char* pty, char* tty);
|
||||||
|
|
||||||
int InputPipe() const { return fPty; };
|
int InputPipe() const { return fPty; };
|
||||||
int OutputPipe() const { return fPty; };
|
int OutputPipe() const { return fPty; };
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool SpawnCommand();
|
bool SpawnCommand();
|
||||||
string fCommand;
|
|
||||||
pid_t fCommandPid;
|
private:
|
||||||
int fPty;
|
string fCommand;
|
||||||
|
pid_t fCommandPid;
|
||||||
|
int fPty;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // SPAWNING_UPLOAD_CLIENT_H
|
#endif // SPAWNING_UPLOAD_CLIENT_H
|
||||||
|
|||||||
@@ -1,19 +1,19 @@
|
|||||||
// Copyright (c) 1998-99, Be Incorporated, All Rights Reserved.
|
/*
|
||||||
// SMS
|
* Copyright 1998-1999 Be, Inc. All Rights Reserved.
|
||||||
// VideoConsumer.cpp
|
* Copyright 2003-2019 Haiku, Inc. All rights reserved.
|
||||||
|
* Distributed under the terms of the MIT License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
#include "FileUploadClient.h"
|
|
||||||
#include "FtpClient.h"
|
|
||||||
#include "SftpClient.h"
|
|
||||||
#include "VideoConsumer.h"
|
#include "VideoConsumer.h"
|
||||||
|
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <unistd.h>
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
#include <Application.h>
|
#include <Application.h>
|
||||||
|
#include <BitmapStream.h>
|
||||||
#include <Buffer.h>
|
#include <Buffer.h>
|
||||||
#include <BufferGroup.h>
|
#include <BufferGroup.h>
|
||||||
#include <Catalog.h>
|
#include <Catalog.h>
|
||||||
@@ -25,10 +25,15 @@
|
|||||||
#include <TimeSource.h>
|
#include <TimeSource.h>
|
||||||
#include <View.h>
|
#include <View.h>
|
||||||
|
|
||||||
|
#include "FileUploadClient.h"
|
||||||
|
#include "FtpClient.h"
|
||||||
|
#include "SftpClient.h"
|
||||||
|
|
||||||
|
|
||||||
#undef B_TRANSLATION_CONTEXT
|
#undef B_TRANSLATION_CONTEXT
|
||||||
#define B_TRANSLATION_CONTEXT "VideoConsumer.cpp"
|
#define B_TRANSLATION_CONTEXT "VideoConsumer.cpp"
|
||||||
|
|
||||||
|
|
||||||
#define M1 ((double)1000000.0)
|
#define M1 ((double)1000000.0)
|
||||||
#define JITTER 20000
|
#define JITTER 20000
|
||||||
|
|
||||||
@@ -38,7 +43,7 @@
|
|||||||
#define LOOP printf
|
#define LOOP printf
|
||||||
|
|
||||||
|
|
||||||
static status_t SetFileType(BFile* file, int32 translator, uint32 type);
|
static status_t SetFileType(BFile* file, int32 translator, uint32 type);
|
||||||
|
|
||||||
const media_raw_video_format vid_format = {29.97, 1, 0, 239,
|
const media_raw_video_format vid_format = {29.97, 1, 0, 239,
|
||||||
B_VIDEO_TOP_LEFT_RIGHT, 1, 1, {B_RGB16, 320, 240, 320 * 4, 0, 0}};
|
B_VIDEO_TOP_LEFT_RIGHT, 1, 1, {B_RGB16, 320, 240, 320 * 4, 0, 0}};
|
||||||
@@ -47,7 +52,8 @@ const media_raw_video_format vid_format = {29.97, 1, 0, 239,
|
|||||||
VideoConsumer::VideoConsumer(const char* name, BView* view,
|
VideoConsumer::VideoConsumer(const char* name, BView* view,
|
||||||
BStringView* statusLine,
|
BStringView* statusLine,
|
||||||
BMediaAddOn* addon, const uint32 internalId)
|
BMediaAddOn* addon, const uint32 internalId)
|
||||||
: BMediaNode(name),
|
:
|
||||||
|
BMediaNode(name),
|
||||||
BMediaEventLooper(),
|
BMediaEventLooper(),
|
||||||
BBufferConsumer(B_MEDIA_RAW_VIDEO),
|
BBufferConsumer(B_MEDIA_RAW_VIDEO),
|
||||||
fStatusLine(statusLine),
|
fStatusLine(statusLine),
|
||||||
@@ -75,7 +81,7 @@ VideoConsumer::VideoConsumer(const char* name, BView* view,
|
|||||||
|
|
||||||
for (uint32 j = 0; j < 3; j++) {
|
for (uint32 j = 0; j < 3; j++) {
|
||||||
fBitmap[j] = NULL;
|
fBitmap[j] = NULL;
|
||||||
fBufferMap[j] = 0;
|
fBufferMap[j] = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
strcpy(fFileNameText, "");
|
strcpy(fFileNameText, "");
|
||||||
@@ -99,7 +105,7 @@ VideoConsumer::~VideoConsumer()
|
|||||||
if (fWindow->Lock()) {
|
if (fWindow->Lock()) {
|
||||||
puts(B_TRANSLATE("Closing the window"));
|
puts(B_TRANSLATE("Closing the window"));
|
||||||
fWindow->Close();
|
fWindow->Close();
|
||||||
fWindow = 0;
|
fWindow = NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -115,7 +121,6 @@ VideoConsumer::~VideoConsumer()
|
|||||||
kill_thread(fFtpThread);
|
kill_thread(fFtpThread);
|
||||||
|
|
||||||
DeleteBuffers();
|
DeleteBuffers();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/********************************
|
/********************************
|
||||||
@@ -192,13 +197,15 @@ VideoConsumer::RequestCompleted(const media_request_info& info)
|
|||||||
switch (info.what) {
|
switch (info.what) {
|
||||||
case media_request_info::B_SET_OUTPUT_BUFFERS_FOR:
|
case media_request_info::B_SET_OUTPUT_BUFFERS_FOR:
|
||||||
if (info.status != B_OK)
|
if (info.status != B_OK)
|
||||||
ERROR("VideoConsumer::RequestCompleted: Not using our buffers!\n");
|
ERROR("VideoConsumer::RequestCompleted: "
|
||||||
|
"Not using our buffers!\n");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
ERROR("VideoConsumer::RequestCompleted: Invalid argument\n");
|
ERROR("VideoConsumer::RequestCompleted: Invalid argument\n");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -208,7 +215,6 @@ VideoConsumer::HandleMessage(int32 message, const void* data, size_t size)
|
|||||||
{
|
{
|
||||||
//FUNCTION("VideoConsumer::HandleMessage\n");
|
//FUNCTION("VideoConsumer::HandleMessage\n");
|
||||||
ftp_msg_info* info = (ftp_msg_info*)data;
|
ftp_msg_info* info = (ftp_msg_info*)data;
|
||||||
status_t status = B_OK;
|
|
||||||
|
|
||||||
switch (message) {
|
switch (message) {
|
||||||
case FTP_INFO:
|
case FTP_INFO:
|
||||||
@@ -224,8 +230,9 @@ VideoConsumer::HandleMessage(int32 message, const void* data, size_t size)
|
|||||||
strcpy(fPasswordText, info->passwordText);
|
strcpy(fPasswordText, info->passwordText);
|
||||||
strcpy(fDirectoryText, info->directoryText);
|
strcpy(fDirectoryText, info->directoryText);
|
||||||
// remove old user events
|
// remove old user events
|
||||||
EventQueue()->FlushEvents(TimeSource()->Now(), BTimedEventQueue::B_ALWAYS,
|
EventQueue()->FlushEvents(TimeSource()->Now(),
|
||||||
true, BTimedEventQueue::B_USER_EVENT);
|
BTimedEventQueue::B_ALWAYS, true,
|
||||||
|
BTimedEventQueue::B_USER_EVENT);
|
||||||
if (fRate != B_INFINITE_TIMEOUT) {
|
if (fRate != B_INFINITE_TIMEOUT) {
|
||||||
// if rate is not "Never," push an event
|
// if rate is not "Never," push an event
|
||||||
// to restart captures 5 seconds from now
|
// to restart captures 5 seconds from now
|
||||||
@@ -236,30 +243,31 @@ VideoConsumer::HandleMessage(int32 message, const void* data, size_t size)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return status;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
VideoConsumer::BufferReceived(BBuffer* buffer)
|
VideoConsumer::BufferReceived(BBuffer* buffer)
|
||||||
{
|
{
|
||||||
LOOP("VideoConsumer::Buffer #%" B_PRId32 " received, start_time %" B_PRIdBIGTIME
|
LOOP("VideoConsumer::Buffer #%" B_PRId32 " received, start_time %"
|
||||||
"\n", buffer->ID(), buffer->Header()->start_time);
|
B_PRIdBIGTIME "\n", buffer->ID(), buffer->Header()->start_time);
|
||||||
|
|
||||||
if (RunState() == B_STOPPED) {
|
if (RunState() == B_STOPPED) {
|
||||||
buffer->Recycle();
|
buffer->Recycle();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
media_timed_event event(buffer->Header()->start_time, BTimedEventQueue::B_HANDLE_BUFFER,
|
media_timed_event event(buffer->Header()->start_time,
|
||||||
buffer, BTimedEventQueue::B_RECYCLE_BUFFER);
|
BTimedEventQueue::B_HANDLE_BUFFER, buffer,
|
||||||
|
BTimedEventQueue::B_RECYCLE_BUFFER);
|
||||||
EventQueue()->AddEvent(event);
|
EventQueue()->AddEvent(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
VideoConsumer::ProducerDataStatus(const media_destination& forWhom, int32 status,
|
VideoConsumer::ProducerDataStatus(const media_destination& forWhom,
|
||||||
bigtime_t atMediaTime)
|
int32 status, bigtime_t atMediaTime)
|
||||||
{
|
{
|
||||||
FUNCTION("VideoConsumer::ProducerDataStatus\n");
|
FUNCTION("VideoConsumer::ProducerDataStatus\n");
|
||||||
|
|
||||||
@@ -292,8 +300,8 @@ VideoConsumer::CreateBuffers(const media_format& withFormat)
|
|||||||
}
|
}
|
||||||
// and attach the bitmaps to the buffer group
|
// and attach the bitmaps to the buffer group
|
||||||
for (uint32 j = 0; j < 3; j++) {
|
for (uint32 j = 0; j < 3; j++) {
|
||||||
fBitmap[j] = new BBitmap(BRect(0, 0, (xSize - 1), (ySize - 1)), colorspace,
|
fBitmap[j] = new BBitmap(BRect(0, 0, (xSize - 1), (ySize - 1)),
|
||||||
false, true);
|
colorspace, false, true);
|
||||||
if (fBitmap[j]->IsValid()) {
|
if (fBitmap[j]->IsValid()) {
|
||||||
buffer_clone_info info;
|
buffer_clone_info info;
|
||||||
if ((info.area = area_for(fBitmap[j]->Bits())) == B_ERROR)
|
if ((info.area = area_for(fBitmap[j]->Bits())) == B_ERROR)
|
||||||
@@ -304,11 +312,13 @@ VideoConsumer::CreateBuffers(const media_format& withFormat)
|
|||||||
info.buffer = 0;
|
info.buffer = 0;
|
||||||
|
|
||||||
if ((status = fBuffers->AddBuffer(info)) != B_OK) {
|
if ((status = fBuffers->AddBuffer(info)) != B_OK) {
|
||||||
ERROR("VideoConsumer::CreateBuffers - ERROR ADDING BUFFER TO GROUP\n");
|
ERROR("VideoConsumer::CreateBuffers - "
|
||||||
|
"ERROR ADDING BUFFER TO GROUP\n");
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
PROGRESS("VideoConsumer::CreateBuffers - SUCCESSFUL ADD BUFFER TO GROUP\n");
|
PROGRESS("VideoConsumer::CreateBuffers - "
|
||||||
|
"SUCCESSFUL ADD BUFFER TO GROUP\n");
|
||||||
} else {
|
} else {
|
||||||
ERROR("VideoConsumer::CreateBuffers - ERROR CREATING VIDEO RING "
|
ERROR("VideoConsumer::CreateBuffers - ERROR CREATING VIDEO RING "
|
||||||
"BUFFER: %08" B_PRIx32 "\n", status);
|
"BUFFER: %08" B_PRIx32 "\n", status);
|
||||||
@@ -320,19 +330,22 @@ VideoConsumer::CreateBuffers(const media_format& withFormat)
|
|||||||
for (int j = 0; j < 3; j++)
|
for (int j = 0; j < 3; j++)
|
||||||
buffList[j] = NULL;
|
buffList[j] = NULL;
|
||||||
|
|
||||||
if ((status = fBuffers->GetBufferList(3, buffList)) == B_OK)
|
status = fBuffers->GetBufferList(3, buffList);
|
||||||
|
if (status == B_OK)
|
||||||
for (int j = 0; j < 3; j++)
|
for (int j = 0; j < 3; j++)
|
||||||
if (buffList[j] != NULL) {
|
if (buffList[j] != NULL) {
|
||||||
fBufferMap[j] = buffList[j];
|
fBufferMap[j] = buffList[j];
|
||||||
PROGRESS(" j = %d buffer = %p\n", j, fBufferMap[j]);
|
PROGRESS(" j = %d buffer = %p\n", j, fBufferMap[j]);
|
||||||
} else {
|
} else {
|
||||||
ERROR("VideoConsumer::CreateBuffers ERROR MAPPING RING BUFFER\n");
|
ERROR("VideoConsumer::CreateBuffers "
|
||||||
|
"ERROR MAPPING RING BUFFER\n");
|
||||||
return B_ERROR;
|
return B_ERROR;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
ERROR("VideoConsumer::CreateBuffers ERROR IN GET BUFFER LIST\n");
|
ERROR("VideoConsumer::CreateBuffers ERROR IN GET BUFFER LIST\n");
|
||||||
|
|
||||||
fFtpBitmap = new BBitmap(BRect(0, 0, xSize - 1, ySize - 1), B_RGB32, false, false);
|
fFtpBitmap = new BBitmap(BRect(0, 0, xSize - 1, ySize - 1), B_RGB32, false,
|
||||||
|
false);
|
||||||
|
|
||||||
FUNCTION("VideoConsumer::CreateBuffers - EXIT\n");
|
FUNCTION("VideoConsumer::CreateBuffers - EXIT\n");
|
||||||
return status;
|
return status;
|
||||||
@@ -354,13 +367,15 @@ VideoConsumer::DeleteBuffers()
|
|||||||
fBitmap[j] = NULL;
|
fBitmap[j] = NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
FUNCTION("VideoConsumer::DeleteBuffers - EXIT\n");
|
FUNCTION("VideoConsumer::DeleteBuffers - EXIT\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
status_t
|
status_t
|
||||||
VideoConsumer::Connected(const media_source& producer, const media_destination& where,
|
VideoConsumer::Connected(const media_source& producer,
|
||||||
const media_format& withFormat, media_input* outInput)
|
const media_destination& where, const media_format& withFormat,
|
||||||
|
media_input* outInput)
|
||||||
{
|
{
|
||||||
FUNCTION("VideoConsumer::Connected\n");
|
FUNCTION("VideoConsumer::Connected\n");
|
||||||
|
|
||||||
@@ -374,7 +389,7 @@ VideoConsumer::Connected(const media_source& producer, const media_destination&
|
|||||||
int32 changeTag = 1;
|
int32 changeTag = 1;
|
||||||
if (CreateBuffers(withFormat) == B_OK)
|
if (CreateBuffers(withFormat) == B_OK)
|
||||||
BBufferConsumer::SetOutputBuffersFor(producer, fDestination,
|
BBufferConsumer::SetOutputBuffersFor(producer, fDestination,
|
||||||
fBuffers, (void *)&userData, &changeTag, true);
|
fBuffers, (void*)&userData, &changeTag, true);
|
||||||
else {
|
else {
|
||||||
ERROR("VideoConsumer::Connected - COULDN'T CREATE BUFFERS\n");
|
ERROR("VideoConsumer::Connected - COULDN'T CREATE BUFFERS\n");
|
||||||
return B_ERROR;
|
return B_ERROR;
|
||||||
@@ -388,7 +403,8 @@ VideoConsumer::Connected(const media_source& producer, const media_destination&
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
VideoConsumer::Disconnected(const media_source& producer, const media_destination& where)
|
VideoConsumer::Disconnected(const media_source& producer,
|
||||||
|
const media_destination& where)
|
||||||
{
|
{
|
||||||
FUNCTION("VideoConsumer::Disconnected\n");
|
FUNCTION("VideoConsumer::Disconnected\n");
|
||||||
|
|
||||||
@@ -425,12 +441,14 @@ VideoConsumer::AcceptFormat(const media_destination& dest, media_format* format)
|
|||||||
&& format->u.raw_video.display.format != B_RGB15
|
&& format->u.raw_video.display.format != B_RGB15
|
||||||
&& format->u.raw_video.display.format != B_GRAY8
|
&& format->u.raw_video.display.format != B_GRAY8
|
||||||
&&
|
&&
|
||||||
format->u.raw_video.display.format != media_raw_video_format::wildcard.display.format) {
|
format->u.raw_video.display.format
|
||||||
|
!= media_raw_video_format::wildcard.display.format) {
|
||||||
ERROR("AcceptFormat - not a format we know about!\n");
|
ERROR("AcceptFormat - not a format we know about!\n");
|
||||||
return B_MEDIA_BAD_FORMAT;
|
return B_MEDIA_BAD_FORMAT;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (format->u.raw_video.display.format == media_raw_video_format::wildcard.display.format) {
|
if (format->u.raw_video.display.format
|
||||||
|
== media_raw_video_format::wildcard.display.format) {
|
||||||
format->u.raw_video.display.format = B_RGB16;
|
format->u.raw_video.display.format = B_RGB16;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -456,11 +474,12 @@ VideoConsumer::GetNextInput(int32* cookie, media_input* outInput)
|
|||||||
sprintf(fIn.name, "Video Consumer");
|
sprintf(fIn.name, "Video Consumer");
|
||||||
*outInput = fIn;
|
*outInput = fIn;
|
||||||
(*cookie)++;
|
(*cookie)++;
|
||||||
|
|
||||||
return B_OK;
|
return B_OK;
|
||||||
} else {
|
|
||||||
ERROR("VideoConsumer::GetNextInput - - BAD INDEX\n");
|
|
||||||
return B_MEDIA_BAD_DESTINATION;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ERROR("VideoConsumer::GetNextInput - - BAD INDEX\n");
|
||||||
|
return B_MEDIA_BAD_DESTINATION;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -471,8 +490,8 @@ VideoConsumer::DisposeInputCookie(int32 /*cookie*/)
|
|||||||
|
|
||||||
|
|
||||||
status_t
|
status_t
|
||||||
VideoConsumer::GetLatencyFor(const media_destination& forWhom, bigtime_t* outLatency,
|
VideoConsumer::GetLatencyFor(const media_destination& forWhom,
|
||||||
media_node_id* out_timesource)
|
bigtime_t* outLatency, media_node_id* out_timesource)
|
||||||
{
|
{
|
||||||
FUNCTION("VideoConsumer::GetLatencyFor\n");
|
FUNCTION("VideoConsumer::GetLatencyFor\n");
|
||||||
|
|
||||||
@@ -486,8 +505,9 @@ VideoConsumer::GetLatencyFor(const media_destination& forWhom, bigtime_t* outLat
|
|||||||
|
|
||||||
|
|
||||||
status_t
|
status_t
|
||||||
VideoConsumer::FormatChanged(const media_source& producer, const media_destination& consumer,
|
VideoConsumer::FormatChanged(const media_source& producer,
|
||||||
int32 fromChangeCount, const media_format& format)
|
const media_destination& consumer, int32 fromChangeCount,
|
||||||
|
const media_format& format)
|
||||||
{
|
{
|
||||||
FUNCTION("VideoConsumer::FormatChanged\n");
|
FUNCTION("VideoConsumer::FormatChanged\n");
|
||||||
|
|
||||||
@@ -518,8 +538,9 @@ VideoConsumer::HandleEvent(const media_timed_event* event, bigtime_t lateness,
|
|||||||
|
|
||||||
case BTimedEventQueue::B_STOP:
|
case BTimedEventQueue::B_STOP:
|
||||||
PROGRESS("VideoConsumer::HandleEvent - STOP\n");
|
PROGRESS("VideoConsumer::HandleEvent - STOP\n");
|
||||||
EventQueue()->FlushEvents(event->event_time, BTimedEventQueue::B_ALWAYS,
|
EventQueue()->FlushEvents(event->event_time,
|
||||||
true, BTimedEventQueue::B_HANDLE_BUFFER);
|
BTimedEventQueue::B_ALWAYS, true,
|
||||||
|
BTimedEventQueue::B_HANDLE_BUFFER);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case BTimedEventQueue::B_USER_EVENT:
|
case BTimedEventQueue::B_USER_EVENT:
|
||||||
@@ -537,7 +558,7 @@ VideoConsumer::HandleEvent(const media_timed_event* event, bigtime_t lateness,
|
|||||||
case BTimedEventQueue::B_HANDLE_BUFFER:
|
case BTimedEventQueue::B_HANDLE_BUFFER:
|
||||||
{
|
{
|
||||||
LOOP("VideoConsumer::HandleEvent - HANDLE BUFFER\n");
|
LOOP("VideoConsumer::HandleEvent - HANDLE BUFFER\n");
|
||||||
buffer = (BBuffer *)event->pointer;
|
buffer = (BBuffer*)event->pointer;
|
||||||
if (RunState() == B_STARTED && fConnectionActive) {
|
if (RunState() == B_STARTED && fConnectionActive) {
|
||||||
// see if this is one of our buffers
|
// see if this is one of our buffers
|
||||||
uint32 index = 0;
|
uint32 index = 0;
|
||||||
@@ -555,26 +576,34 @@ VideoConsumer::HandleEvent(const media_timed_event* event, bigtime_t lateness,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (fFtpComplete && fTimeToFtp) {
|
if (fFtpComplete && fTimeToFtp) {
|
||||||
PROGRESS("VidConsumer::HandleEvent - SPAWNING FTP THREAD\n");
|
PROGRESS("VidConsumer::HandleEvent - "
|
||||||
|
"SPAWNING FTP THREAD\n");
|
||||||
fTimeToFtp = false;
|
fTimeToFtp = false;
|
||||||
fFtpComplete = false;
|
fFtpComplete = false;
|
||||||
memcpy(fFtpBitmap->Bits(), buffer->Data(), fFtpBitmap->BitsLength());
|
memcpy(fFtpBitmap->Bits(), buffer->Data(),
|
||||||
fFtpThread = spawn_thread(FtpRun, "Video Window Ftp", B_NORMAL_PRIORITY, this);
|
fFtpBitmap->BitsLength());
|
||||||
|
fFtpThread = spawn_thread(FtpRun, "Video Window Ftp",
|
||||||
|
B_NORMAL_PRIORITY, this);
|
||||||
resume_thread(fFtpThread);
|
resume_thread(fFtpThread);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((RunMode() == B_OFFLINE)
|
if ((RunMode() == B_OFFLINE)
|
||||||
|| ((TimeSource()->Now() > (buffer->Header()->start_time - JITTER))
|
|| ((TimeSource()->Now() >
|
||||||
&& (TimeSource()->Now() < (buffer->Header()->start_time + JITTER)))) {
|
(buffer->Header()->start_time - JITTER))
|
||||||
|
&& (TimeSource()->Now() <
|
||||||
|
(buffer->Header()->start_time + JITTER)))) {
|
||||||
if (!fOurBuffers)
|
if (!fOurBuffers)
|
||||||
// not our buffers, so we need to copy
|
// not our buffers, so we need to copy
|
||||||
memcpy(fBitmap[index]->Bits(), buffer->Data(), fBitmap[index]->BitsLength());
|
memcpy(fBitmap[index]->Bits(), buffer->Data(),
|
||||||
|
fBitmap[index]->BitsLength());
|
||||||
|
|
||||||
if (fWindow->Lock()) {
|
if (fWindow->Lock()) {
|
||||||
uint32 flags;
|
uint32 flags;
|
||||||
if ((fBitmap[index]->ColorSpace() == B_GRAY8) &&
|
if ((fBitmap[index]->ColorSpace() == B_GRAY8) &&
|
||||||
!bitmaps_support_space(fBitmap[index]->ColorSpace(), &flags)) {
|
!bitmaps_support_space(fBitmap[index]->ColorSpace(),
|
||||||
// handle mapping of GRAY8 until app server knows how
|
&flags)) {
|
||||||
|
// handle mapping of GRAY8 until app server
|
||||||
|
// knows how
|
||||||
uint32* start = (uint32*)fBitmap[index]->Bits();
|
uint32* start = (uint32*)fBitmap[index]->Bits();
|
||||||
int32 size = fBitmap[index]->BitsLength();
|
int32 size = fBitmap[index]->BitsLength();
|
||||||
uint32* end = start + size / 4;
|
uint32* end = start + size / 4;
|
||||||
@@ -607,7 +636,7 @@ VideoConsumer::FtpRun(void* data)
|
|||||||
{
|
{
|
||||||
FUNCTION("VideoConsumer::FtpRun\n");
|
FUNCTION("VideoConsumer::FtpRun\n");
|
||||||
|
|
||||||
((VideoConsumer *)data)->FtpThread();
|
((VideoConsumer*)data)->FtpThread();
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -620,7 +649,8 @@ VideoConsumer::FtpThread()
|
|||||||
FUNCTION("VideoConsumer::FtpThread\n");
|
FUNCTION("VideoConsumer::FtpThread\n");
|
||||||
if (fUploadClient == 2) {
|
if (fUploadClient == 2) {
|
||||||
// 64 + 64 = 128 max
|
// 64 + 64 = 128 max
|
||||||
snprintf(fullPath, B_PATH_NAME_LENGTH, "%s/%s", fDirectoryText, fFileNameText);
|
snprintf(fullPath, B_PATH_NAME_LENGTH, "%s/%s", fDirectoryText,
|
||||||
|
fFileNameText);
|
||||||
LocalSave(fullPath, fFtpBitmap);
|
LocalSave(fullPath, fFtpBitmap);
|
||||||
} else if (LocalSave(fFileNameText, fFtpBitmap) == B_OK)
|
} else if (LocalSave(fFileNameText, fFtpBitmap) == B_OK)
|
||||||
FtpSave(fFileNameText);
|
FtpSave(fFileNameText);
|
||||||
@@ -666,14 +696,16 @@ VideoConsumer::LocalSave(char* filename, BBitmap* bitmap)
|
|||||||
|
|
||||||
/* save a local copy of the image in the requested format */
|
/* save a local copy of the image in the requested format */
|
||||||
output = new BFile();
|
output = new BFile();
|
||||||
if (output->SetTo(filename, B_READ_WRITE | B_CREATE_FILE | B_ERASE_FILE) == B_NO_ERROR) {
|
if (output->SetTo(filename, B_READ_WRITE | B_CREATE_FILE | B_ERASE_FILE)
|
||||||
|
== B_NO_ERROR) {
|
||||||
BBitmapStream input(bitmap);
|
BBitmapStream input(bitmap);
|
||||||
status_t err = BTranslatorRoster::Default()->Translate(&input, NULL, NULL,
|
status_t err = BTranslatorRoster::Default()->Translate(&input, NULL,
|
||||||
output, fImageFormat);
|
NULL, output, fImageFormat);
|
||||||
if (err == B_OK) {
|
if (err == B_OK) {
|
||||||
err = SetFileType(output, fTranslator, fImageFormat);
|
err = SetFileType(output, fTranslator, fImageFormat);
|
||||||
if (err != B_OK)
|
if (err != B_OK)
|
||||||
UpdateFtpStatus(B_TRANSLATE("Error setting type of output file"));
|
UpdateFtpStatus(
|
||||||
|
B_TRANSLATE("Error setting type of output file"));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
UpdateFtpStatus(B_TRANSLATE("Error writing output file"));
|
UpdateFtpStatus(B_TRANSLATE("Error writing output file"));
|
||||||
@@ -681,18 +713,19 @@ VideoConsumer::LocalSave(char* filename, BBitmap* bitmap)
|
|||||||
input.DetachBitmap(&bitmap);
|
input.DetachBitmap(&bitmap);
|
||||||
output->Unset();
|
output->Unset();
|
||||||
delete output;
|
delete output;
|
||||||
|
|
||||||
return B_OK;
|
return B_OK;
|
||||||
} else {
|
|
||||||
UpdateFtpStatus(B_TRANSLATE("Error creating output file"));
|
|
||||||
return B_ERROR;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
UpdateFtpStatus(B_TRANSLATE("Error creating output file"));
|
||||||
|
return B_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
status_t
|
status_t
|
||||||
VideoConsumer::FtpSave(char* filename)
|
VideoConsumer::FtpSave(char* filename)
|
||||||
{
|
{
|
||||||
FileUploadClient *ftp;
|
FileUploadClient* ftp;
|
||||||
|
|
||||||
//XXX: make that cleaner
|
//XXX: make that cleaner
|
||||||
switch (fUploadClient) {
|
switch (fUploadClient) {
|
||||||
@@ -764,7 +797,7 @@ SetFileType(BFile* file, int32 translator, uint32 type)
|
|||||||
int32 count;
|
int32 count;
|
||||||
|
|
||||||
status_t err = BTranslatorRoster::Default()->GetOutputFormats(translator,
|
status_t err = BTranslatorRoster::Default()->GetOutputFormats(translator,
|
||||||
(const translation_format **)&formats, &count);
|
(const translation_format**)&formats, &count);
|
||||||
if (err < B_OK)
|
if (err < B_OK)
|
||||||
return err;
|
return err;
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
// Copyright (c) 1998-99, Be Incorporated, All Rights Reserved.
|
/*
|
||||||
// SMS
|
* Copyright 1998-1999 Be, Inc. All Rights Reserved.
|
||||||
/* VideoConsumer.h */
|
* Copyright 2003-2019 Haiku, Inc. All rights reserved.
|
||||||
|
* Distributed under the terms of the MIT License.
|
||||||
|
*/
|
||||||
#ifndef VIDEO_CONSUMER_H
|
#ifndef VIDEO_CONSUMER_H
|
||||||
#define VIDEO_CONSUMER_H
|
#define VIDEO_CONSUMER_H
|
||||||
|
|
||||||
@@ -10,7 +12,7 @@
|
|||||||
#include <MediaEventLooper.h>
|
#include <MediaEventLooper.h>
|
||||||
#include <MediaNode.h>
|
#include <MediaNode.h>
|
||||||
#include <TimedEventQueue.h>
|
#include <TimedEventQueue.h>
|
||||||
#include <TranslationKit.h>
|
#include <TranslatorRoster.h>
|
||||||
#include <View.h>
|
#include <View.h>
|
||||||
#include <Window.h>
|
#include <Window.h>
|
||||||
|
|
||||||
@@ -36,115 +38,123 @@ class BStringView;
|
|||||||
|
|
||||||
|
|
||||||
class VideoConsumer : public BMediaEventLooper, public BBufferConsumer {
|
class VideoConsumer : public BMediaEventLooper, public BBufferConsumer {
|
||||||
public:
|
public:
|
||||||
VideoConsumer(const char* name, BView* view, BStringView* statusLine,
|
VideoConsumer(const char* name, BView* view,
|
||||||
BMediaAddOn *addon, const uint32 internalId);
|
BStringView* statusLine, BMediaAddOn *addon,
|
||||||
~VideoConsumer();
|
const uint32 internalId);
|
||||||
|
~VideoConsumer();
|
||||||
|
|
||||||
/* BMediaNode */
|
/* BMediaNode */
|
||||||
public:
|
public:
|
||||||
virtual BMediaAddOn* AddOn(int32* cookie) const;
|
virtual BMediaAddOn* AddOn(int32* cookie) const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void Start(bigtime_t performanceTime);
|
virtual void Start(bigtime_t performanceTime);
|
||||||
virtual void Stop(bigtime_t performanceTime, bool immediate);
|
virtual void Stop(bigtime_t performanceTime, bool immediate);
|
||||||
virtual void Seek(bigtime_t mediaTime, bigtime_t performanceTime);
|
virtual void Seek(bigtime_t mediaTime,
|
||||||
virtual void TimeWarp(bigtime_t atRealTime,
|
bigtime_t performanceTime);
|
||||||
bigtime_t toPerformanceTime);
|
virtual void TimeWarp(bigtime_t atRealTime,
|
||||||
|
bigtime_t toPerformanceTime);
|
||||||
|
|
||||||
virtual void NodeRegistered();
|
virtual void NodeRegistered();
|
||||||
virtual status_t RequestCompleted(const media_request_info& info);
|
virtual status_t RequestCompleted(
|
||||||
|
const media_request_info& info);
|
||||||
|
|
||||||
virtual status_t HandleMessage(int32 message, const void* data,
|
virtual status_t HandleMessage(int32 message, const void* data,
|
||||||
size_t size);
|
size_t size);
|
||||||
|
|
||||||
virtual status_t DeleteHook(BMediaNode* node);
|
virtual status_t DeleteHook(BMediaNode* node);
|
||||||
|
|
||||||
/* BMediaEventLooper */
|
/* BMediaEventLooper */
|
||||||
protected:
|
protected:
|
||||||
virtual void HandleEvent(const media_timed_event* event,
|
virtual void HandleEvent(const media_timed_event* event,
|
||||||
bigtime_t lateness, bool realTimeEvent);
|
bigtime_t lateness, bool realTimeEvent);
|
||||||
|
|
||||||
/* BBufferConsumer */
|
/* BBufferConsumer */
|
||||||
public:
|
public:
|
||||||
virtual status_t AcceptFormat(const media_destination& dest,
|
virtual status_t AcceptFormat(const media_destination& dest,
|
||||||
media_format* format);
|
media_format* format);
|
||||||
|
|
||||||
virtual status_t GetNextInput(int32* cookie, media_input* outInput);
|
virtual status_t GetNextInput(int32* cookie,
|
||||||
|
media_input* outInput);
|
||||||
|
|
||||||
virtual void DisposeInputCookie(int32 cookie);
|
virtual void DisposeInputCookie(int32 cookie);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void BufferReceived(BBuffer* buffer);
|
virtual void BufferReceived(BBuffer* buffer);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
virtual void ProducerDataStatus(const media_destination &forWhom,
|
virtual void ProducerDataStatus(
|
||||||
int32 status, bigtime_t atMediaTime);
|
const media_destination &forWhom,
|
||||||
|
int32 status, bigtime_t atMediaTime);
|
||||||
|
|
||||||
virtual status_t GetLatencyFor(const media_destination& forWhom,
|
virtual status_t GetLatencyFor(const media_destination& forWhom,
|
||||||
bigtime_t* outLatency, media_node_id* outId);
|
bigtime_t* outLatency,
|
||||||
|
media_node_id* outId);
|
||||||
|
|
||||||
virtual status_t Connected(const media_source& producer,
|
virtual status_t Connected(const media_source& producer,
|
||||||
const media_destination& where, const media_format& withFormat,
|
const media_destination& where,
|
||||||
media_input* outInput);
|
const media_format& withFormat,
|
||||||
|
media_input* outInput);
|
||||||
|
|
||||||
virtual void Disconnected(const media_source& producer,
|
virtual void Disconnected(const media_source& producer,
|
||||||
const media_destination& where);
|
const media_destination& where);
|
||||||
|
|
||||||
virtual status_t FormatChanged(const media_source& producer,
|
virtual status_t FormatChanged(const media_source& producer,
|
||||||
const media_destination& consumer, int32 fromChangeCount,
|
const media_destination& consumer,
|
||||||
const media_format& format);
|
int32 fromChangeCount,
|
||||||
|
const media_format& format);
|
||||||
|
|
||||||
/* implementation */
|
/* implementation */
|
||||||
|
|
||||||
public:
|
public:
|
||||||
status_t CreateBuffers(const media_format& withFormat);
|
status_t CreateBuffers(const media_format& withFormat);
|
||||||
|
|
||||||
void DeleteBuffers();
|
void DeleteBuffers();
|
||||||
|
|
||||||
static status_t FtpRun(void* data);
|
static status_t FtpRun(void* data);
|
||||||
|
|
||||||
void FtpThread();
|
void FtpThread();
|
||||||
|
|
||||||
void UpdateFtpStatus(const char* status);
|
void UpdateFtpStatus(const char* status);
|
||||||
|
|
||||||
status_t LocalSave(char* filename, BBitmap* bitmap);
|
status_t LocalSave(char* filename, BBitmap* bitmap);
|
||||||
|
|
||||||
status_t FtpSave(char* filename);
|
status_t FtpSave(char* filename);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
BStringView* fStatusLine;
|
BStringView* fStatusLine;
|
||||||
int32 fInternalID;
|
int32 fInternalID;
|
||||||
BMediaAddOn* fAddOn;
|
BMediaAddOn* fAddOn;
|
||||||
|
|
||||||
thread_id fFtpThread;
|
thread_id fFtpThread;
|
||||||
|
|
||||||
bool fConnectionActive;
|
bool fConnectionActive;
|
||||||
media_input fIn;
|
media_input fIn;
|
||||||
media_destination fDestination;
|
media_destination fDestination;
|
||||||
bigtime_t fMyLatency;
|
bigtime_t fMyLatency;
|
||||||
|
|
||||||
BWindow* fWindow;
|
BWindow* fWindow;
|
||||||
BView* fView;
|
BView* fView;
|
||||||
BBitmap* fBitmap[3];
|
BBitmap* fBitmap[3];
|
||||||
bool fOurBuffers;
|
bool fOurBuffers;
|
||||||
BBufferGroup* fBuffers;
|
BBufferGroup* fBuffers;
|
||||||
BBuffer* fBufferMap[3];
|
BBuffer* fBufferMap[3];
|
||||||
|
|
||||||
BBitmap* fFtpBitmap;
|
BBitmap* fFtpBitmap;
|
||||||
volatile bool fTimeToFtp;
|
volatile bool fTimeToFtp;
|
||||||
volatile bool fFtpComplete;
|
volatile bool fFtpComplete;
|
||||||
|
|
||||||
bigtime_t fRate;
|
bigtime_t fRate;
|
||||||
uint32 fImageFormat;
|
uint32 fImageFormat;
|
||||||
int32 fTranslator;
|
int32 fTranslator;
|
||||||
int32 fUploadClient;
|
int32 fUploadClient;
|
||||||
bool fPassiveFtp;
|
bool fPassiveFtp;
|
||||||
char fFileNameText[64];
|
char fFileNameText[64];
|
||||||
char fServerText[64];
|
char fServerText[64];
|
||||||
char fLoginText[64];
|
char fLoginText[64];
|
||||||
char fPasswordText[64];
|
char fPasswordText[64];
|
||||||
char fDirectoryText[64];
|
char fDirectoryText[64];
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // VIDEO_CONSUMER_H
|
#endif // VIDEO_CONSUMER_H
|
||||||
|
|||||||
Reference in New Issue
Block a user