Coder Social home page Coder Social logo

xsystem's Introduction

xsystem

xsystem is a simple, yet elegant, cross-system c++ library.

xsystem include net http crypt etc. You can use it to build what you want extremely easily.

Installing xsystem

xsystem is available on Github: https://github.com/freetbash/xsystem

git clone https://github.com/freetbash/xsystem.git
and just include "xsystem.hpp"

Usage

// The SSL_ENABLE should be placed in the front fo "includes"
#define SSL_ENABLE 1 // 0
#include "xsystem.hpp"

net socket


server

#include "../xsystem.hpp"
using xsystem::net::Socket;
#include <iostream>
using std::cout;
using std::endl;

int main(){
  Socket::Init();
  
  Socket s(AF_INET, SOCK_STREAM, 0);
  s.Bind("192.168.0.103", 80);
  s.Listen(5);
  
  auto c = s.Accept();
  
  char buf[1024]="Hello!";
  c->Send(buf,1024,0);
  c->Recv(buf,1024,0);
  cout << buf << endl;
  
  Socket::Exit();
  return 0;
}

client

#include "../xsystem.hpp"
using xsystem::net::Socket;
#include <iostream>
using std::cout;
using std::endl;

int main(){
  Socket::Init();
  
  Socket c(AF_INET, SOCK_STREAM, 0);
  c.Connect("192.168.0.103", 3147);
  
  char buf[1024]="Hello!";
  c.Send(buf,1024,0);
  c.Recv(buf,1024,0);
  cout << buf << endl;

  Socket::Exit();
  return 0;
}

ssl server


#define SSL_ENABLE 1
#include "../xsystem.hpp"
using xsystem::net::Socket;
#include <iostream>
using std::cout;
using std::endl;

int main() {
	Socket::Init();

	Socket s(AF_INET, SOCK_STREAM, 0);
	s.Bind("192.168.0.103", 80);
	s.Listen(5);

	auto c = s.SSL_Accept();

	char buf[1024] = "Hello!";
	c->SSL_Send(buf, 1024);
	c->SSL_Recv(buf, 1024);
	cout << buf << endl;

	Socket::Exit();
	return 0;
}

ssl client


#define SSL_ENABLE 1
#include "../xsystem.hpp"
using xsystem::net::Socket;
#include <iostream>
using std::cout;
using std::endl;

int main(){
  Socket::Init();
  
  Socket c(AF_INET, SOCK_STREAM, 0);
  c.SSL_Connect("192.168.0.103", 3147);
  
  char buf[1024]="Hello!";
  c.SSL_Send(buf,1024);
  c.SSL_Recv(buf,1024);
  cout << buf << endl;

  Socket::Exit();
  return 0;
}

net http


#include "../xsystem.hpp"
using namespace xsystem::net::http;

#include <iostream>
using std::cout;
using std::endl;


int main() {
	HttpInit();
	Request req("https://www.baidu.com");
	cout << req.domain << endl;
	cout << req.port << endl;
	cout << req.ip << endl;

	auto r = req.Get();
	cout << r->status_code << endl
		<< r->status << endl
		<< r->headers["Server"] << endl
		<< r->headers["Content-Length"] << endl
		<< r->data << endl
		 << r->text << endl;
	HttpExit();
	return 0;
}

crypt


#include "../xsystem.hpp"
using xsystem::crypt::Base64;
using xsystem::crypt::hash::sha256;
using xsystem::crypt::hash::Md5;

#include <iostream>
using std::cout;
using std::endl;

int main() {
	string text = "FreetBash";
	// base64
	string result = Base64::Encode((unsigned char *)(text.c_str()), text.length());
	cout << result << endl;
	int outlen;
	result = Base64::Decode(result.c_str(), result.size(), &outlen);
	cout << result << endl;
	// sha256
	result = sha256((unsigned char *)text.c_str(), text.size());
	cout << result<< endl;
	// md5
	result = Md5::Encode((unsigned char *)text.c_str(), text.size());
	cout << result << endl;
	// md5 file
	result = Md5::FileEncode("server.exe");
	cout << result << endl;
}

os


#include "../xsystem.hpp"
using namespace xsystem::os;

#include <iostream>
using std::cout;
using std::endl;

int main() {
	// SYSTEM_PATH_DELIM
	cout << "SYSTEM_PATH_DELIM" << endl;
	cout << SYSTEM_PATH_DELIM << endl;

	// TEST GETENV
	cout << GetEnv("PAsTH") << endl;

	// GetCwd
	string cwd = GetCwd();
	cout << cwd << endl;

	// Chdir
	int ret = Chdir("..");// fuck
	cout << GetCwd() << endl;
	ret = Chdir(cwd);

	// FileExist
	cout << FileExist("testproxyhttp.exe") << endl;
	cout << FileExist("freet.bash") << endl;

	// DirExist
	cout << DirExist("..") << endl;
	cout << DirExist("asd") << endl;
	cout << "-------------------" << endl;

	// Mkdir
	cout << Mkdir("asd") << endl;
	cout << DirExist("asd") << endl;
	cout << Rmdir("asd") << endl;
	cout << DirExist("asd") << endl;

	// Rmove
	cout << FileExist("test111111.txt") << endl;
	cout << Remove("test111111.txt") << endl;

	// ListDir

	for(auto c : ListDir(".") ){
		cout << c << endl;
	}


	return 0;
}

At the end

Hope you can fork this repo to assist it.

xsystem's People

Contributors

freetbash avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.