/
gwan-browser-plugin.c
190 lines (155 loc) · 3.5 KB
/
gwan-browser-plugin.c
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
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
#define PATH_TO_GWAN "/home/ers/downloads/gwan_linux64-bit/gwan"
#include "gwan-browser-plugin.h"
// http://forum.gwan.com/index.php?p=/discussion/comment/1407/#Comment_1407
// http://devedge-temp.mozilla.org/library/manuals/2002/plugin/1.0/npp_api.html#1004145
// https://developer.mozilla.org/En/Gecko_Plugin_API_Reference:Scripting_plugins
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <unistd.h>
#define PLUGIN_NAME "G-WAN Browser plugin"
#define PLUGIN_DESCRIPTION "This plugin embeds G-WAN in a web browser."
#define PLUGIN_VERSION "1.0.0.0"
static NPNetscapeFuncs *sBrowserFuncs = NULL;
NP_EXPORT(NPError)
NP_Initialize(NPNetscapeFuncs *bFuncs, NPPluginFuncs *pFuncs)
{
sBrowserFuncs = bFuncs;
*pFuncs = (NPPluginFuncs){
.newp = NPP_New,
.destroy = NPP_Destroy,
.setwindow = NPP_SetWindow,
.newstream = NPP_NewStream,
.destroystream = NPP_DestroyStream,
.asfile = NPP_StreamAsFile,
.writeready = NPP_WriteReady,
.write = NPP_Write,
.print = NPP_Print,
.event = NPP_HandleEvent,
.urlnotify = NPP_URLNotify,
.getvalue = NPP_GetValue,
.setvalue = NPP_SetValue,
};
pid_t pid = vfork();
if (pid == 0) {
// start and daemonize G-WAN
int code = execl(
"/usr/bin/gksu",
"gksu",
"--description",
"G-WAN (Global-WAN)",
PATH_TO_GWAN " -d",
NULL
);
}
return NPERR_NO_ERROR;
}
NP_EXPORT(NPError)
NP_Shutdown()
{
pid_t pid = vfork();
if (pid == 0) {
// stop G-WAN
int code = execl(
"/usr/bin/gksu",
"gksu",
"--description",
"G-WAN (Global-WAN)",
PATH_TO_GWAN " -k",
NULL
);
}
return NPERR_NO_ERROR;
}
NP_EXPORT(char*)
NP_GetPluginVersion()
{
return PLUGIN_VERSION;
}
NP_EXPORT(const char*)
NP_GetMIMEDescription()
{
return "application/gwan:gwan:G-WAN browser plugin";
}
NP_EXPORT(NPError)
NP_GetValue(void *future, NPPVariable aVariable, void *aValue)
{
switch (aVariable)
{
case NPPVpluginNameString: {
*((char**)aValue) = PLUGIN_NAME;
break;
}
case NPPVpluginDescriptionString: {
*((char**)aValue) = PLUGIN_DESCRIPTION;
break;
}
default: {
return NPERR_INVALID_PARAM;
break;
}
}
return NPERR_NO_ERROR;
}
NPError
NPP_New(NPMIMEType pluginType, NPP instance, uint16_t mode, int16_t argc, char *argn[], char *argv[], NPSavedData *saved)
{
return NPERR_NO_ERROR;
}
NPError
NPP_Destroy(NPP instance, NPSavedData **save)
{
return NPERR_NO_ERROR;
}
NPError
NPP_SetWindow(NPP instance, NPWindow *window)
{
return NPERR_NO_ERROR;
}
NPError
NPP_NewStream(NPP instance, NPMIMEType type, NPStream *stream, NPBool seekable, uint16_t *stype)
{
return NPERR_GENERIC_ERROR;
}
NPError
NPP_DestroyStream(NPP instance, NPStream *stream, NPReason reason)
{
return NPERR_GENERIC_ERROR;
}
int32_t
NPP_WriteReady(NPP instance, NPStream *stream)
{
return 0;
}
int32_t
NPP_Write(NPP instance, NPStream *stream, int32_t offset, int32_t len, void *buffer)
{
return 0;
}
void
NPP_StreamAsFile(NPP instance, NPStream *stream, const char *fname)
{
}
void
NPP_Print(NPP instance, NPPrint *platformPrint)
{
}
int16_t
NPP_HandleEvent(NPP instance, void *event)
{
return 0;
}
void
NPP_URLNotify(NPP instance, const char *URL, NPReason reason, void *notifyData)
{
}
NPError
NPP_GetValue(NPP instance, NPPVariable variable, void *value)
{
return NPERR_GENERIC_ERROR;
}
NPError
NPP_SetValue(NPP instance, NPNVariable variable, void *value)
{
return NPERR_GENERIC_ERROR;
}