npcolony 1.2.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- npcolony-1.2.1/PKG-INFO +112 -0
- npcolony-1.2.1/README.md +80 -0
- npcolony-1.2.1/setup.cfg +4 -0
- npcolony-1.2.1/setup.py +143 -0
- npcolony-1.2.1/src/colony_npapi/encoding/base_64.c +346 -0
- npcolony-1.2.1/src/colony_npapi/plugin/base.c +579 -0
- npcolony-1.2.1/src/colony_npapi/plugin/python.c +298 -0
- npcolony-1.2.1/src/colony_npapi/plugin/util.c +50 -0
- npcolony-1.2.1/src/colony_npapi/print/print_unix.c +200 -0
- npcolony-1.2.1/src/colony_npapi/print/print_win32.c +700 -0
- npcolony-1.2.1/src/colony_npapi/stdafx.c +33 -0
- npcolony-1.2.1/src/colony_npapi/system/gui_unix.c +42 -0
- npcolony-1.2.1/src/colony_npapi/system/gui_win32.c +71 -0
- npcolony-1.2.1/src/python/npcolony.egg-info/PKG-INFO +112 -0
- npcolony-1.2.1/src/python/npcolony.egg-info/SOURCES.txt +19 -0
- npcolony-1.2.1/src/python/npcolony.egg-info/dependency_links.txt +1 -0
- npcolony-1.2.1/src/python/npcolony.egg-info/not-zip-safe +1 -0
- npcolony-1.2.1/src/python/npcolony.egg-info/top_level.txt +2 -0
- npcolony-1.2.1/src/python/npcolony_py/__init__.py +2 -0
- npcolony-1.2.1/src/python/npcolony_py/test/__init__.py +2 -0
- npcolony-1.2.1/src/python/npcolony_py/test/global.py +14 -0
npcolony-1.2.1/PKG-INFO
ADDED
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: npcolony
|
|
3
|
+
Version: 1.2.1
|
|
4
|
+
Summary: Colony Framework
|
|
5
|
+
Home-page: http://colony_npapi.hive.pt
|
|
6
|
+
Author: Hive Solutions Lda.
|
|
7
|
+
Author-email: development@hive.pt
|
|
8
|
+
License: Apache License, Version 2.0
|
|
9
|
+
Description: # [Colony Gateway (NPAPI Plugin)](http://getcolony.com)
|
|
10
|
+
|
|
11
|
+
NPAPI-based plugin that provides a series of native features like:
|
|
12
|
+
|
|
13
|
+
* Printing using direct access to the printing infra-structure of the operative system
|
|
14
|
+
* Creation of native-based GUI elements
|
|
15
|
+
|
|
16
|
+
The current implementation supports only x86/x64 architectures and Windows, Linux, and Mac OS X.
|
|
17
|
+
|
|
18
|
+
## Building
|
|
19
|
+
|
|
20
|
+
To build both the CRX (Google Chrome) and the XPI (Mozilla Firefox) files for the plugin
|
|
21
|
+
one should use the scripts created for such effect under the [scripts](scripts) directory. The
|
|
22
|
+
automated process assumes the Windows build process using the Visual Studio IDE.
|
|
23
|
+
|
|
24
|
+
### Windows
|
|
25
|
+
|
|
26
|
+
Use Visual Studio 2008 Express for compilation with no additional dependencies. The build process should
|
|
27
|
+
create the plugin files in the output.
|
|
28
|
+
|
|
29
|
+
### Mac OS X
|
|
30
|
+
|
|
31
|
+
Download the [Gecko SDK 1.9 32 bit](https://developer.mozilla.org/en-US/docs/Gecko_SDK) from the official
|
|
32
|
+
website.
|
|
33
|
+
|
|
34
|
+
Use the `/Library/Internet Plug-Ins/` directory to test the plugin while the proper extension package file
|
|
35
|
+
is not created. Remember to rename the `*.bundle` package into an `*.plugin` based package.
|
|
36
|
+
|
|
37
|
+
### Linux
|
|
38
|
+
|
|
39
|
+
Use the `/usr/lib/mozilla/plugins/` directory to test the `*.so` based plugin file for development purposes.
|
|
40
|
+
[Mozilla Firefox](http://www.mozilla.org) should be the primary browser for the debugging of the NPAPI-based plugin.
|
|
41
|
+
|
|
42
|
+
### Python
|
|
43
|
+
|
|
44
|
+
It's also possible to build a Python module that exports the functionality in the NPAPI Plugin for
|
|
45
|
+
running the python script as `python setup.py install` under an UNIX-based machine.
|
|
46
|
+
|
|
47
|
+
## Packaging
|
|
48
|
+
|
|
49
|
+
### Google Chrome
|
|
50
|
+
|
|
51
|
+
Create a package file containing references to the complete set of plugin files for the various
|
|
52
|
+
platforms as defined in the `src/colony_npapi/descriptors/manifest_u.json` file.
|
|
53
|
+
|
|
54
|
+
```javascript
|
|
55
|
+
"plugins" : [{
|
|
56
|
+
"path" : "npcolony.dll",
|
|
57
|
+
"public" : true
|
|
58
|
+
}, {
|
|
59
|
+
"path" : "libnpcolony.so",
|
|
60
|
+
"public" : true
|
|
61
|
+
}, {
|
|
62
|
+
"path" : "npcolony.plugin",
|
|
63
|
+
"public" : true
|
|
64
|
+
}]
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
Copy the proper files (`npcolony.dll`, `libnpcolony.so` and `npcolony.plugin`) into the proper release directory
|
|
68
|
+
and then run the `make_all build` script to create the target files (eg: cbx and xpi).
|
|
69
|
+
|
|
70
|
+
```bash
|
|
71
|
+
make_all build <dir>
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
## Examples
|
|
75
|
+
|
|
76
|
+
There's an [examples directory](examples) containing HTML samples to test the plugin.
|
|
77
|
+
|
|
78
|
+
## License
|
|
79
|
+
|
|
80
|
+
Colony Gateway is currently licensed under the [Apache License, Version 2.0](http://www.apache.org/licenses/).
|
|
81
|
+
|
|
82
|
+
## Build Automation
|
|
83
|
+
|
|
84
|
+
[](https://travis-ci.com/github/hivesolutions/colony-npapi)
|
|
85
|
+
[](https://github.com/hivesolutions/colony-npapi/actions)
|
|
86
|
+
[](https://coveralls.io/r/hivesolutions/colony-npapi?branch=master)
|
|
87
|
+
[](https://pypi.python.org/pypi/appier)
|
|
88
|
+
[](https://www.apache.org/licenses/)
|
|
89
|
+
|
|
90
|
+
Keywords: colony npapi native
|
|
91
|
+
Platform: UNKNOWN
|
|
92
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
93
|
+
Classifier: Topic :: Utilities
|
|
94
|
+
Classifier: License :: OSI Approved :: Apache Software License
|
|
95
|
+
Classifier: Operating System :: OS Independent
|
|
96
|
+
Classifier: Programming Language :: Python
|
|
97
|
+
Classifier: Programming Language :: Python :: 2.6
|
|
98
|
+
Classifier: Programming Language :: Python :: 2.7
|
|
99
|
+
Classifier: Programming Language :: Python :: 3.0
|
|
100
|
+
Classifier: Programming Language :: Python :: 3.1
|
|
101
|
+
Classifier: Programming Language :: Python :: 3.2
|
|
102
|
+
Classifier: Programming Language :: Python :: 3.3
|
|
103
|
+
Classifier: Programming Language :: Python :: 3.4
|
|
104
|
+
Classifier: Programming Language :: Python :: 3.5
|
|
105
|
+
Classifier: Programming Language :: Python :: 3.6
|
|
106
|
+
Classifier: Programming Language :: Python :: 3.7
|
|
107
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
108
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
109
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
110
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
111
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
112
|
+
Description-Content-Type: text/markdown
|
npcolony-1.2.1/README.md
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
# [Colony Gateway (NPAPI Plugin)](http://getcolony.com)
|
|
2
|
+
|
|
3
|
+
NPAPI-based plugin that provides a series of native features like:
|
|
4
|
+
|
|
5
|
+
* Printing using direct access to the printing infra-structure of the operative system
|
|
6
|
+
* Creation of native-based GUI elements
|
|
7
|
+
|
|
8
|
+
The current implementation supports only x86/x64 architectures and Windows, Linux, and Mac OS X.
|
|
9
|
+
|
|
10
|
+
## Building
|
|
11
|
+
|
|
12
|
+
To build both the CRX (Google Chrome) and the XPI (Mozilla Firefox) files for the plugin
|
|
13
|
+
one should use the scripts created for such effect under the [scripts](scripts) directory. The
|
|
14
|
+
automated process assumes the Windows build process using the Visual Studio IDE.
|
|
15
|
+
|
|
16
|
+
### Windows
|
|
17
|
+
|
|
18
|
+
Use Visual Studio 2008 Express for compilation with no additional dependencies. The build process should
|
|
19
|
+
create the plugin files in the output.
|
|
20
|
+
|
|
21
|
+
### Mac OS X
|
|
22
|
+
|
|
23
|
+
Download the [Gecko SDK 1.9 32 bit](https://developer.mozilla.org/en-US/docs/Gecko_SDK) from the official
|
|
24
|
+
website.
|
|
25
|
+
|
|
26
|
+
Use the `/Library/Internet Plug-Ins/` directory to test the plugin while the proper extension package file
|
|
27
|
+
is not created. Remember to rename the `*.bundle` package into an `*.plugin` based package.
|
|
28
|
+
|
|
29
|
+
### Linux
|
|
30
|
+
|
|
31
|
+
Use the `/usr/lib/mozilla/plugins/` directory to test the `*.so` based plugin file for development purposes.
|
|
32
|
+
[Mozilla Firefox](http://www.mozilla.org) should be the primary browser for the debugging of the NPAPI-based plugin.
|
|
33
|
+
|
|
34
|
+
### Python
|
|
35
|
+
|
|
36
|
+
It's also possible to build a Python module that exports the functionality in the NPAPI Plugin for
|
|
37
|
+
running the python script as `python setup.py install` under an UNIX-based machine.
|
|
38
|
+
|
|
39
|
+
## Packaging
|
|
40
|
+
|
|
41
|
+
### Google Chrome
|
|
42
|
+
|
|
43
|
+
Create a package file containing references to the complete set of plugin files for the various
|
|
44
|
+
platforms as defined in the `src/colony_npapi/descriptors/manifest_u.json` file.
|
|
45
|
+
|
|
46
|
+
```javascript
|
|
47
|
+
"plugins" : [{
|
|
48
|
+
"path" : "npcolony.dll",
|
|
49
|
+
"public" : true
|
|
50
|
+
}, {
|
|
51
|
+
"path" : "libnpcolony.so",
|
|
52
|
+
"public" : true
|
|
53
|
+
}, {
|
|
54
|
+
"path" : "npcolony.plugin",
|
|
55
|
+
"public" : true
|
|
56
|
+
}]
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
Copy the proper files (`npcolony.dll`, `libnpcolony.so` and `npcolony.plugin`) into the proper release directory
|
|
60
|
+
and then run the `make_all build` script to create the target files (eg: cbx and xpi).
|
|
61
|
+
|
|
62
|
+
```bash
|
|
63
|
+
make_all build <dir>
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
## Examples
|
|
67
|
+
|
|
68
|
+
There's an [examples directory](examples) containing HTML samples to test the plugin.
|
|
69
|
+
|
|
70
|
+
## License
|
|
71
|
+
|
|
72
|
+
Colony Gateway is currently licensed under the [Apache License, Version 2.0](http://www.apache.org/licenses/).
|
|
73
|
+
|
|
74
|
+
## Build Automation
|
|
75
|
+
|
|
76
|
+
[](https://travis-ci.com/github/hivesolutions/colony-npapi)
|
|
77
|
+
[](https://github.com/hivesolutions/colony-npapi/actions)
|
|
78
|
+
[](https://coveralls.io/r/hivesolutions/colony-npapi?branch=master)
|
|
79
|
+
[](https://pypi.python.org/pypi/appier)
|
|
80
|
+
[](https://www.apache.org/licenses/)
|
npcolony-1.2.1/setup.cfg
ADDED
npcolony-1.2.1/setup.py
ADDED
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
#!/usr/bin/python
|
|
2
|
+
# -*- coding: utf-8 -*-
|
|
3
|
+
|
|
4
|
+
# Hive Colony Framework
|
|
5
|
+
# Copyright (c) 2008-2020 Hive Solutions Lda.
|
|
6
|
+
#
|
|
7
|
+
# This file is part of Hive Colony Framework
|
|
8
|
+
#
|
|
9
|
+
# Hive Colony Framework is free software: you can redistribute it and/or modify
|
|
10
|
+
# it under the terms of the Apache License as published by the Apache
|
|
11
|
+
# Foundation, either version 2.0 of the License, or (at your option) any
|
|
12
|
+
# later version.
|
|
13
|
+
#
|
|
14
|
+
# Hive Colony Framework is distributed in the hope that it will be useful,
|
|
15
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
16
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
17
|
+
# Apache License for more details.
|
|
18
|
+
#
|
|
19
|
+
# You should have received a copy of the Apache License along with
|
|
20
|
+
# Hive Colony Framework If not, see <http://www.apache.org/licenses/>.
|
|
21
|
+
|
|
22
|
+
__author__ = "João Magalhães <joamag@hive.pt>"
|
|
23
|
+
""" The author(s) of the module """
|
|
24
|
+
|
|
25
|
+
__copyright__ = "Copyright (c) 2008-2020 Hive Solutions Lda."
|
|
26
|
+
""" The copyright for the module """
|
|
27
|
+
|
|
28
|
+
__license__ = "Apache License, Version 2.0"
|
|
29
|
+
""" The license for the module """
|
|
30
|
+
|
|
31
|
+
import os
|
|
32
|
+
import setuptools
|
|
33
|
+
|
|
34
|
+
def rename_sources(sources, base = ".c", target = ".cpp"):
|
|
35
|
+
renamed = []
|
|
36
|
+
for source in sources:
|
|
37
|
+
source_extension = os.path.splitext(source)[1]
|
|
38
|
+
if not source_extension == base: continue
|
|
39
|
+
source_name = os.path.splitext(source)[0]
|
|
40
|
+
new_source_path = source_name + target
|
|
41
|
+
os.rename(source, new_source_path)
|
|
42
|
+
renamed.append(new_source_path)
|
|
43
|
+
return renamed
|
|
44
|
+
|
|
45
|
+
def rollback_sources(sources, base = ".cpp", target = ".c"):
|
|
46
|
+
return rename_sources(sources, base = base, target = target)
|
|
47
|
+
|
|
48
|
+
module = setuptools.Extension(
|
|
49
|
+
"npcolony",
|
|
50
|
+
define_macros = [
|
|
51
|
+
("MAJOR_VERSION", "1"),
|
|
52
|
+
('MINOR_VERSION', '0')
|
|
53
|
+
],
|
|
54
|
+
include_dirs = [
|
|
55
|
+
".",
|
|
56
|
+
"src/colony_npapi/",
|
|
57
|
+
"/usr/local/include"
|
|
58
|
+
],
|
|
59
|
+
libraries = [
|
|
60
|
+
"user32",
|
|
61
|
+
"gdi32",
|
|
62
|
+
"winspool",
|
|
63
|
+
"comdlg32"
|
|
64
|
+
] if os.name in ("nt",) else ["cups"],
|
|
65
|
+
library_dirs = ["/usr/local/lib"],
|
|
66
|
+
extra_compile_args = [
|
|
67
|
+
"/DHAVE_LIBPYTHON",
|
|
68
|
+
"/DHAVE_LIBPYTHON_UNDEF"
|
|
69
|
+
] if os.name in ("nt",) else [
|
|
70
|
+
"-std=c99",
|
|
71
|
+
"-pedantic",
|
|
72
|
+
"-finline-functions",
|
|
73
|
+
"-Wall",
|
|
74
|
+
"-Wno-long-long",
|
|
75
|
+
"-Wno-variadic-macros",
|
|
76
|
+
"-Wno-strict-aliasing",
|
|
77
|
+
"-Wno-strict-prototypes",
|
|
78
|
+
"-DNO_CONFIG_H",
|
|
79
|
+
"-DCOLONY_PLATFORM_UNIX"
|
|
80
|
+
],
|
|
81
|
+
sources = [
|
|
82
|
+
"src/colony_npapi/stdafx.c",
|
|
83
|
+
"src/colony_npapi/encoding/base_64.c",
|
|
84
|
+
"src/colony_npapi/plugin/base.c",
|
|
85
|
+
"src/colony_npapi/plugin/python.c",
|
|
86
|
+
"src/colony_npapi/plugin/util.c",
|
|
87
|
+
"src/colony_npapi/print/print_unix.c",
|
|
88
|
+
"src/colony_npapi/print/print_win32.c",
|
|
89
|
+
"src/colony_npapi/system/gui_unix.c",
|
|
90
|
+
"src/colony_npapi/system/gui_win32.c"
|
|
91
|
+
]
|
|
92
|
+
)
|
|
93
|
+
|
|
94
|
+
if os.name in ("nt",):
|
|
95
|
+
module.sources = rename_sources(module.sources)
|
|
96
|
+
try:
|
|
97
|
+
setuptools.setup(
|
|
98
|
+
name = "npcolony",
|
|
99
|
+
version = "1.2.1",
|
|
100
|
+
author = "Hive Solutions Lda.",
|
|
101
|
+
author_email = "development@hive.pt",
|
|
102
|
+
description = "Colony Framework",
|
|
103
|
+
license = "Apache License, Version 2.0",
|
|
104
|
+
keywords = "colony npapi native",
|
|
105
|
+
url = "http://colony_npapi.hive.pt",
|
|
106
|
+
packages = [
|
|
107
|
+
"npcolony_py",
|
|
108
|
+
"npcolony_py.test"
|
|
109
|
+
],
|
|
110
|
+
test_suite = "npcolony_py.test",
|
|
111
|
+
package_dir = {
|
|
112
|
+
"" : os.path.normpath("src/python")
|
|
113
|
+
},
|
|
114
|
+
zip_safe = False,
|
|
115
|
+
ext_modules = [module],
|
|
116
|
+
classifiers = [
|
|
117
|
+
"Development Status :: 5 - Production/Stable",
|
|
118
|
+
"Topic :: Utilities",
|
|
119
|
+
"License :: OSI Approved :: Apache Software License",
|
|
120
|
+
"Operating System :: OS Independent",
|
|
121
|
+
"Programming Language :: Python",
|
|
122
|
+
"Programming Language :: Python :: 2.6",
|
|
123
|
+
"Programming Language :: Python :: 2.7",
|
|
124
|
+
"Programming Language :: Python :: 3.0",
|
|
125
|
+
"Programming Language :: Python :: 3.1",
|
|
126
|
+
"Programming Language :: Python :: 3.2",
|
|
127
|
+
"Programming Language :: Python :: 3.3",
|
|
128
|
+
"Programming Language :: Python :: 3.4",
|
|
129
|
+
"Programming Language :: Python :: 3.5",
|
|
130
|
+
"Programming Language :: Python :: 3.6",
|
|
131
|
+
"Programming Language :: Python :: 3.7",
|
|
132
|
+
"Programming Language :: Python :: 3.8",
|
|
133
|
+
"Programming Language :: Python :: 3.9",
|
|
134
|
+
"Programming Language :: Python :: 3.10",
|
|
135
|
+
"Programming Language :: Python :: 3.11",
|
|
136
|
+
"Programming Language :: Python :: 3.12"
|
|
137
|
+
],
|
|
138
|
+
long_description = open(os.path.join(os.path.dirname(__file__), "README.md"), "rb").read().decode("utf-8"),
|
|
139
|
+
long_description_content_type = "text/markdown"
|
|
140
|
+
)
|
|
141
|
+
finally:
|
|
142
|
+
if os.name in ("nt",):
|
|
143
|
+
rollback_sources(module.sources)
|
|
@@ -0,0 +1,346 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Hive Colony Framework
|
|
3
|
+
Copyright (c) 2008-2020 Hive Solutions Lda.
|
|
4
|
+
|
|
5
|
+
This file is part of Hive Colony Framework.
|
|
6
|
+
|
|
7
|
+
Hive Colony Framework is free software: you can redistribute it and/or modify
|
|
8
|
+
it under the terms of the Apache License as published by the Apache
|
|
9
|
+
Foundation, either version 2.0 of the License, or (at your option) any
|
|
10
|
+
later version.
|
|
11
|
+
|
|
12
|
+
Hive Colony Framework is distributed in the hope that it will be useful,
|
|
13
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
14
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
15
|
+
Apache License for more details.
|
|
16
|
+
|
|
17
|
+
You should have received a copy of the Apache License along with
|
|
18
|
+
Hive Colony Framework. If not, see <http://www.apache.org/licenses/>.
|
|
19
|
+
|
|
20
|
+
__author__ = João Magalhães <joamag@hive.pt>
|
|
21
|
+
__copyright__ = Copyright (c) 2008-2020 Hive Solutions Lda.
|
|
22
|
+
__license__ = Apache License, Version 2.0
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
#include "stdafx.h"
|
|
26
|
+
|
|
27
|
+
#include "base_64.h"
|
|
28
|
+
|
|
29
|
+
const char base64_characters[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
|
30
|
+
|
|
31
|
+
int encode_base64(
|
|
32
|
+
unsigned char *buffer, size_t buffer_length,
|
|
33
|
+
unsigned char **encoded_buffer_pointer,
|
|
34
|
+
size_t *encoded_buffer_length_pointer
|
|
35
|
+
) {
|
|
36
|
+
/* allocates the encoded buffer, and assigns the encoded buffer length */
|
|
37
|
+
_allocate_encoded_buffer(buffer_length, encoded_buffer_pointer, encoded_buffer_length_pointer);
|
|
38
|
+
|
|
39
|
+
/* encodes the buffer into base 64 */
|
|
40
|
+
_encode_base64(buffer, buffer_length, *encoded_buffer_pointer, *encoded_buffer_length_pointer);
|
|
41
|
+
|
|
42
|
+
/* returns valid */
|
|
43
|
+
return 0;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
int decode_base64(
|
|
47
|
+
unsigned char *encoded_buffer,
|
|
48
|
+
size_t encoded_buffer_length,
|
|
49
|
+
unsigned char **decoded_buffer_pointer,
|
|
50
|
+
size_t *decoded_buffer_length_pointer
|
|
51
|
+
) {
|
|
52
|
+
/* retrieves the padding count from the encoded buffer */
|
|
53
|
+
unsigned int padding_count = _get_padding_count(encoded_buffer, encoded_buffer_length);
|
|
54
|
+
|
|
55
|
+
/* allocates the decoded buffer, and assigns the decoded buffer length */
|
|
56
|
+
_allocate_decoded_buffer(encoded_buffer_length, decoded_buffer_pointer, decoded_buffer_length_pointer, padding_count);
|
|
57
|
+
|
|
58
|
+
/* decodes the buffer from base 64 */
|
|
59
|
+
_decode_base64(
|
|
60
|
+
encoded_buffer,
|
|
61
|
+
encoded_buffer_length,
|
|
62
|
+
*decoded_buffer_pointer,
|
|
63
|
+
*decoded_buffer_length_pointer,
|
|
64
|
+
padding_count
|
|
65
|
+
);
|
|
66
|
+
|
|
67
|
+
/* returns valid */
|
|
68
|
+
return 0;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
size_t calculate_encoded_buffer_length_base64(size_t buffer_length) {
|
|
72
|
+
/* allocates the encoded buffer length */
|
|
73
|
+
size_t encoded_buffer_length;
|
|
74
|
+
|
|
75
|
+
/* allocates the padding count */
|
|
76
|
+
size_t padding_count;
|
|
77
|
+
|
|
78
|
+
/* calculates the padding count */
|
|
79
|
+
padding_count = (buffer_length % 3) ? 3 - (buffer_length % 3) : 0;
|
|
80
|
+
|
|
81
|
+
/* calculates the encoded buffer length */
|
|
82
|
+
encoded_buffer_length = ((buffer_length + padding_count) * 4 / 3);
|
|
83
|
+
|
|
84
|
+
/* returns the encoded buffer length */
|
|
85
|
+
return encoded_buffer_length;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
size_t calculate_decoded_buffer_length_base64(
|
|
89
|
+
size_t encoded_buffer_length,
|
|
90
|
+
size_t padding_count
|
|
91
|
+
) {
|
|
92
|
+
/* allocates the decoded buffer length */
|
|
93
|
+
size_t decoded_buffer_length;
|
|
94
|
+
|
|
95
|
+
/* calculates the decoded buffer length */
|
|
96
|
+
decoded_buffer_length = (encoded_buffer_length / 4 * 3) - padding_count;
|
|
97
|
+
|
|
98
|
+
/* returns the decoded buffer length */
|
|
99
|
+
return decoded_buffer_length;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
int _encode_base64(
|
|
103
|
+
unsigned char *buffer,
|
|
104
|
+
size_t buffer_length,
|
|
105
|
+
unsigned char *encoded_buffer,
|
|
106
|
+
size_t encoded_buffer_length
|
|
107
|
+
) {
|
|
108
|
+
/* allocates space for the the encoded buffer index */
|
|
109
|
+
size_t encoded_buffer_index;
|
|
110
|
+
|
|
111
|
+
/* allocates space for the the index */
|
|
112
|
+
size_t index;
|
|
113
|
+
|
|
114
|
+
/* allocates space for the long number */
|
|
115
|
+
unsigned long number = 0;
|
|
116
|
+
|
|
117
|
+
/* allocates space for the partial numbers */
|
|
118
|
+
unsigned char number0, number1, number2, number3;
|
|
119
|
+
|
|
120
|
+
/* creates the pad count value */
|
|
121
|
+
unsigned int pad_count = (unsigned int) buffer_length % 3;
|
|
122
|
+
|
|
123
|
+
/* starts the encoded buffer index */
|
|
124
|
+
encoded_buffer_index = 0;
|
|
125
|
+
|
|
126
|
+
/* increment over the length of the buffer, three characters at a time */
|
|
127
|
+
for(index = 0; index < buffer_length; index += 3) {
|
|
128
|
+
/* starts creating the number with the first byte */
|
|
129
|
+
number = buffer[index] << 16;
|
|
130
|
+
|
|
131
|
+
/* in case there are two bytes (at least) available */
|
|
132
|
+
if(index + 1 < buffer_length) {
|
|
133
|
+
/* increments the number with the value of the second byte */
|
|
134
|
+
number += buffer[index + 1] << 8;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/* in case there are three bytes (at least) available */
|
|
138
|
+
if(index + 2 < buffer_length) {
|
|
139
|
+
/* increments the number with the value of the third byte */
|
|
140
|
+
number += buffer[index + 2];
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/* separates the 24 bit number into four 6 bit numbers */
|
|
144
|
+
number0 = (unsigned char) (number >> 18) & 63;
|
|
145
|
+
number1 = (unsigned char) (number >> 12) & 63;
|
|
146
|
+
number2 = (unsigned char) (number >> 6) & 63;
|
|
147
|
+
number3 = (unsigned char) number & 63;
|
|
148
|
+
|
|
149
|
+
/* sets the first two characters in the encoded buffer */
|
|
150
|
+
encoded_buffer[encoded_buffer_index++] = base64_characters[number0];
|
|
151
|
+
encoded_buffer[encoded_buffer_index++] = base64_characters[number1];
|
|
152
|
+
|
|
153
|
+
/* in case there are two bytes (at least) available */
|
|
154
|
+
if(index + 1 < buffer_length) {
|
|
155
|
+
/* sets the third character in the encoded buffer */
|
|
156
|
+
encoded_buffer[encoded_buffer_index++] = base64_characters[number2];
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/* in case there are three bytes (at least) available */
|
|
160
|
+
if(index + 2 < buffer_length) {
|
|
161
|
+
/* sets the fourth character in the encoded buffer */
|
|
162
|
+
encoded_buffer[encoded_buffer_index++] = base64_characters[number3];
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
/* in case the padding count is valid */
|
|
167
|
+
if(pad_count > 0) {
|
|
168
|
+
/* iterates over the pad count */
|
|
169
|
+
for(; pad_count < 3; pad_count++) {
|
|
170
|
+
/* sets the padding character in the encoded buffer buffer */
|
|
171
|
+
encoded_buffer[encoded_buffer_index++] = PADDING_BASE_64;
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
/* returns one success */
|
|
176
|
+
return 1;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
int _decode_base64(
|
|
180
|
+
unsigned char *encoded_buffer,
|
|
181
|
+
size_t encoded_buffer_length,
|
|
182
|
+
unsigned char *buffer,
|
|
183
|
+
size_t buffer_length,
|
|
184
|
+
size_t padding_count
|
|
185
|
+
) {
|
|
186
|
+
/* allocates space for the the buffer index */
|
|
187
|
+
size_t buffer_index;
|
|
188
|
+
|
|
189
|
+
/* allocates space for the the index */
|
|
190
|
+
size_t index;
|
|
191
|
+
|
|
192
|
+
/* allocates space for the long number */
|
|
193
|
+
unsigned long number = 0;
|
|
194
|
+
|
|
195
|
+
/* allocates space for the partial numbers */
|
|
196
|
+
unsigned char number0, number1, number2;
|
|
197
|
+
|
|
198
|
+
/* calculates the valid buffer length */
|
|
199
|
+
size_t valid_buffer_length = buffer_length - padding_count;
|
|
200
|
+
|
|
201
|
+
/* starts the buffer index */
|
|
202
|
+
buffer_index = 0;
|
|
203
|
+
|
|
204
|
+
/* increments over the length of the encoded buffer, four characters at a time */
|
|
205
|
+
for(index = 0; index < encoded_buffer_length; index += 4) {
|
|
206
|
+
/* retrieves the number resulting from the concatenation of the 24 bits */
|
|
207
|
+
number = (_lookup_fast_base64(encoded_buffer[index]) << 18) + (_lookup_fast_base64(encoded_buffer[index + 1]) << 12) +
|
|
208
|
+
(_lookup_fast_base64(encoded_buffer[index + 2]) << 6) + _lookup_fast_base64(encoded_buffer[index + 3]);
|
|
209
|
+
|
|
210
|
+
/* retrieves the various bytes from the retrieved number */
|
|
211
|
+
number0 = (unsigned char) (number >> 16) & 255;
|
|
212
|
+
number1 = (unsigned char) (number >> 8) & 255;
|
|
213
|
+
number2 = (unsigned char) number & 255;
|
|
214
|
+
|
|
215
|
+
/* writes the first byte in the buffer */
|
|
216
|
+
buffer[buffer_index++] = number0;
|
|
217
|
+
|
|
218
|
+
/* in case the buffer index is still valid */
|
|
219
|
+
if(buffer_index <= valid_buffer_length) {
|
|
220
|
+
/* writes the second byte in the buffer */
|
|
221
|
+
buffer[buffer_index++] = number1;
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
/* in case the buffer index is still valid */
|
|
225
|
+
if(buffer_index <= valid_buffer_length) {
|
|
226
|
+
/* writes the third byte in the buffer */
|
|
227
|
+
buffer[buffer_index++] = number2;
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
/* returns one success */
|
|
232
|
+
return 1;
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
int _allocate_encoded_buffer(
|
|
236
|
+
size_t buffer_length,
|
|
237
|
+
unsigned char **encoded_buffer_pointer,
|
|
238
|
+
size_t *encoded_buffer_length_pointer
|
|
239
|
+
) {
|
|
240
|
+
/* allocates the encoded buffer length */
|
|
241
|
+
*encoded_buffer_length_pointer = calculate_encoded_buffer_length_base64(buffer_length);
|
|
242
|
+
|
|
243
|
+
/* allocates the encoded buffer */
|
|
244
|
+
*encoded_buffer_pointer = (unsigned char *) malloc(*encoded_buffer_length_pointer);
|
|
245
|
+
|
|
246
|
+
/* returns valid */
|
|
247
|
+
return 0;
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
int _allocate_decoded_buffer(
|
|
251
|
+
size_t encoded_buffer_length,
|
|
252
|
+
unsigned char **decoded_buffer_pointer,
|
|
253
|
+
size_t *decoded_buffer_length_pointer,
|
|
254
|
+
size_t padding_count
|
|
255
|
+
) {
|
|
256
|
+
/* allocates the decoded buffer length */
|
|
257
|
+
*decoded_buffer_length_pointer = calculate_decoded_buffer_length_base64(encoded_buffer_length, padding_count);
|
|
258
|
+
|
|
259
|
+
/* allocates the decoded buffer */
|
|
260
|
+
*decoded_buffer_pointer = (unsigned char *) malloc(*decoded_buffer_length_pointer);
|
|
261
|
+
|
|
262
|
+
/* returns valid */
|
|
263
|
+
return 0;
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
unsigned int _get_padding_count(unsigned char *encoded_buffer, size_t encoded_buffer_length) {
|
|
267
|
+
/* allocates the index */
|
|
268
|
+
unsigned int index;
|
|
269
|
+
|
|
270
|
+
/* allocates the current value */
|
|
271
|
+
unsigned char current_value;
|
|
272
|
+
|
|
273
|
+
/* allocates the padding count */
|
|
274
|
+
int padding_count = 0;
|
|
275
|
+
|
|
276
|
+
/* iterates over the encoded buffer */
|
|
277
|
+
for(index = (unsigned int) encoded_buffer_length - 1; index > 0 ; index--) {
|
|
278
|
+
/* retireve the current value */
|
|
279
|
+
current_value = encoded_buffer[index];
|
|
280
|
+
|
|
281
|
+
/* in case the current value is not a padding character */
|
|
282
|
+
if(current_value != PADDING_BASE_64) {
|
|
283
|
+
/* breaks the loop */
|
|
284
|
+
break;
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
/* increments the padding count */
|
|
288
|
+
padding_count++;
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
/* returns the padding count */
|
|
292
|
+
return padding_count;
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
unsigned char _lookup_base64(unsigned char value) {
|
|
296
|
+
/* allocates space for the index */
|
|
297
|
+
unsigned char index;
|
|
298
|
+
|
|
299
|
+
/* allocates space for the current value */
|
|
300
|
+
unsigned char current_value;
|
|
301
|
+
|
|
302
|
+
/* iterates over all the base 64 characters */
|
|
303
|
+
for(index = 0; index < 64; index++) {
|
|
304
|
+
/* retrieves the current value */
|
|
305
|
+
current_value = base64_characters[index];
|
|
306
|
+
|
|
307
|
+
/* in case the current value and the value match */
|
|
308
|
+
if(current_value == value) {
|
|
309
|
+
/* returns the index */
|
|
310
|
+
return index;
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
/* returns the default value */
|
|
315
|
+
return 0;
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
unsigned char _lookup_fast_base64(unsigned char value) {
|
|
319
|
+
/* in case it's a capital letter */
|
|
320
|
+
if(value >= 'A' && value <= 'Z') {
|
|
321
|
+
return value - 65;
|
|
322
|
+
}
|
|
323
|
+
/* in case it's a non capital letter */
|
|
324
|
+
else if(value >= 'a' && value <= 'z') {
|
|
325
|
+
return value - 71;
|
|
326
|
+
}
|
|
327
|
+
/* in case it's a number */
|
|
328
|
+
else if(value >= '0' && value <= '9') {
|
|
329
|
+
return value + 4;
|
|
330
|
+
}
|
|
331
|
+
/* in case it's the plus sign */
|
|
332
|
+
else if(value == '+') {
|
|
333
|
+
return 62;
|
|
334
|
+
}
|
|
335
|
+
/* in case it's the slash sign */
|
|
336
|
+
else if(value == '/') {
|
|
337
|
+
return 63;
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
/* returns the default value */
|
|
341
|
+
return 0;
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
void _free_base64(unsigned char *pointer) {
|
|
345
|
+
free(pointer);
|
|
346
|
+
}
|