Commit a7b2d167 authored by jan.koester's avatar jan.koester
Browse files

removed not planned folder

parent 2d994929
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -2,3 +2,4 @@ build/
/.vs
/out/install/x64-Debug
/out/install/x64-Release
/out/
−207 KiB

File deleted.

+0 −152
Original line number Diff line number Diff line
/*******************************************************************************
 * Copyright (c) 2014, Jan Koester jan.koester@gmx.net
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 * Redistributions of source code must retain the above copyright
 *      notice, this list of conditions and the following disclaimer.
 * Redistributions in binary form must reproduce the above copyright
 *      notice, this list of conditions and the following disclaimer in the
 *      documentation and/or other materials provided with the distribution.
 * Neither the name of the <organization> nor the
 *      names of its contributors may be used to endorse or promote products
 *      derived from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *******************************************************************************/

#include <stdlib.h>
#include <string.h>

#pragma once 

namespace netplus {
    namespace base64 {
        /* aaaack but it's fast and const should make it shared text page. */
        static const unsigned char pr2six[256] = {
            /* ASCII table */
            64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
            64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
            64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 62, 64, 64, 64, 63,
            52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 64, 64, 64, 64, 64, 64,
            64,  0,  1,  2,  3,  4,  5,  6,  7,  8,  9, 10, 11, 12, 13, 14,
            15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 64, 64, 64, 64, 64,
            64, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
            41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 64, 64, 64, 64, 64,
            64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
            64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
            64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
            64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
            64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
            64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
            64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
            64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64
        };

        static const char basis_64[] =
            "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";

        inline size_t Decodelen(const char* bufcoded) {
            size_t nbytesdecoded;
            const unsigned char* bufin;
            int nprbytes;

            bufin = (const unsigned char*)bufcoded;
            while (pr2six[*(bufin++)] <= 63);

            nprbytes = (bufin - (const unsigned char*)bufcoded) - 1;
            nbytesdecoded = ((nprbytes + 3) / 4) * 3;

            return nbytesdecoded + 1;
        }

        inline size_t Decode(char* bufplain, const char* bufcoded) {
            size_t nbytesdecoded;
            const unsigned char* bufin;
            unsigned char* bufout;
            int nprbytes;

            bufin = (const unsigned char*)bufcoded;
            while (pr2six[*(bufin++)] <= 63);
            nprbytes = (bufin - (const unsigned char*)bufcoded) - 1;
            nbytesdecoded = ((nprbytes + 3) / 4) * 3;

            bufout = (unsigned char*)bufplain;
            bufin = (const unsigned char*)bufcoded;

            while (nprbytes > 4) {
                *(bufout++) =
                    (unsigned char)(pr2six[*bufin] << 2 | pr2six[bufin[1]] >> 4);
                *(bufout++) =
                    (unsigned char)(pr2six[bufin[1]] << 4 | pr2six[bufin[2]] >> 2);
                *(bufout++) =
                    (unsigned char)(pr2six[bufin[2]] << 6 | pr2six[bufin[3]]);
                bufin += 4;
                nprbytes -= 4;
            }

            /* Note: (nprbytes == 1) would be an error, so just ingore that case */
            if (nprbytes > 1) {
                *(bufout++) =
                    (unsigned char)(pr2six[*bufin] << 2 | pr2six[bufin[1]] >> 4);
            }
            if (nprbytes > 2) {
                *(bufout++) =
                    (unsigned char)(pr2six[bufin[1]] << 4 | pr2six[bufin[2]] >> 2);
            }
            if (nprbytes > 3) {
                *(bufout++) =
                    (unsigned char)(pr2six[bufin[2]] << 6 | pr2six[bufin[3]]);
            }

            *(bufout++) = '\0';
            nbytesdecoded -= (4 - nprbytes) & 3;
            return nbytesdecoded;
        }

        inline size_t Encodelen(size_t len) {
            return ((len + 2) / 3 * 4) + 1;
        }

        size_t inline Encode(char* encoded, const char* string, size_t len) {
            size_t i = 0;
            char* p;

            p = encoded;
            for (i = 0; i < len - 2; i += 3) {
                *p++ = basis_64[(string[i] >> 2) & 0x3F];
                *p++ = basis_64[((string[i] & 0x3) << 4) |
                    ((size_t)(string[i + 1] & 0xF0) >> 4)];
                *p++ = basis_64[((string[i + 1] & 0xF) << 2) |
                    ((size_t)(string[i + 2] & 0xC0) >> 6)];
                *p++ = basis_64[string[i + 2] & 0x3F];
            }
            if (i < len) {
                *p++ = basis_64[(string[i] >> 2) & 0x3F];
                if (i == (len - 1)) {
                    *p++ = basis_64[((string[i] & 0x3) << 4)];
                    *p++ = '=';
                }
                else {
                    *p++ = basis_64[((string[i] & 0x3) << 4) |
                        ((size_t)(string[i + 1] & 0xF0) >> 4)];
                    *p++ = basis_64[((string[i + 1] & 0xF) << 2)];
                }
                *p++ = '=';
            }

            *p++ = '\0';
            return p - encoded;
        }
    };
};
 No newline at end of file
+0 −2
Original line number Diff line number Diff line
#define Windows
#define ARCH_AMD64
+0 −161
Original line number Diff line number Diff line
/*******************************************************************************
 * Copyright (c) 2014, Jan Koester jan.koester@gmx.net
 * All rights reserved.
 * 
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 * Redistributions of source code must retain the above copyright
 *      notice, this list of conditions and the following disclaimer.
 * Redistributions in binary form must reproduce the above copyright
 *      notice, this list of conditions and the following disclaimer in the
 *      documentation and/or other materials provided with the distribution.
 * Neither the name of the <organization> nor the
 *      names of its contributors may be used to endorse or promote products
 *      derived from this software without specific prior written permission.
 * 
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *******************************************************************************/

#include <vector>
#include <memory>
#include <atomic>
#include <limits>
#include <type_traits>

#include <cstddef>

#pragma once

namespace netplus {
        class eventapi;
        class pollapi;

        template <class T>
        class condataAlloc {
        public:
            // type definitions
            typedef T        value_type;
            typedef T*       pointer;
            typedef const T* const_pointer;
            typedef T&       reference;
            typedef const T& const_reference;
            typedef std::size_t    size_type;
            typedef std::ptrdiff_t difference_type;

            // rebind allocator to type U
            template <class U>
            struct rebind {
                typedef condataAlloc<U> other;
            };

            // return address of values
            pointer address (reference value) const {
                return &value;
            }
            const_pointer address (const_reference value) const {
                return &value;
            }

            /* constructors and destructor
             * - nothing to do because the allocator has no state
             */
            condataAlloc() throw() {
            }
            condataAlloc(const condataAlloc&) throw() {
            }
            template <class U>
            condataAlloc (const condataAlloc<U>&) throw() {
            }
            ~condataAlloc() throw() {
            }

            // return maximum number of elements that can be allocated
            size_type max_size () const throw() {
                return (std::numeric_limits<std::size_t>::max)() / sizeof(T);
            }

            // allocate but don't initialize num elements of type T
            pointer allocate (size_type num, const void* = 0) {
                pointer ret = (pointer)(::operator new(num*sizeof(T)));
                return ret;
            }

            // initialize elements of allocated storage p with value value
            void construct (pointer p, const T& value) {
                new((void*)p)T(value);
            }

            // destroy elements of initialized storage p
            void destroy (pointer p) {
                p->~T();
            }

            // deallocate storage p of deleted elements
            void deallocate (pointer p, size_type num) {
                ::operator delete((void*)p);
            }
        };

        // return that all specializations of this allocator are interchangeable
        template <class T1, class T2>
        bool operator== (const condataAlloc<T1>&,
                         const condataAlloc<T2>&) throw() {
                             return true;
        }
        template <class T1, class T2>
        bool operator!= (const condataAlloc<T1>&,
                         const condataAlloc<T2>&) throw() {
                             return false;
        }

        template <typename T>
        class condata;

        template <> class condata<char> : public std::vector<char,condataAlloc<char>>{
        public:
            condata();
            condata(const condata<char> &src);
            condata(const std::vector<char> &src);
            void        resize(size_t size_c);
            void        append(const char *data,size_t datalen);
            size_t      search(const char *word);
            size_t      search(const char *word,size_t pos);
            void        push_back(char a);
            size_t      pos;
            bool        empty();
        };

        class con {
        public:
            
            con(eventapi *event);
            virtual ~con();

            /*clientsocket*/
            socket *csock;

            /*event stauts*/
            int state;

            /*connection Data*/
            condata<char> RecvData;
            condata<char> SendData;

        protected:
            con();
            int lasteventime;
        private:
            eventapi         *_eventapi;
            pollapi          *_pollapi;
            friend class poll;
        };
};
Loading