Skip to content

Commit

Permalink
Initial import
Browse files Browse the repository at this point in the history
  • Loading branch information
hu55a1n1 committed Oct 19, 2016
0 parents commit d9ae276
Show file tree
Hide file tree
Showing 72 changed files with 683,297 additions and 0 deletions.
9 changes: 9 additions & 0 deletions .gitignore
@@ -0,0 +1,9 @@
*.log
*.o
*.jar
*.bak
tags
tmp
wsdl
skeleton
ipconvif
25 changes: 25 additions & 0 deletions COMPILE
@@ -0,0 +1,25 @@
For New Compiles:
=================

# Reboot first! And wait for large processes to complete!
# Add swap file
free
dd if=/dev/zero of=/var/swap.img bs=1024k count=3000
mkswap /var/swap.img
swapon /var/swap.img

# Free RAM
# Flush file system buffers by executing
sync;

# free page cache
echo 1 > /proc/sys/vm/drop_caches;

# free dentries and inodes
echo 2 > /proc/sys/vm/drop_caches

# free page cache, dentries and inodes
echo 3 > /proc/sys/vm/drop_caches

# Compile
make
49 changes: 49 additions & 0 deletions ErrorLog.h
@@ -0,0 +1,49 @@
#include<stdio.h>
#include<string.h>
#include<time.h>

#define MAX_MSG_LEN 1024

typedef unsigned int uint;

void processEventLog(char *fileName, uint lineNo, FILE *fp, const char *argList, ...){
char sLogParamString[MAX_MSG_LEN];
memset(sLogParamString,0x00,MAX_MSG_LEN);
char sLogBuffer[MAX_MSG_LEN];
memset(sLogBuffer,0x00,MAX_MSG_LEN);
va_list vErrorList;
uint iStrLen;

time_t lTime;
struct tm tm;
time(&lTime);
localtime_r(&lTime, &tm);

tm.tm_mon += 1;
tm.tm_year += 1900;


strcpy(sLogParamString,"[%4d-%02d-%02d %02d:%02d:%02d] [%s] [%d] {");
iStrLen = sprintf(sLogBuffer,
sLogParamString,
tm.tm_year,
tm.tm_mon,
tm.tm_mday,
tm.tm_hour,
tm.tm_min,
tm.tm_sec,
fileName,
lineNo
);

va_start(vErrorList, argList);
iStrLen += vsprintf((sLogBuffer+iStrLen),argList,vErrorList);
va_end(vErrorList);
iStrLen += sprintf(sLogBuffer+iStrLen,"}");
sLogBuffer[iStrLen]='\n';
sLogBuffer[iStrLen+1]=NULL;

fprintf(fp, sLogBuffer);
fflush(fp);
}

25 changes: 25 additions & 0 deletions Makefile
@@ -0,0 +1,25 @@
CC = g++
CPPFLAG = -Wall -g -w -fPIC -DWITH_NONAMESPACES -fno-use-cxa-atexit -fexceptions -DWITH_DOM -DWITH_OPENSSL -std=c++0x -static-libstdc++

BASE_DIR=.
SOURCE=$(BASE_DIR)

INCLUDE +=-I$(SOURCE)/include -I$(BASE_DIR) -I/usr/include/x86_64-linux-gnu
LIB= -lssl -lcrypto -lcurl
PROXYSOURCE=$(BASE_DIR)/proxycpp
ProxyOBJ=$(PROXYSOURCE)/soapDeviceBindingProxy.o $(PROXYSOURCE)/soapMediaBindingProxy.o $(PROXYSOURCE)/soapPTZBindingProxy.o \
$(PROXYSOURCE)/soapPullPointSubscriptionBindingProxy.o $(PROXYSOURCE)/soapRemoteDiscoveryBindingProxy.o
PluginSOURCE=$(BASE_DIR)/plugin
PluginOBJ=$(PluginSOURCE)/wsaapi.o $(PluginSOURCE)/wsseapi.o $(PluginSOURCE)/threads.o $(PluginSOURCE)/duration.o \
$(PluginSOURCE)/smdevp.o $(PluginSOURCE)/mecevp.o $(PluginSOURCE)/dom.o
SRC= $(SOURCE)/stdsoap2.o $(SOURCE)/soapC.o $(SOURCE)/soapClient.o $(SOURCE)/Media.o $(SOURCE)/Snapshot.o $(SOURCE)/main.o $(PluginOBJ) $(ProxyOBJ)
OBJECTS = $(patsubst %.cpp,%.o,$(SRC))
TARGET=ipconvif
all: $(TARGET)
$(TARGET):$(OBJECTS)
$(CC) $(CPPFLAG) $(OBJECTS) $(INCLUDE) $(LIB) -o $(TARGET)
$(OBJECTS):%.o : %.cpp
$(CC) -c $(CPPFLAG) $(INCLUDE) $< -o $@
clean:
rm -rf $(OBJECTS)

45 changes: 45 additions & 0 deletions Media.cpp
@@ -0,0 +1,45 @@
#include <stdarg.h> // For va_start, etc.
#include <memory> // For std::unique_ptr
#include <ctime>
#include <cstring> // For strcpy
#include <sstream> // For stringstream
#include "Media.hpp"

Media::Media() {
_timeCreated = Media::formattedTimeStamp();
}

std::string Media::getTimeCreated(void){
return _timeCreated;
}

std::string Media::string_format(const std::string fmt_str, ...) {
int final_n, n = ((int)fmt_str.size()) * 2; /* Reserve two times as much as the length of the fmt_str */
std::string str;
std::unique_ptr<char[]> formatted;
va_list ap;
while(1) {
formatted.reset(new char[n]); /* Wrap the plain char array into the unique_ptr */
std::strcpy(&formatted[0], fmt_str.c_str());
va_start(ap, fmt_str);
final_n = vsnprintf(&formatted[0], n, fmt_str.c_str(), ap);
va_end(ap);
if (final_n < 0 || final_n >= n)
n += abs(final_n - n + 1);
else
break;
}
return std::string(formatted.get());
}

std::string Media::formattedTimeStamp(void) {
std::stringstream timeStampString;
char timeBuf [80];

std::time_t result = std::time(nullptr);
struct tm* now = std::localtime( & result );
std::strftime(timeBuf,80,"%Y-%m-%d-%H-%M-%S",now);
timeStampString << timeBuf;
return timeStampString.str();
}

26 changes: 26 additions & 0 deletions Media.hpp
@@ -0,0 +1,26 @@
// Base class for Snapshot and Stream
class Media {

public:
// Overloaded in derived classes
Media();
// virtual ~Media();

// Returns formatted curl command for downloading snapshot
virtual std::string getDownloadUri(const std::string mediaUri) = 0;

// Returns formatted curl command for uploading snapshot
virtual std::string getUploadUri(const std::string ftpIP, const std::string ftpUser, const std::string ftpPwd) = 0;

// Public getters exposing private NSVs
std::string getTimeCreated(void);

protected:
// Helper methods for subclasses
static std::string string_format(const std::string fmt_str, ...);
static std::string formattedTimeStamp(void);

private:
std::string _timeCreated;

};
84 changes: 84 additions & 0 deletions Snapshot.cpp
@@ -0,0 +1,84 @@
#include <stdarg.h> // For va_start, etc.
#include <memory> // For std::unique_ptr
#include <ctime>
#include <cstring> // For strcpy
#include <sstream> // For stringstream
#include <sys/stat.h>
#include "Snapshot.hpp"


Snapshot::Snapshot(std::string path, std::string name)
: Media(){ // Call base class constructor
// Create a name for the snapshot
this->_snapshotPath = path;
this->_snapshotName = name;
}

Snapshot::~Snapshot(void){
// Delete the snapshot file from disk.
this->deleteFromDisk();

}

std::string Snapshot::getDownloadUri(const std::string snapshotUri){
return Media::string_format("curl --create-dirs -o %s %s", this->_snapshotName.c_str(), snapshotUri.c_str());
}

/*
* Get the FTP shell cmd for uploading this snapshot to the FTP server.
*/
std::string Snapshot::getUploadUri(const std::string ftpIP, const std::string ftpUser, const std::string ftpPwd){
return Media::string_format("curl -C - --ftp-create-dirs -u %s:%s -T %s/%s ftp://%s/",
ftpUser.c_str(),
ftpPwd.c_str(),
this->_snapshotPath.c_str(),
this->_snapshotName.c_str(),
ftpIP.c_str());
}

size_t Snapshot::saveLocally(void *ptr, size_t size, size_t nmemb, FILE *stream) {
size_t written;
written = fwrite(ptr, size, nmemb, stream);
return written;
}

void Snapshot::deleteFromDisk(void) {
std::string deleteCmd = Media::string_format("rm %s/%s", this->_snapshotPath.c_str(), this->_snapshotName.c_str());
system(deleteCmd.c_str());
}

CURLcode Snapshot::download(const std::string downloadUri) {
CURL *curl;
FILE *fp;
CURLcode res;
char const *url = downloadUri.c_str();
char outfilename[FILENAME_MAX];
std::strcpy(outfilename, Media::string_format("%s/%s", this->_snapshotPath.c_str(), this->_snapshotName.c_str()).c_str());

char error[CURL_ERROR_SIZE] = "";
int timeoutSeconds = 10;
curl = curl_easy_init();
if (curl) {
struct stat st = {0};
if (stat(this->_snapshotPath.c_str(), &st) == -1) {
mkdir(this->_snapshotPath.c_str(), 0700);
}

fp = fopen(outfilename,"wb");
curl_easy_setopt(curl, CURLOPT_URL, url);
curl_easy_setopt(curl, CURLOPT_ERRORBUFFER , error);
curl_easy_setopt(curl, CURLOPT_TIMEOUT , timeoutSeconds);
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, Snapshot::saveLocally);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, fp);
res = curl_easy_perform(curl);
if(res) {
printf("Error: %s\n", error);
}
curl_easy_cleanup(curl);
fclose(fp);
}
// else {
// return -1;
// }
return res;
}
19 changes: 19 additions & 0 deletions Snapshot.hpp
@@ -0,0 +1,19 @@
#include "Media.hpp"
#include <curl/curl.h>
// #include <curl/types.h>
#include <curl/easy.h>

class Snapshot: public Media {
public:
Snapshot(std::string path, std::string name);
~Snapshot(void);
std::string getDownloadUri(const std::string snapshotUri);
std::string getUploadUri(const std::string ftpIP, const std::string ftpUser, const std::string ftpPwd);
CURLcode download(const std::string downloadUri);

private:
std::string _snapshotPath;
std::string _snapshotName;
static size_t saveLocally(void *ptr, size_t size, size_t nmemb, FILE *stream);
void deleteFromDisk(void);
};

0 comments on commit d9ae276

Please sign in to comment.