summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/plugins/scripts/perl/weechat-perl.c22
-rw-r--r--src/plugins/scripts/python/weechat-python.c115
-rw-r--r--weechat/src/plugins/scripts/perl/weechat-perl.c22
-rw-r--r--weechat/src/plugins/scripts/python/weechat-python.c115
4 files changed, 170 insertions, 104 deletions
diff --git a/src/plugins/scripts/perl/weechat-perl.c b/src/plugins/scripts/perl/weechat-perl.c
index ca46868f1..c46f78480 100644
--- a/src/plugins/scripts/perl/weechat-perl.c
+++ b/src/plugins/scripts/perl/weechat-perl.c
@@ -122,8 +122,7 @@ weechat_perl_exec (t_weechat_plugin *plugin,
func = function;
PERL_SET_CONTEXT (script->interpreter);
#endif
- perl_current_script = script;
-
+
dSP;
ENTER;
SAVETMPS;
@@ -135,8 +134,12 @@ weechat_perl_exec (t_weechat_plugin *plugin,
argv[1] = arguments;
argv[2] = NULL;
+ perl_current_script = script;
+
count = perl_call_argv (func, G_EVAL | G_SCALAR, argv);
+ perl_current_script = NULL;
+
SPAGAIN;
sv = GvSV (gv_fetchpv ("@", TRUE, SVt_PV));
@@ -560,6 +563,9 @@ static XS (XS_weechat_get_dcc_info)
{
t_plugin_dcc_info *dcc_info, *ptr_dcc;
int dcc_count;
+ char timebuffer1[64];
+ char timebuffer2[64];
+ struct in_addr in;
dXSARGS;
/* make gcc happy */
@@ -582,15 +588,21 @@ static XS (XS_weechat_get_dcc_info)
for (ptr_dcc = dcc_info; ptr_dcc; ptr_dcc = ptr_dcc->next_dcc)
{
+ strftime(timebuffer1, sizeof(timebuffer1), "%F %T",
+ localtime(&ptr_dcc->start_time));
+ strftime(timebuffer2, sizeof(timebuffer2), "%F %T",
+ localtime(&ptr_dcc->start_transfer));
+ in.s_addr = htonl(ptr_dcc->addr);
+
HV *infohash = (HV *) sv_2mortal((SV *) newHV());
hv_store (infohash, "server", 6, newSVpv (ptr_dcc->server, 0), 0);
hv_store (infohash, "channel", 7, newSVpv (ptr_dcc->channel, 0), 0);
hv_store (infohash, "type", 4, newSViv (ptr_dcc->type), 0);
hv_store (infohash, "status", 6, newSViv (ptr_dcc->status), 0);
- hv_store (infohash, "start_time", 10, newSViv (ptr_dcc->start_time), 0);
- hv_store (infohash, "start_transfer", 14, newSViv (ptr_dcc->start_transfer), 0);
- hv_store (infohash, "address", 7, newSViv (ptr_dcc->addr), 0);
+ hv_store (infohash, "start_time", 10, newSVpv (timebuffer1, 0), 0);
+ hv_store (infohash, "start_transfer", 14, newSVpv (timebuffer2, 0), 0);
+ hv_store (infohash, "address", 7, newSVpv (inet_ntoa(in), 0), 0);
hv_store (infohash, "port", 4, newSViv (ptr_dcc->port), 0);
hv_store (infohash, "nick", 4, newSVpv (ptr_dcc->nick, 0), 0);
hv_store (infohash, "remote_file", 11, newSVpv (ptr_dcc->filename, 0), 0);
diff --git a/src/plugins/scripts/python/weechat-python.c b/src/plugins/scripts/python/weechat-python.c
index c75982796..85be78a40 100644
--- a/src/plugins/scripts/python/weechat-python.c
+++ b/src/plugins/scripts/python/weechat-python.c
@@ -23,6 +23,9 @@
#include <Python.h>
#include <stdlib.h>
#include <string.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
#undef _
#include "../../weechat-plugin.h"
#include "../weechat-script.h"
@@ -74,6 +77,8 @@ weechat_python_exec (t_weechat_plugin *plugin,
python_current_script = script;
rc = PyObject_CallFunction(evFunc, "ss", server == NULL ? "" : server, arguments == NULL ? "" : arguments);
+
+ python_current_script = NULL;
if (rc)
{
@@ -462,8 +467,11 @@ static PyObject *
weechat_python_get_dcc_info (PyObject *self, PyObject *args)
{
t_plugin_dcc_info *dcc_info, *ptr_dcc;
- int dcc_count;
- PyObject *list, *listvalue;
+ PyObject *dcc_list;
+ PyObject *dcc_list_member;
+ char timebuffer1[64];
+ char timebuffer2[64];
+ struct in_addr in;
/* make gcc happy */
(void) self;
@@ -474,71 +482,84 @@ weechat_python_get_dcc_info (PyObject *self, PyObject *args)
python_plugin->printf_server (python_plugin,
"Python error: unable to get DCC info, "
"script not initialized");
- return Py_BuildValue ("i", 0);
+ return Py_None;
}
+
+ dcc_list = PyList_New (0);
- dcc_info = python_plugin->get_dcc_info (python_plugin);
- dcc_count = 0;
+ if (!dcc_list)
+ return Py_None;
+ dcc_info = python_plugin->get_dcc_info (python_plugin);
if (!dcc_info)
- return Py_BuildValue ("i", 0);
+ return dcc_list;
- for (ptr_dcc = dcc_info; ptr_dcc; ptr_dcc = ptr_dcc->next_dcc)
- {
- dcc_count++;
- }
-
- list = PyList_New (dcc_count);
-
- if (!list)
- {
- python_plugin->free_dcc_info (python_plugin, dcc_info);
- return Py_BuildValue ("i", 0);
- }
-
- dcc_count = 0;
for(ptr_dcc = dcc_info; ptr_dcc; ptr_dcc = ptr_dcc->next_dcc)
{
- listvalue = Py_BuildValue ("{s:s,s:s,s:i,s:i,s:k,s:k,s:k,s:i,s:s,s:s,"
- "s:s,s:s,s:k,s:k,s:k,s:k}",
- "server", ptr_dcc->server,
- "channel", ptr_dcc->channel,
- "type", ptr_dcc->type,
- "status", ptr_dcc->status,
- "start_time", ptr_dcc->start_time,
- "start_transfer", ptr_dcc->start_transfer,
- "address", ptr_dcc->addr,
- "port", ptr_dcc->port,
- "nick", ptr_dcc->nick,
- "remote_file", ptr_dcc->filename,
- "local_file", ptr_dcc->local_filename,
- "filename_suffix", ptr_dcc->filename_suffix,
- "size", ptr_dcc->size,
- "pos", ptr_dcc->pos,
- "start_resume", ptr_dcc->start_resume,
- "cps", ptr_dcc->bytes_per_sec);
- if (listvalue)
+ strftime(timebuffer1, sizeof(timebuffer1), "%F %T",
+ localtime(&ptr_dcc->start_time));
+ strftime(timebuffer2, sizeof(timebuffer2), "%F %T",
+ localtime(&ptr_dcc->start_transfer));
+ in.s_addr = htonl(ptr_dcc->addr);
+
+ dcc_list_member= PyDict_New();
+
+ if (dcc_list_member)
{
- if (PyList_SetItem (list, dcc_count, listvalue) != 0)
+
+ PyDict_SetItem(dcc_list_member, Py_BuildValue("s", "server"),
+ Py_BuildValue("s", ptr_dcc->server));
+ PyDict_SetItem(dcc_list_member, Py_BuildValue("s", "channel"),
+ Py_BuildValue("s", ptr_dcc->channel));
+ PyDict_SetItem(dcc_list_member, Py_BuildValue("s", "type"),
+ Py_BuildValue("i", ptr_dcc->type));
+ PyDict_SetItem(dcc_list_member, Py_BuildValue("s", "status"),
+ Py_BuildValue("i", ptr_dcc->status));
+ PyDict_SetItem(dcc_list_member, Py_BuildValue("s", "start_time"),
+ Py_BuildValue("s", timebuffer1));
+ PyDict_SetItem(dcc_list_member, Py_BuildValue("s", "start_transfer"),
+ Py_BuildValue("s", timebuffer2));
+ PyDict_SetItem(dcc_list_member, Py_BuildValue("s", "address"),
+ Py_BuildValue("s", inet_ntoa(in)));
+ PyDict_SetItem(dcc_list_member, Py_BuildValue("s", "port"),
+ Py_BuildValue("i", ptr_dcc->port));
+ PyDict_SetItem(dcc_list_member, Py_BuildValue("s", "nick"),
+ Py_BuildValue("s", ptr_dcc->nick));
+ PyDict_SetItem(dcc_list_member, Py_BuildValue("s", "remote_file"),
+ Py_BuildValue("s", ptr_dcc->filename));
+ PyDict_SetItem(dcc_list_member, Py_BuildValue("s", "local_file"),
+ Py_BuildValue("s", ptr_dcc->local_filename));
+ PyDict_SetItem(dcc_list_member, Py_BuildValue("s", "filename_suffix"),
+ Py_BuildValue("i", ptr_dcc->filename_suffix));
+ PyDict_SetItem(dcc_list_member, Py_BuildValue("s", "size"),
+ Py_BuildValue("k", ptr_dcc->size));
+ PyDict_SetItem(dcc_list_member, Py_BuildValue("s", "pos"),
+ Py_BuildValue("k", ptr_dcc->pos));
+ PyDict_SetItem(dcc_list_member, Py_BuildValue("s", "start_resume"),
+ Py_BuildValue("k", ptr_dcc->start_resume));
+ PyDict_SetItem(dcc_list_member, Py_BuildValue("s", "cps"),
+ Py_BuildValue("k", ptr_dcc->bytes_per_sec));
+
+
+ if (PyList_Append(dcc_list, dcc_list_member) != 0)
{
- PyMem_Free (listvalue);
- PyMem_Free (list);
+ Py_DECREF(dcc_list_member);
+ Py_DECREF(dcc_list);
python_plugin->free_dcc_info (python_plugin, dcc_info);
- return Py_BuildValue ("i", 0);
+ return Py_None;
}
- PyMem_Free (listvalue);
}
else
{
+ Py_DECREF(dcc_list);
python_plugin->free_dcc_info (python_plugin, dcc_info);
- return Py_BuildValue ("i", 0);
+ return Py_None;
}
- dcc_count++;
}
python_plugin->free_dcc_info (python_plugin, dcc_info);
- return list;
+ return dcc_list;
}
/*
diff --git a/weechat/src/plugins/scripts/perl/weechat-perl.c b/weechat/src/plugins/scripts/perl/weechat-perl.c
index ca46868f1..c46f78480 100644
--- a/weechat/src/plugins/scripts/perl/weechat-perl.c
+++ b/weechat/src/plugins/scripts/perl/weechat-perl.c
@@ -122,8 +122,7 @@ weechat_perl_exec (t_weechat_plugin *plugin,
func = function;
PERL_SET_CONTEXT (script->interpreter);
#endif
- perl_current_script = script;
-
+
dSP;
ENTER;
SAVETMPS;
@@ -135,8 +134,12 @@ weechat_perl_exec (t_weechat_plugin *plugin,
argv[1] = arguments;
argv[2] = NULL;
+ perl_current_script = script;
+
count = perl_call_argv (func, G_EVAL | G_SCALAR, argv);
+ perl_current_script = NULL;
+
SPAGAIN;
sv = GvSV (gv_fetchpv ("@", TRUE, SVt_PV));
@@ -560,6 +563,9 @@ static XS (XS_weechat_get_dcc_info)
{
t_plugin_dcc_info *dcc_info, *ptr_dcc;
int dcc_count;
+ char timebuffer1[64];
+ char timebuffer2[64];
+ struct in_addr in;
dXSARGS;
/* make gcc happy */
@@ -582,15 +588,21 @@ static XS (XS_weechat_get_dcc_info)
for (ptr_dcc = dcc_info; ptr_dcc; ptr_dcc = ptr_dcc->next_dcc)
{
+ strftime(timebuffer1, sizeof(timebuffer1), "%F %T",
+ localtime(&ptr_dcc->start_time));
+ strftime(timebuffer2, sizeof(timebuffer2), "%F %T",
+ localtime(&ptr_dcc->start_transfer));
+ in.s_addr = htonl(ptr_dcc->addr);
+
HV *infohash = (HV *) sv_2mortal((SV *) newHV());
hv_store (infohash, "server", 6, newSVpv (ptr_dcc->server, 0), 0);
hv_store (infohash, "channel", 7, newSVpv (ptr_dcc->channel, 0), 0);
hv_store (infohash, "type", 4, newSViv (ptr_dcc->type), 0);
hv_store (infohash, "status", 6, newSViv (ptr_dcc->status), 0);
- hv_store (infohash, "start_time", 10, newSViv (ptr_dcc->start_time), 0);
- hv_store (infohash, "start_transfer", 14, newSViv (ptr_dcc->start_transfer), 0);
- hv_store (infohash, "address", 7, newSViv (ptr_dcc->addr), 0);
+ hv_store (infohash, "start_time", 10, newSVpv (timebuffer1, 0), 0);
+ hv_store (infohash, "start_transfer", 14, newSVpv (timebuffer2, 0), 0);
+ hv_store (infohash, "address", 7, newSVpv (inet_ntoa(in), 0), 0);
hv_store (infohash, "port", 4, newSViv (ptr_dcc->port), 0);
hv_store (infohash, "nick", 4, newSVpv (ptr_dcc->nick, 0), 0);
hv_store (infohash, "remote_file", 11, newSVpv (ptr_dcc->filename, 0), 0);
diff --git a/weechat/src/plugins/scripts/python/weechat-python.c b/weechat/src/plugins/scripts/python/weechat-python.c
index c75982796..85be78a40 100644
--- a/weechat/src/plugins/scripts/python/weechat-python.c
+++ b/weechat/src/plugins/scripts/python/weechat-python.c
@@ -23,6 +23,9 @@
#include <Python.h>
#include <stdlib.h>
#include <string.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
#undef _
#include "../../weechat-plugin.h"
#include "../weechat-script.h"
@@ -74,6 +77,8 @@ weechat_python_exec (t_weechat_plugin *plugin,
python_current_script = script;
rc = PyObject_CallFunction(evFunc, "ss", server == NULL ? "" : server, arguments == NULL ? "" : arguments);
+
+ python_current_script = NULL;
if (rc)
{
@@ -462,8 +467,11 @@ static PyObject *
weechat_python_get_dcc_info (PyObject *self, PyObject *args)
{
t_plugin_dcc_info *dcc_info, *ptr_dcc;
- int dcc_count;
- PyObject *list, *listvalue;
+ PyObject *dcc_list;
+ PyObject *dcc_list_member;
+ char timebuffer1[64];
+ char timebuffer2[64];
+ struct in_addr in;
/* make gcc happy */
(void) self;
@@ -474,71 +482,84 @@ weechat_python_get_dcc_info (PyObject *self, PyObject *args)
python_plugin->printf_server (python_plugin,
"Python error: unable to get DCC info, "
"script not initialized");
- return Py_BuildValue ("i", 0);
+ return Py_None;
}
+
+ dcc_list = PyList_New (0);
- dcc_info = python_plugin->get_dcc_info (python_plugin);
- dcc_count = 0;
+ if (!dcc_list)
+ return Py_None;
+ dcc_info = python_plugin->get_dcc_info (python_plugin);
if (!dcc_info)
- return Py_BuildValue ("i", 0);
+ return dcc_list;
- for (ptr_dcc = dcc_info; ptr_dcc; ptr_dcc = ptr_dcc->next_dcc)
- {
- dcc_count++;
- }
-
- list = PyList_New (dcc_count);
-
- if (!list)
- {
- python_plugin->free_dcc_info (python_plugin, dcc_info);
- return Py_BuildValue ("i", 0);
- }
-
- dcc_count = 0;
for(ptr_dcc = dcc_info; ptr_dcc; ptr_dcc = ptr_dcc->next_dcc)
{
- listvalue = Py_BuildValue ("{s:s,s:s,s:i,s:i,s:k,s:k,s:k,s:i,s:s,s:s,"
- "s:s,s:s,s:k,s:k,s:k,s:k}",
- "server", ptr_dcc->server,
- "channel", ptr_dcc->channel,
- "type", ptr_dcc->type,
- "status", ptr_dcc->status,
- "start_time", ptr_dcc->start_time,
- "start_transfer", ptr_dcc->start_transfer,
- "address", ptr_dcc->addr,
- "port", ptr_dcc->port,
- "nick", ptr_dcc->nick,
- "remote_file", ptr_dcc->filename,
- "local_file", ptr_dcc->local_filename,
- "filename_suffix", ptr_dcc->filename_suffix,
- "size", ptr_dcc->size,
- "pos", ptr_dcc->pos,
- "start_resume", ptr_dcc->start_resume,
- "cps", ptr_dcc->bytes_per_sec);
- if (listvalue)
+ strftime(timebuffer1, sizeof(timebuffer1), "%F %T",
+ localtime(&ptr_dcc->start_time));
+ strftime(timebuffer2, sizeof(timebuffer2), "%F %T",
+ localtime(&ptr_dcc->start_transfer));
+ in.s_addr = htonl(ptr_dcc->addr);
+
+ dcc_list_member= PyDict_New();
+
+ if (dcc_list_member)
{
- if (PyList_SetItem (list, dcc_count, listvalue) != 0)
+
+ PyDict_SetItem(dcc_list_member, Py_BuildValue("s", "server"),
+ Py_BuildValue("s", ptr_dcc->server));
+ PyDict_SetItem(dcc_list_member, Py_BuildValue("s", "channel"),
+ Py_BuildValue("s", ptr_dcc->channel));
+ PyDict_SetItem(dcc_list_member, Py_BuildValue("s", "type"),
+ Py_BuildValue("i", ptr_dcc->type));
+ PyDict_SetItem(dcc_list_member, Py_BuildValue("s", "status"),
+ Py_BuildValue("i", ptr_dcc->status));
+ PyDict_SetItem(dcc_list_member, Py_BuildValue("s", "start_time"),
+ Py_BuildValue("s", timebuffer1));
+ PyDict_SetItem(dcc_list_member, Py_BuildValue("s", "start_transfer"),
+ Py_BuildValue("s", timebuffer2));
+ PyDict_SetItem(dcc_list_member, Py_BuildValue("s", "address"),
+ Py_BuildValue("s", inet_ntoa(in)));
+ PyDict_SetItem(dcc_list_member, Py_BuildValue("s", "port"),
+ Py_BuildValue("i", ptr_dcc->port));
+ PyDict_SetItem(dcc_list_member, Py_BuildValue("s", "nick"),
+ Py_BuildValue("s", ptr_dcc->nick));
+ PyDict_SetItem(dcc_list_member, Py_BuildValue("s", "remote_file"),
+ Py_BuildValue("s", ptr_dcc->filename));
+ PyDict_SetItem(dcc_list_member, Py_BuildValue("s", "local_file"),
+ Py_BuildValue("s", ptr_dcc->local_filename));
+ PyDict_SetItem(dcc_list_member, Py_BuildValue("s", "filename_suffix"),
+ Py_BuildValue("i", ptr_dcc->filename_suffix));
+ PyDict_SetItem(dcc_list_member, Py_BuildValue("s", "size"),
+ Py_BuildValue("k", ptr_dcc->size));
+ PyDict_SetItem(dcc_list_member, Py_BuildValue("s", "pos"),
+ Py_BuildValue("k", ptr_dcc->pos));
+ PyDict_SetItem(dcc_list_member, Py_BuildValue("s", "start_resume"),
+ Py_BuildValue("k", ptr_dcc->start_resume));
+ PyDict_SetItem(dcc_list_member, Py_BuildValue("s", "cps"),
+ Py_BuildValue("k", ptr_dcc->bytes_per_sec));
+
+
+ if (PyList_Append(dcc_list, dcc_list_member) != 0)
{
- PyMem_Free (listvalue);
- PyMem_Free (list);
+ Py_DECREF(dcc_list_member);
+ Py_DECREF(dcc_list);
python_plugin->free_dcc_info (python_plugin, dcc_info);
- return Py_BuildValue ("i", 0);
+ return Py_None;
}
- PyMem_Free (listvalue);
}
else
{
+ Py_DECREF(dcc_list);
python_plugin->free_dcc_info (python_plugin, dcc_info);
- return Py_BuildValue ("i", 0);
+ return Py_None;
}
- dcc_count++;
}
python_plugin->free_dcc_info (python_plugin, dcc_info);
- return list;
+ return dcc_list;
}
/*