~ubuntu-branches/ubuntu/trusty/weechat/trusty-proposed

« back to all changes in this revision

Viewing changes to src/plugins/scripts/python/weechat-python-api.c

  • Committer: Bazaar Package Importer
  • Author(s): Emmanuel Bouthenot
  • Date: 2009-09-15 20:58:07 UTC
  • mfrom: (1.2.6 upstream)
  • Revision ID: james.westby@ubuntu.com-20090915205807-nd2nx3kof2aldqbt
Tags: 0.3.0-1
* New (final) upstream release.
* Upload to unstable.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (c) 2003-2009 by FlashCode <flashcode@flashtux.org>
 
3
 * See README for License detail, AUTHORS for developers list.
 
4
 *
 
5
 * This program is free software; you can redistribute it and/or modify
 
6
 * it under the terms of the GNU General Public License as published by
 
7
 * the Free Software Foundation; either version 3 of the License, or
 
8
 * (at your option) any later version.
 
9
 *
 
10
 * This program is distributed in the hope that it will be useful,
 
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
13
 * GNU General Public License for more details.
 
14
 *
 
15
 * You should have received a copy of the GNU General Public License
 
16
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
17
 */
 
18
 
 
19
/* weechat-python-api.c: Python API functions */
 
20
 
 
21
 
 
22
#undef _
 
23
 
 
24
#include <Python.h>
 
25
#include <time.h>
 
26
 
 
27
#include "../../weechat-plugin.h"
 
28
#include "../script.h"
 
29
#include "../script-api.h"
 
30
#include "../script-callback.h"
 
31
#include "weechat-python.h"
 
32
 
 
33
 
 
34
#define PYTHON_RETURN_OK return Py_BuildValue ("i", 1);
 
35
#define PYTHON_RETURN_ERROR return Py_BuildValue ("i", 0);
 
36
#define PYTHON_RETURN_EMPTY \
 
37
    Py_INCREF(Py_None);     \
 
38
    return Py_None;
 
39
#define PYTHON_RETURN_STRING(__string)             \
 
40
    if (__string)                                  \
 
41
        return Py_BuildValue ("s", __string);      \
 
42
    return Py_BuildValue ("s", "")
 
43
#define PYTHON_RETURN_STRING_FREE(__string)        \
 
44
    if (__string)                                  \
 
45
    {                                              \
 
46
        object = Py_BuildValue ("s", __string);    \
 
47
        free (__string);                           \
 
48
        return object;                             \
 
49
    }                                              \
 
50
    return Py_BuildValue ("s", "")
 
51
#define PYTHON_RETURN_INT(__int)                \
 
52
    return Py_BuildValue("i", __int);
 
53
 
 
54
 
 
55
/*
 
56
 * weechat_python_api_register: startup function for all WeeChat Python scripts
 
57
 */
 
58
 
 
59
static PyObject *
 
60
weechat_python_api_register (PyObject *self, PyObject *args)
 
61
{
 
62
    char *name, *author, *version, *license, *shutdown_func, *description;
 
63
    char *charset;
 
64
    
 
65
    /* make C compiler happy */
 
66
    (void) self;
 
67
    
 
68
    python_current_script = NULL;
 
69
    
 
70
    name = NULL;
 
71
    author = NULL;
 
72
    version = NULL;
 
73
    license = NULL;
 
74
    description = NULL;
 
75
    shutdown_func = NULL;
 
76
    charset = NULL;
 
77
    
 
78
    if (!PyArg_ParseTuple (args, "sssssss", &name, &author, &version,
 
79
                           &license, &description, &shutdown_func, &charset))
 
80
    {
 
81
        WEECHAT_SCRIPT_MSG_WRONG_ARGS(python_current_script_filename, "register");
 
82
        PYTHON_RETURN_ERROR;
 
83
    }
 
84
    
 
85
    if (script_search (weechat_python_plugin, python_scripts, name))
 
86
    {
 
87
        /* error: another scripts already exists with this name! */
 
88
        weechat_printf (NULL,
 
89
                        weechat_gettext ("%s%s: unable to register script "
 
90
                                         "\"%s\" (another script already "
 
91
                                         "exists with this name)"),
 
92
                        weechat_prefix ("error"), PYTHON_PLUGIN_NAME, name);
 
93
        PYTHON_RETURN_ERROR;
 
94
    }
 
95
    
 
96
    /* register script */
 
97
    python_current_script = script_add (weechat_python_plugin,
 
98
                                        &python_scripts, &last_python_script,
 
99
                                        (python_current_script_filename) ?
 
100
                                        python_current_script_filename : "",
 
101
                                        name, author, version, license,
 
102
                                        description, shutdown_func, charset);
 
103
    if (python_current_script)
 
104
    {
 
105
        if ((weechat_python_plugin->debug >= 1) || !python_quiet)
 
106
        {
 
107
            weechat_printf (NULL,
 
108
                            weechat_gettext ("%s: registered script \"%s\", "
 
109
                                             "version %s (%s)"),
 
110
                            PYTHON_PLUGIN_NAME, name, version, description);
 
111
        }
 
112
    }
 
113
    else
 
114
    {
 
115
        PYTHON_RETURN_ERROR;
 
116
    }
 
117
    
 
118
    PYTHON_RETURN_OK;
 
119
}
 
120
 
 
121
/*
 
122
 * weechat_python_api_plugin_get_name: get name of plugin (return "core" for
 
123
 *                                     WeeChat core)
 
124
 */
 
125
 
 
126
static PyObject *
 
127
weechat_python_api_plugin_get_name (PyObject *self, PyObject *args)
 
128
{
 
129
    char *plugin;
 
130
    const char *result;
 
131
    
 
132
    /* make C compiler happy */
 
133
    (void) self;
 
134
    
 
135
    if (!python_current_script)
 
136
    {
 
137
        WEECHAT_SCRIPT_MSG_NOT_INIT(PYTHON_CURRENT_SCRIPT_NAME, "plugin_get_name");
 
138
        PYTHON_RETURN_EMPTY;
 
139
    }
 
140
    
 
141
    plugin = NULL;
 
142
    
 
143
    if (!PyArg_ParseTuple (args, "s", &plugin))
 
144
    {
 
145
        WEECHAT_SCRIPT_MSG_WRONG_ARGS(PYTHON_CURRENT_SCRIPT_NAME, "plugin_get_name");
 
146
        PYTHON_RETURN_EMPTY;
 
147
    }
 
148
    
 
149
    result = weechat_plugin_get_name (script_str2ptr (plugin));
 
150
    
 
151
    PYTHON_RETURN_STRING(result);
 
152
}
 
153
 
 
154
/*
 
155
 * weechat_python_api_charset_set: set script charset
 
156
 */
 
157
 
 
158
static PyObject *
 
159
weechat_python_api_charset_set (PyObject *self, PyObject *args)
 
160
{
 
161
    char *charset;
 
162
    
 
163
    /* make C compiler happy */
 
164
    (void) self;
 
165
    
 
166
    if (!python_current_script)
 
167
    {
 
168
        WEECHAT_SCRIPT_MSG_NOT_INIT(PYTHON_CURRENT_SCRIPT_NAME, "charset_set");
 
169
        PYTHON_RETURN_ERROR;
 
170
    }
 
171
    
 
172
    charset = NULL;
 
173
    
 
174
    if (!PyArg_ParseTuple (args, "s", &charset))
 
175
    {
 
176
        WEECHAT_SCRIPT_MSG_WRONG_ARGS(PYTHON_CURRENT_SCRIPT_NAME, "charset_set");
 
177
        PYTHON_RETURN_ERROR;
 
178
    }
 
179
    
 
180
    script_api_charset_set (python_current_script,
 
181
                            charset);
 
182
    
 
183
    PYTHON_RETURN_OK;
 
184
}
 
185
 
 
186
/*
 
187
 * weechat_python_api_iconv_to_internal: convert string to internal WeeChat charset
 
188
 */
 
189
 
 
190
static PyObject *
 
191
weechat_python_api_iconv_to_internal (PyObject *self, PyObject *args)
 
192
{
 
193
    char *charset, *string, *result;
 
194
    PyObject *object;
 
195
    
 
196
    /* make C compiler happy */
 
197
    (void) self;
 
198
    
 
199
    if (!python_current_script)
 
200
    {
 
201
        WEECHAT_SCRIPT_MSG_NOT_INIT(PYTHON_CURRENT_SCRIPT_NAME, "iconv_to_internal");
 
202
        PYTHON_RETURN_EMPTY;
 
203
    }
 
204
    
 
205
    charset = NULL;
 
206
    string = NULL;
 
207
    
 
208
    if (!PyArg_ParseTuple (args, "ss", &charset, &string))
 
209
    {
 
210
        WEECHAT_SCRIPT_MSG_WRONG_ARGS(PYTHON_CURRENT_SCRIPT_NAME, "iconv_to_internal");
 
211
        PYTHON_RETURN_EMPTY;
 
212
    }
 
213
    
 
214
    result = weechat_iconv_to_internal (charset, string);
 
215
    
 
216
    PYTHON_RETURN_STRING_FREE(result);
 
217
}
 
218
 
 
219
/*
 
220
 * weechat_python_api_iconv_from_internal: convert string from WeeChat internal
 
221
 *                                         charset to another one
 
222
 */
 
223
 
 
224
static PyObject *
 
225
weechat_python_api_iconv_from_internal (PyObject *self, PyObject *args)
 
226
{
 
227
    char *charset, *string, *result;
 
228
    PyObject *object;
 
229
    
 
230
    /* make C compiler happy */
 
231
    (void) self;
 
232
    
 
233
    if (!python_current_script)
 
234
    {
 
235
        WEECHAT_SCRIPT_MSG_NOT_INIT(PYTHON_CURRENT_SCRIPT_NAME, "iconv_from_internal");
 
236
        PYTHON_RETURN_EMPTY;
 
237
    }
 
238
    
 
239
    charset = NULL;
 
240
    string = NULL;
 
241
    
 
242
    if (!PyArg_ParseTuple (args, "ss", &charset, &string))
 
243
    {
 
244
        WEECHAT_SCRIPT_MSG_WRONG_ARGS(PYTHON_CURRENT_SCRIPT_NAME, "iconv_from_internal");
 
245
        PYTHON_RETURN_EMPTY;
 
246
    }
 
247
    
 
248
    result = weechat_iconv_from_internal (charset, string);
 
249
    
 
250
    PYTHON_RETURN_STRING_FREE(result);
 
251
}
 
252
 
 
253
/*
 
254
 * weechat_python_api_gettext: get translated string
 
255
 */
 
256
 
 
257
static PyObject *
 
258
weechat_python_api_gettext (PyObject *self, PyObject *args)
 
259
{
 
260
    char *string;
 
261
    const char *result;
 
262
    
 
263
    /* make C compiler happy */
 
264
    (void) self;
 
265
    
 
266
    if (!python_current_script)
 
267
    {
 
268
        WEECHAT_SCRIPT_MSG_NOT_INIT(PYTHON_CURRENT_SCRIPT_NAME, "gettext");
 
269
        PYTHON_RETURN_EMPTY;
 
270
    }
 
271
    
 
272
    string = NULL;
 
273
    
 
274
    if (!PyArg_ParseTuple (args, "s", &string))
 
275
    {
 
276
        WEECHAT_SCRIPT_MSG_WRONG_ARGS(PYTHON_CURRENT_SCRIPT_NAME, "gettext");
 
277
        PYTHON_RETURN_EMPTY;
 
278
    }
 
279
    
 
280
    result = weechat_gettext (string);
 
281
    
 
282
    PYTHON_RETURN_STRING(result);
 
283
}
 
284
 
 
285
/*
 
286
 * weechat_python_api_ngettext: get translated string with plural form
 
287
 */
 
288
 
 
289
static PyObject *
 
290
weechat_python_api_ngettext (PyObject *self, PyObject *args)
 
291
{
 
292
    char *single, *plural;
 
293
    const char *result;
 
294
    int count;
 
295
    
 
296
    /* make C compiler happy */
 
297
    (void) self;
 
298
    
 
299
    if (!python_current_script)
 
300
    {
 
301
        WEECHAT_SCRIPT_MSG_NOT_INIT(PYTHON_CURRENT_SCRIPT_NAME, "ngettext");
 
302
        PYTHON_RETURN_EMPTY;
 
303
    }
 
304
    
 
305
    single = NULL;
 
306
    plural = NULL;
 
307
    count = 0;
 
308
    
 
309
    if (!PyArg_ParseTuple (args, "ssi", &single, &plural, &count))
 
310
    {
 
311
        WEECHAT_SCRIPT_MSG_WRONG_ARGS(PYTHON_CURRENT_SCRIPT_NAME, "ngettext");
 
312
        PYTHON_RETURN_EMPTY;
 
313
    }
 
314
    
 
315
    result = weechat_ngettext (single, plural, count);
 
316
    
 
317
    PYTHON_RETURN_STRING(result);
 
318
}
 
319
 
 
320
/*
 
321
 * weechat_python_api_string_remove_color: remove WeeChat color codes from string
 
322
 */
 
323
 
 
324
static PyObject *
 
325
weechat_python_api_string_remove_color (PyObject *self, PyObject *args)
 
326
{
 
327
    char *string, *replacement, *result;
 
328
    PyObject *object;
 
329
    
 
330
    /* make C compiler happy */
 
331
    (void) self;
 
332
    
 
333
    if (!python_current_script)
 
334
    {
 
335
        WEECHAT_SCRIPT_MSG_NOT_INIT(PYTHON_CURRENT_SCRIPT_NAME, "string_remove_color");
 
336
        PYTHON_RETURN_EMPTY;
 
337
    }
 
338
    
 
339
    string = NULL;
 
340
    replacement = NULL;
 
341
    
 
342
    if (!PyArg_ParseTuple (args, "ss", &string, &replacement))
 
343
    {
 
344
        WEECHAT_SCRIPT_MSG_WRONG_ARGS(PYTHON_CURRENT_SCRIPT_NAME, "string_remove_color");
 
345
        PYTHON_RETURN_EMPTY;
 
346
    }
 
347
    
 
348
    result = weechat_string_remove_color (string, replacement);
 
349
    
 
350
    PYTHON_RETURN_STRING_FREE(result);
 
351
}
 
352
 
 
353
/*
 
354
 * weechat_python_api_mkdir_home: create a directory in WeeChat home
 
355
 */
 
356
 
 
357
static PyObject *
 
358
weechat_python_api_mkdir_home (PyObject *self, PyObject *args)
 
359
{
 
360
    char *directory;
 
361
    int mode;
 
362
    
 
363
    /* make C compiler happy */
 
364
    (void) self;
 
365
    
 
366
    if (!python_current_script)
 
367
    {
 
368
        WEECHAT_SCRIPT_MSG_NOT_INIT(PYTHON_CURRENT_SCRIPT_NAME, "mkdir_home");
 
369
        PYTHON_RETURN_ERROR;
 
370
    }
 
371
    
 
372
    directory = NULL;
 
373
    mode = 0;
 
374
    
 
375
    if (!PyArg_ParseTuple (args, "si", &directory, &mode))
 
376
    {
 
377
        WEECHAT_SCRIPT_MSG_WRONG_ARGS(PYTHON_CURRENT_SCRIPT_NAME, "mkdir_home");
 
378
        PYTHON_RETURN_ERROR;
 
379
    }
 
380
    
 
381
    if (weechat_mkdir_home (directory, mode))
 
382
        PYTHON_RETURN_OK;
 
383
 
 
384
    PYTHON_RETURN_ERROR;
 
385
}
 
386
 
 
387
/*
 
388
 * weechat_python_api_mkdir: create a directory
 
389
 */
 
390
 
 
391
static PyObject *
 
392
weechat_python_api_mkdir (PyObject *self, PyObject *args)
 
393
{
 
394
    char *directory;
 
395
    int mode;
 
396
    
 
397
    /* make C compiler happy */
 
398
    (void) self;
 
399
    
 
400
    if (!python_current_script)
 
401
    {
 
402
        WEECHAT_SCRIPT_MSG_NOT_INIT(PYTHON_CURRENT_SCRIPT_NAME, "mkdir");
 
403
        PYTHON_RETURN_ERROR;
 
404
    }
 
405
    
 
406
    directory = NULL;
 
407
    mode = 0;
 
408
    
 
409
    if (!PyArg_ParseTuple (args, "si", &directory, &mode))
 
410
    {
 
411
        WEECHAT_SCRIPT_MSG_WRONG_ARGS(PYTHON_CURRENT_SCRIPT_NAME, "mkdir");
 
412
        PYTHON_RETURN_ERROR;
 
413
    }
 
414
    
 
415
    if (weechat_mkdir (directory, mode))
 
416
        PYTHON_RETURN_OK;
 
417
    
 
418
    PYTHON_RETURN_ERROR;
 
419
}
 
420
 
 
421
/*
 
422
 * weechat_python_api_mkdir_parents: create a directory and make parent
 
423
 *                                   directories as needed
 
424
 */
 
425
 
 
426
static PyObject *
 
427
weechat_python_api_mkdir_parents (PyObject *self, PyObject *args)
 
428
{
 
429
    char *directory;
 
430
    int mode;
 
431
    
 
432
    /* make C compiler happy */
 
433
    (void) self;
 
434
    
 
435
    if (!python_current_script)
 
436
    {
 
437
        WEECHAT_SCRIPT_MSG_NOT_INIT(PYTHON_CURRENT_SCRIPT_NAME, "mkdir_parents");
 
438
        PYTHON_RETURN_ERROR;
 
439
    }
 
440
    
 
441
    directory = NULL;
 
442
    mode = 0;
 
443
    
 
444
    if (!PyArg_ParseTuple (args, "si", &directory, &mode))
 
445
    {
 
446
        WEECHAT_SCRIPT_MSG_WRONG_ARGS(PYTHON_CURRENT_SCRIPT_NAME, "mkdir_parents");
 
447
        PYTHON_RETURN_ERROR;
 
448
    }
 
449
    
 
450
    if (weechat_mkdir_parents (directory, mode))
 
451
        PYTHON_RETURN_OK;
 
452
    
 
453
    PYTHON_RETURN_ERROR;
 
454
}
 
455
 
 
456
/*
 
457
 * weechat_python_api_list_new: create a new list
 
458
 */
 
459
 
 
460
static PyObject *
 
461
weechat_python_api_list_new (PyObject *self, PyObject *args)
 
462
{
 
463
    char *result;
 
464
    PyObject *object;
 
465
    
 
466
    /* make C compiler happy */
 
467
    (void) self;
 
468
    (void) args;
 
469
    
 
470
    if (!python_current_script)
 
471
    {
 
472
        WEECHAT_SCRIPT_MSG_NOT_INIT(PYTHON_CURRENT_SCRIPT_NAME, "list_new");
 
473
        PYTHON_RETURN_EMPTY;
 
474
    }
 
475
    
 
476
    result = script_ptr2str (weechat_list_new ());
 
477
    
 
478
    PYTHON_RETURN_STRING_FREE(result);
 
479
}
 
480
 
 
481
/*
 
482
 * weechat_python_api_list_add: add a string to list
 
483
 */
 
484
 
 
485
static PyObject *
 
486
weechat_python_api_list_add (PyObject *self, PyObject *args)
 
487
{
 
488
    char *weelist, *data, *where, *user_data, *result;
 
489
    PyObject *object;
 
490
    
 
491
    /* make C compiler happy */
 
492
    (void) self;
 
493
    
 
494
    if (!python_current_script)
 
495
    {
 
496
        WEECHAT_SCRIPT_MSG_NOT_INIT(PYTHON_CURRENT_SCRIPT_NAME, "list_add");
 
497
        PYTHON_RETURN_EMPTY;
 
498
    }
 
499
    
 
500
    weelist = NULL;
 
501
    data = NULL;
 
502
    where = NULL;
 
503
    user_data = NULL;
 
504
    
 
505
    if (!PyArg_ParseTuple (args, "ssss", &weelist, &data, &where, &user_data))
 
506
    {
 
507
        WEECHAT_SCRIPT_MSG_WRONG_ARGS(PYTHON_CURRENT_SCRIPT_NAME, "list_add");
 
508
        PYTHON_RETURN_EMPTY;
 
509
    }
 
510
    
 
511
    result = script_ptr2str (weechat_list_add (script_str2ptr (weelist),
 
512
                                               data,
 
513
                                               where,
 
514
                                               script_str2ptr (user_data)));
 
515
    
 
516
    PYTHON_RETURN_STRING_FREE(result);
 
517
}
 
518
 
 
519
/*
 
520
 * weechat_python_api_list_search: search a string in list
 
521
 */
 
522
 
 
523
static PyObject *
 
524
weechat_python_api_list_search (PyObject *self, PyObject *args)
 
525
{
 
526
    char *weelist, *data, *result;
 
527
    PyObject *object;
 
528
    
 
529
    /* make C compiler happy */
 
530
    (void) self;
 
531
    
 
532
    if (!python_current_script)
 
533
    {
 
534
        WEECHAT_SCRIPT_MSG_NOT_INIT(PYTHON_CURRENT_SCRIPT_NAME, "list_search");
 
535
        PYTHON_RETURN_EMPTY;
 
536
    }
 
537
    
 
538
    weelist = NULL;
 
539
    data = NULL;
 
540
    
 
541
    if (!PyArg_ParseTuple (args, "ss", &weelist, &data))
 
542
    {
 
543
        WEECHAT_SCRIPT_MSG_WRONG_ARGS(PYTHON_CURRENT_SCRIPT_NAME, "list_search");
 
544
        PYTHON_RETURN_EMPTY;
 
545
    }
 
546
    
 
547
    result = script_ptr2str (weechat_list_search (script_str2ptr (weelist),
 
548
                                                  data));
 
549
    
 
550
    PYTHON_RETURN_STRING_FREE(result);
 
551
}
 
552
 
 
553
/*
 
554
 * weechat_python_api_list_casesearch: search a string in list (ignore case)
 
555
 */
 
556
 
 
557
static PyObject *
 
558
weechat_python_api_list_casesearch (PyObject *self, PyObject *args)
 
559
{
 
560
    char *weelist, *data, *result;
 
561
    PyObject *object;
 
562
    
 
563
    /* make C compiler happy */
 
564
    (void) self;
 
565
    
 
566
    if (!python_current_script)
 
567
    {
 
568
        WEECHAT_SCRIPT_MSG_NOT_INIT(PYTHON_CURRENT_SCRIPT_NAME, "list_casesearch");
 
569
        PYTHON_RETURN_EMPTY;
 
570
    }
 
571
    
 
572
    weelist = NULL;
 
573
    data = NULL;
 
574
    
 
575
    if (!PyArg_ParseTuple (args, "ss", &weelist, &data))
 
576
    {
 
577
        WEECHAT_SCRIPT_MSG_WRONG_ARGS(PYTHON_CURRENT_SCRIPT_NAME, "list_casesearch");
 
578
        PYTHON_RETURN_EMPTY;
 
579
    }
 
580
    
 
581
    result = script_ptr2str (weechat_list_casesearch (script_str2ptr (weelist),
 
582
                                                      data));
 
583
    
 
584
    PYTHON_RETURN_STRING_FREE(result);
 
585
}
 
586
 
 
587
/*
 
588
 * weechat_python_api_list_get: get item by position
 
589
 */
 
590
 
 
591
static PyObject *
 
592
weechat_python_api_list_get (PyObject *self, PyObject *args)
 
593
{
 
594
    char *weelist, *result;
 
595
    int position;
 
596
    PyObject *object;
 
597
    
 
598
    /* make C compiler happy */
 
599
    (void) self;
 
600
    
 
601
    if (!python_current_script)
 
602
    {
 
603
        WEECHAT_SCRIPT_MSG_NOT_INIT(PYTHON_CURRENT_SCRIPT_NAME, "list_get");
 
604
        PYTHON_RETURN_EMPTY;
 
605
    }
 
606
    
 
607
    weelist = NULL;
 
608
    position = 0;
 
609
    
 
610
    if (!PyArg_ParseTuple (args, "si", &weelist, &position))
 
611
    {
 
612
        WEECHAT_SCRIPT_MSG_WRONG_ARGS(PYTHON_CURRENT_SCRIPT_NAME, "list_get");
 
613
        PYTHON_RETURN_EMPTY;
 
614
    }
 
615
    
 
616
    result = script_ptr2str (weechat_list_get (script_str2ptr (weelist),
 
617
                                               position));
 
618
    PYTHON_RETURN_STRING_FREE(result);
 
619
}
 
620
 
 
621
/*
 
622
 * weechat_python_api_list_set: set new value for item
 
623
 */
 
624
 
 
625
static PyObject *
 
626
weechat_python_api_list_set (PyObject *self, PyObject *args)
 
627
{
 
628
    char *item, *new_value;
 
629
    
 
630
    /* make C compiler happy */
 
631
    (void) self;
 
632
    
 
633
    if (!python_current_script)
 
634
    {
 
635
        WEECHAT_SCRIPT_MSG_NOT_INIT(PYTHON_CURRENT_SCRIPT_NAME, "list_set");
 
636
        PYTHON_RETURN_ERROR;
 
637
    }
 
638
    
 
639
    item = NULL;
 
640
    new_value = NULL;
 
641
    
 
642
    if (!PyArg_ParseTuple (args, "ss", &item, &new_value))
 
643
    {
 
644
        WEECHAT_SCRIPT_MSG_WRONG_ARGS(PYTHON_CURRENT_SCRIPT_NAME, "list_set");
 
645
        PYTHON_RETURN_ERROR;
 
646
    }
 
647
    
 
648
    weechat_list_set (script_str2ptr (item),
 
649
                      new_value);
 
650
    
 
651
    PYTHON_RETURN_OK;
 
652
}
 
653
 
 
654
/*
 
655
 * weechat_python_api_list_next: get next item
 
656
 */
 
657
 
 
658
static PyObject *
 
659
weechat_python_api_list_next (PyObject *self, PyObject *args)
 
660
{
 
661
    char *item, *result;
 
662
    PyObject *object;
 
663
    
 
664
    /* make C compiler happy */
 
665
    (void) self;
 
666
    
 
667
    if (!python_current_script)
 
668
    {
 
669
        WEECHAT_SCRIPT_MSG_NOT_INIT(PYTHON_CURRENT_SCRIPT_NAME, "list_next");
 
670
        PYTHON_RETURN_EMPTY;
 
671
    }
 
672
    
 
673
    item = NULL;
 
674
    
 
675
    if (!PyArg_ParseTuple (args, "s", &item))
 
676
    {
 
677
        WEECHAT_SCRIPT_MSG_WRONG_ARGS(PYTHON_CURRENT_SCRIPT_NAME, "list_next");
 
678
        PYTHON_RETURN_EMPTY;
 
679
    }
 
680
    
 
681
    result = script_ptr2str (weechat_list_next (script_str2ptr (item)));
 
682
    
 
683
    PYTHON_RETURN_STRING_FREE(result);
 
684
}
 
685
 
 
686
/*
 
687
 * weechat_python_api_list_prev: get previous item
 
688
 */
 
689
 
 
690
static PyObject *
 
691
weechat_python_api_list_prev (PyObject *self, PyObject *args)
 
692
{
 
693
    char *item, *result;
 
694
    PyObject *object;
 
695
    
 
696
    /* make C compiler happy */
 
697
    (void) self;
 
698
    
 
699
    if (!python_current_script)
 
700
    {
 
701
        WEECHAT_SCRIPT_MSG_NOT_INIT(PYTHON_CURRENT_SCRIPT_NAME, "list_prev");
 
702
        PYTHON_RETURN_EMPTY;
 
703
    }
 
704
    
 
705
    item = NULL;
 
706
    
 
707
    if (!PyArg_ParseTuple (args, "s", &item))
 
708
    {
 
709
        WEECHAT_SCRIPT_MSG_WRONG_ARGS(PYTHON_CURRENT_SCRIPT_NAME, "list_prev");
 
710
        PYTHON_RETURN_EMPTY;
 
711
    }
 
712
    
 
713
    result = script_ptr2str (weechat_list_prev (script_str2ptr (item)));
 
714
    
 
715
    PYTHON_RETURN_STRING_FREE(result);
 
716
}
 
717
 
 
718
/*
 
719
 * weechat_python_api_list_string: get string value of item
 
720
 */
 
721
 
 
722
static PyObject *
 
723
weechat_python_api_list_string (PyObject *self, PyObject *args)
 
724
{
 
725
    char *item;
 
726
    const char *result;
 
727
    
 
728
    /* make C compiler happy */
 
729
    (void) self;
 
730
    
 
731
    if (!python_current_script)
 
732
    {
 
733
        WEECHAT_SCRIPT_MSG_NOT_INIT(PYTHON_CURRENT_SCRIPT_NAME, "list_string");
 
734
        PYTHON_RETURN_EMPTY;
 
735
    }
 
736
    
 
737
    item = NULL;
 
738
    
 
739
    if (!PyArg_ParseTuple (args, "s", &item))
 
740
    {
 
741
        WEECHAT_SCRIPT_MSG_WRONG_ARGS(PYTHON_CURRENT_SCRIPT_NAME, "list_string");
 
742
        PYTHON_RETURN_EMPTY;
 
743
    }
 
744
    
 
745
    result = weechat_list_string (script_str2ptr (item));
 
746
    
 
747
    PYTHON_RETURN_STRING(result);
 
748
}
 
749
 
 
750
/*
 
751
 * weechat_python_api_list_size: get number of elements in list
 
752
 */
 
753
 
 
754
static PyObject *
 
755
weechat_python_api_list_size (PyObject *self, PyObject *args)
 
756
{
 
757
    char *weelist;
 
758
    int size;
 
759
    
 
760
    /* make C compiler happy */
 
761
    (void) self;
 
762
    
 
763
    if (!python_current_script)
 
764
    {
 
765
        WEECHAT_SCRIPT_MSG_NOT_INIT(PYTHON_CURRENT_SCRIPT_NAME, "list_size");
 
766
        PYTHON_RETURN_INT(0);
 
767
    }
 
768
    
 
769
    weelist = NULL;
 
770
    
 
771
    if (!PyArg_ParseTuple (args, "s", &weelist))
 
772
    {
 
773
        WEECHAT_SCRIPT_MSG_WRONG_ARGS(PYTHON_CURRENT_SCRIPT_NAME, "list_size");
 
774
        PYTHON_RETURN_INT(0);
 
775
    }
 
776
    
 
777
    size = weechat_list_size (script_str2ptr (weelist));
 
778
    
 
779
    PYTHON_RETURN_INT(size);
 
780
}
 
781
 
 
782
/*
 
783
 * weechat_python_api_list_remove: remove item from list
 
784
 */
 
785
 
 
786
static PyObject *
 
787
weechat_python_api_list_remove (PyObject *self, PyObject *args)
 
788
{
 
789
    char *weelist, *item;
 
790
    
 
791
    /* make C compiler happy */
 
792
    (void) self;
 
793
    
 
794
    if (!python_current_script)
 
795
    {
 
796
        WEECHAT_SCRIPT_MSG_NOT_INIT(PYTHON_CURRENT_SCRIPT_NAME, "list_remove");
 
797
        PYTHON_RETURN_ERROR;
 
798
    }
 
799
    
 
800
    weelist = NULL;
 
801
    item = NULL;
 
802
    
 
803
    if (!PyArg_ParseTuple (args, "ss", &weelist, &item))
 
804
    {
 
805
        WEECHAT_SCRIPT_MSG_WRONG_ARGS(PYTHON_CURRENT_SCRIPT_NAME, "list_remove");
 
806
        PYTHON_RETURN_ERROR;
 
807
    }
 
808
    
 
809
    weechat_list_remove (script_str2ptr (weelist),
 
810
                         script_str2ptr (item));
 
811
    
 
812
    PYTHON_RETURN_OK;
 
813
}
 
814
 
 
815
/*
 
816
 * weechat_python_api_list_remove_all: remove all items from list
 
817
 */
 
818
 
 
819
static PyObject *
 
820
weechat_python_api_list_remove_all (PyObject *self, PyObject *args)
 
821
{
 
822
    char *weelist;
 
823
    
 
824
    /* make C compiler happy */
 
825
    (void) self;
 
826
    
 
827
    if (!python_current_script)
 
828
    {
 
829
        WEECHAT_SCRIPT_MSG_NOT_INIT(PYTHON_CURRENT_SCRIPT_NAME, "list_remove_all");
 
830
        PYTHON_RETURN_ERROR;
 
831
    }
 
832
    
 
833
    weelist = NULL;
 
834
    
 
835
    if (!PyArg_ParseTuple (args, "s", &weelist))
 
836
    {
 
837
        WEECHAT_SCRIPT_MSG_WRONG_ARGS(PYTHON_CURRENT_SCRIPT_NAME, "list_remove_all");
 
838
        PYTHON_RETURN_ERROR;
 
839
    }
 
840
    
 
841
    weechat_list_remove_all (script_str2ptr (weelist));
 
842
    
 
843
    PYTHON_RETURN_OK;
 
844
}
 
845
 
 
846
/*
 
847
 * weechat_python_api_list_free: free list
 
848
 */
 
849
 
 
850
static PyObject *
 
851
weechat_python_api_list_free (PyObject *self, PyObject *args)
 
852
{
 
853
    char *weelist;
 
854
    
 
855
    /* make C compiler happy */
 
856
    (void) self;
 
857
    
 
858
    if (!python_current_script)
 
859
    {
 
860
        WEECHAT_SCRIPT_MSG_NOT_INIT(PYTHON_CURRENT_SCRIPT_NAME, "list_free");
 
861
        PYTHON_RETURN_ERROR;
 
862
    }
 
863
    
 
864
    weelist = NULL;
 
865
    
 
866
    if (!PyArg_ParseTuple (args, "s", &weelist))
 
867
    {
 
868
        WEECHAT_SCRIPT_MSG_WRONG_ARGS(PYTHON_CURRENT_SCRIPT_NAME, "list_free");
 
869
        PYTHON_RETURN_ERROR;
 
870
    }
 
871
    
 
872
    weechat_list_free (script_str2ptr (weelist));
 
873
    
 
874
    PYTHON_RETURN_OK;
 
875
}
 
876
 
 
877
/*
 
878
 * weechat_python_api_config_reload_cb: callback for config reload
 
879
 */
 
880
 
 
881
int
 
882
weechat_python_api_config_reload_cb (void *data,
 
883
                                     struct t_config_file *config_file)
 
884
{
 
885
    struct t_script_callback *script_callback;
 
886
    char *python_argv[3], empty_arg[1] = { '\0' };
 
887
    int *rc, ret;
 
888
    
 
889
    script_callback = (struct t_script_callback *)data;
 
890
    
 
891
    if (script_callback && script_callback->function && script_callback->function[0])
 
892
    {
 
893
        python_argv[0] = (script_callback->data) ? script_callback->data : empty_arg;
 
894
        python_argv[1] = script_ptr2str (config_file);
 
895
        python_argv[2] = NULL;
 
896
        
 
897
        rc = (int *) weechat_python_exec (script_callback->script,
 
898
                                          WEECHAT_SCRIPT_EXEC_INT,
 
899
                                          script_callback->function,
 
900
                                          python_argv);
 
901
        
 
902
        if (!rc)
 
903
            ret = WEECHAT_CONFIG_READ_FILE_NOT_FOUND;
 
904
        else
 
905
        {
 
906
            ret = *rc;
 
907
            free (rc);
 
908
        }
 
909
        if (python_argv[1])
 
910
            free (python_argv[1]);
 
911
        
 
912
        return ret;
 
913
    }
 
914
    
 
915
    return WEECHAT_CONFIG_READ_FILE_NOT_FOUND;
 
916
}
 
917
 
 
918
/*
 
919
 * weechat_python_api_config_new: create a new configuration file
 
920
 */
 
921
 
 
922
static PyObject *
 
923
weechat_python_api_config_new (PyObject *self, PyObject *args)
 
924
{
 
925
    char *name, *function, *data, *result;
 
926
    PyObject *object;
 
927
    
 
928
    /* make C compiler happy */
 
929
    (void) self;
 
930
    
 
931
    if (!python_current_script)
 
932
    {
 
933
        WEECHAT_SCRIPT_MSG_NOT_INIT(PYTHON_CURRENT_SCRIPT_NAME, "config_new");
 
934
        PYTHON_RETURN_EMPTY;
 
935
    }
 
936
    
 
937
    name = NULL;
 
938
    function = NULL;
 
939
    data = NULL;
 
940
    
 
941
    if (!PyArg_ParseTuple (args, "sss", &name, &function, &data))
 
942
    {
 
943
        WEECHAT_SCRIPT_MSG_WRONG_ARGS(PYTHON_CURRENT_SCRIPT_NAME, "config_new");
 
944
        PYTHON_RETURN_EMPTY;
 
945
    }
 
946
    
 
947
    result = script_ptr2str (script_api_config_new (weechat_python_plugin,
 
948
                                                    python_current_script,
 
949
                                                    name,
 
950
                                                    &weechat_python_api_config_reload_cb,
 
951
                                                    function,
 
952
                                                    data));
 
953
    
 
954
    PYTHON_RETURN_STRING_FREE(result);
 
955
}
 
956
 
 
957
/*
 
958
 * weechat_python_api_config_read_cb: callback for reading option in section
 
959
 */
 
960
 
 
961
int
 
962
weechat_python_api_config_read_cb (void *data,
 
963
                                   struct t_config_file *config_file,
 
964
                                   struct t_config_section *section,
 
965
                                   const char *option_name, const char *value)
 
966
{
 
967
    struct t_script_callback *script_callback;
 
968
    char *python_argv[6], empty_arg[1] = { '\0' };
 
969
    int *rc, ret;
 
970
    
 
971
    script_callback = (struct t_script_callback *)data;
 
972
    
 
973
    if (script_callback && script_callback->function && script_callback->function[0])
 
974
    {
 
975
        python_argv[0] = (script_callback->data) ? script_callback->data : empty_arg;
 
976
        python_argv[1] = script_ptr2str (config_file);
 
977
        python_argv[2] = script_ptr2str (section);
 
978
        python_argv[3] = (option_name) ? (char *)option_name : empty_arg;
 
979
        python_argv[4] = (value) ? (char *)value : empty_arg;
 
980
        python_argv[5] = NULL;
 
981
        
 
982
        rc = (int *) weechat_python_exec (script_callback->script,
 
983
                                          WEECHAT_SCRIPT_EXEC_INT,
 
984
                                          script_callback->function,
 
985
                                          python_argv);
 
986
        
 
987
        if (!rc)
 
988
            ret = WEECHAT_CONFIG_OPTION_SET_ERROR;
 
989
        else
 
990
        {
 
991
            ret = *rc;
 
992
            free (rc);
 
993
        }
 
994
        if (python_argv[1])
 
995
            free (python_argv[1]);
 
996
        if (python_argv[2])
 
997
            free (python_argv[2]);
 
998
        
 
999
        return ret;
 
1000
    }
 
1001
    
 
1002
    return WEECHAT_CONFIG_OPTION_SET_ERROR;
 
1003
}
 
1004
 
 
1005
/*
 
1006
 * weechat_python_api_config_section_write_cb: callback for writing section
 
1007
 */
 
1008
 
 
1009
void
 
1010
weechat_python_api_config_section_write_cb (void *data,
 
1011
                                            struct t_config_file *config_file,
 
1012
                                            const char *section_name)
 
1013
{
 
1014
    struct t_script_callback *script_callback;
 
1015
    char *python_argv[4], empty_arg[1] = { '\0' };
 
1016
    int *rc;
 
1017
    
 
1018
    script_callback = (struct t_script_callback *)data;
 
1019
 
 
1020
    if (script_callback && script_callback->function && script_callback->function[0])
 
1021
    {
 
1022
        python_argv[0] = (script_callback->data) ? script_callback->data : empty_arg;
 
1023
        python_argv[1] = script_ptr2str (config_file);
 
1024
        python_argv[2] = (section_name) ? (char *)section_name : empty_arg;
 
1025
        python_argv[3] = NULL;
 
1026
        
 
1027
        rc = (int *) weechat_python_exec (script_callback->script,
 
1028
                                          WEECHAT_SCRIPT_EXEC_INT,
 
1029
                                          script_callback->function,
 
1030
                                          python_argv);
 
1031
        
 
1032
        if (rc)
 
1033
            free (rc);
 
1034
        if (python_argv[1])
 
1035
            free (python_argv[1]);
 
1036
    }
 
1037
}
 
1038
 
 
1039
/*
 
1040
 * weechat_python_api_config_section_write_default_cb: callback for writing
 
1041
 *                                                     default values for section
 
1042
 */
 
1043
 
 
1044
void
 
1045
weechat_python_api_config_section_write_default_cb (void *data,
 
1046
                                                    struct t_config_file *config_file,
 
1047
                                                    const char *section_name)
 
1048
{
 
1049
    struct t_script_callback *script_callback;
 
1050
    char *python_argv[4], empty_arg[1] = { '\0' };
 
1051
    int *rc;
 
1052
    
 
1053
    script_callback = (struct t_script_callback *)data;
 
1054
 
 
1055
    if (script_callback && script_callback->function && script_callback->function[0])
 
1056
    {
 
1057
        python_argv[0] = (script_callback->data) ? script_callback->data : empty_arg;
 
1058
        python_argv[1] = script_ptr2str (config_file);
 
1059
        python_argv[2] = (section_name) ? (char *)section_name : empty_arg;
 
1060
        python_argv[3] = NULL;
 
1061
        
 
1062
        rc = (int *) weechat_python_exec (script_callback->script,
 
1063
                                          WEECHAT_SCRIPT_EXEC_INT,
 
1064
                                          script_callback->function,
 
1065
                                          python_argv);
 
1066
        
 
1067
        if (rc)
 
1068
            free (rc);
 
1069
        if (python_argv[1])
 
1070
            free (python_argv[1]);
 
1071
    }
 
1072
}
 
1073
 
 
1074
/*
 
1075
 * weechat_python_api_config_section_create_option_cb: callback to create an option
 
1076
 */
 
1077
 
 
1078
int
 
1079
weechat_python_api_config_section_create_option_cb (void *data,
 
1080
                                                    struct t_config_file *config_file,
 
1081
                                                    struct t_config_section *section,
 
1082
                                                    const char *option_name,
 
1083
                                                    const char *value)
 
1084
{
 
1085
    struct t_script_callback *script_callback;
 
1086
    char *python_argv[6], empty_arg[1] = { '\0' };
 
1087
    int *rc, ret;
 
1088
    
 
1089
    script_callback = (struct t_script_callback *)data;
 
1090
    
 
1091
    if (script_callback && script_callback->function && script_callback->function[0])
 
1092
    {
 
1093
        python_argv[0] = (script_callback->data) ? script_callback->data : empty_arg;
 
1094
        python_argv[1] = script_ptr2str (config_file);
 
1095
        python_argv[2] = script_ptr2str (section);
 
1096
        python_argv[3] = (option_name) ? (char *)option_name : empty_arg;
 
1097
        python_argv[4] = (value) ? (char *)value : empty_arg;
 
1098
        python_argv[5] = NULL;
 
1099
 
 
1100
        rc = (int *) weechat_python_exec (script_callback->script,
 
1101
                                          WEECHAT_SCRIPT_EXEC_INT,
 
1102
                                          script_callback->function,
 
1103
                                          python_argv);
 
1104
        
 
1105
        if (!rc)
 
1106
            ret = WEECHAT_CONFIG_OPTION_SET_ERROR;
 
1107
        else
 
1108
        {
 
1109
            ret = *rc;
 
1110
            free (rc);
 
1111
        }
 
1112
        if (python_argv[1])
 
1113
            free (python_argv[1]);
 
1114
        if (python_argv[2])
 
1115
            free (python_argv[2]);
 
1116
        
 
1117
        return ret;
 
1118
    }
 
1119
    
 
1120
    return WEECHAT_CONFIG_OPTION_SET_ERROR;
 
1121
}
 
1122
 
 
1123
/*
 
1124
 * weechat_python_api_config_section_delete_option_cb: callback to delete an option
 
1125
 */
 
1126
 
 
1127
int
 
1128
weechat_python_api_config_section_delete_option_cb (void *data,
 
1129
                                                    struct t_config_file *config_file,
 
1130
                                                    struct t_config_section *section,
 
1131
                                                    struct t_config_option *option)
 
1132
{
 
1133
    struct t_script_callback *script_callback;
 
1134
    char *python_argv[5], empty_arg[1] = { '\0' };
 
1135
    int *rc, ret;
 
1136
    
 
1137
    script_callback = (struct t_script_callback *)data;
 
1138
    
 
1139
    if (script_callback && script_callback->function && script_callback->function[0])
 
1140
    {
 
1141
        python_argv[0] = (script_callback->data) ? script_callback->data : empty_arg;
 
1142
        python_argv[1] = script_ptr2str (config_file);
 
1143
        python_argv[2] = script_ptr2str (section);
 
1144
        python_argv[3] = script_ptr2str (option);
 
1145
        python_argv[4] = NULL;
 
1146
 
 
1147
        rc = (int *) weechat_python_exec (script_callback->script,
 
1148
                                          WEECHAT_SCRIPT_EXEC_INT,
 
1149
                                          script_callback->function,
 
1150
                                          python_argv);
 
1151
        
 
1152
        if (!rc)
 
1153
            ret = WEECHAT_CONFIG_OPTION_UNSET_ERROR;
 
1154
        else
 
1155
        {
 
1156
            ret = *rc;
 
1157
            free (rc);
 
1158
        }
 
1159
        if (python_argv[1])
 
1160
            free (python_argv[1]);
 
1161
        if (python_argv[2])
 
1162
            free (python_argv[2]);
 
1163
        if (python_argv[3])
 
1164
            free (python_argv[3]);
 
1165
        
 
1166
        return ret;
 
1167
    }
 
1168
    
 
1169
    return WEECHAT_CONFIG_OPTION_UNSET_ERROR;
 
1170
}
 
1171
 
 
1172
/*
 
1173
 * weechat_python_api_config_new_section: create a new section in configuration file
 
1174
 */
 
1175
 
 
1176
static PyObject *
 
1177
weechat_python_api_config_new_section (PyObject *self, PyObject *args)
 
1178
{
 
1179
    char *config_file, *name, *function_read, *data_read, *function_write;
 
1180
    char *data_write, *function_write_default, *data_write_default;
 
1181
    char *function_create_option, *data_create_option, *function_delete_option;
 
1182
    char *data_delete_option, *result;
 
1183
    int user_can_add_options, user_can_delete_options;
 
1184
    PyObject *object;
 
1185
    
 
1186
    /* make C compiler happy */
 
1187
    (void) self;
 
1188
    
 
1189
    if (!python_current_script)
 
1190
    {
 
1191
        WEECHAT_SCRIPT_MSG_NOT_INIT(PYTHON_CURRENT_SCRIPT_NAME, "config_new_section");
 
1192
        PYTHON_RETURN_EMPTY;
 
1193
    }
 
1194
    
 
1195
    config_file = NULL;
 
1196
    name = NULL;
 
1197
    user_can_add_options = 0;
 
1198
    user_can_delete_options = 0;
 
1199
    function_read = NULL;
 
1200
    data_read = NULL;
 
1201
    function_write = NULL;
 
1202
    data_write = NULL;
 
1203
    function_write_default = NULL;
 
1204
    data_write_default = NULL;
 
1205
    function_create_option = NULL;
 
1206
    data_create_option = NULL;
 
1207
    function_delete_option = NULL;
 
1208
    data_delete_option = NULL;
 
1209
    
 
1210
    if (!PyArg_ParseTuple (args, "ssiissssssssss", &config_file, &name,
 
1211
                           &user_can_add_options, &user_can_delete_options,
 
1212
                           &function_read, &data_read, &function_write,
 
1213
                           &data_write, &function_write_default,
 
1214
                           &data_write_default, &function_create_option,
 
1215
                           &data_create_option, &function_delete_option,
 
1216
                           &data_delete_option))
 
1217
    {
 
1218
        WEECHAT_SCRIPT_MSG_WRONG_ARGS(PYTHON_CURRENT_SCRIPT_NAME, "config_new_section");
 
1219
        PYTHON_RETURN_EMPTY;
 
1220
    }
 
1221
    
 
1222
    result = script_ptr2str (script_api_config_new_section (weechat_python_plugin,
 
1223
                                                            python_current_script,
 
1224
                                                            script_str2ptr (config_file),
 
1225
                                                            name,
 
1226
                                                            user_can_add_options,
 
1227
                                                            user_can_delete_options,
 
1228
                                                            &weechat_python_api_config_read_cb,
 
1229
                                                            function_read,
 
1230
                                                            data_read,
 
1231
                                                            &weechat_python_api_config_section_write_cb,
 
1232
                                                            function_write,
 
1233
                                                            data_write,
 
1234
                                                            &weechat_python_api_config_section_write_default_cb,
 
1235
                                                            function_write_default,
 
1236
                                                            data_write_default,
 
1237
                                                            &weechat_python_api_config_section_create_option_cb,
 
1238
                                                            function_create_option,
 
1239
                                                            data_create_option,
 
1240
                                                            &weechat_python_api_config_section_delete_option_cb,
 
1241
                                                            function_delete_option,
 
1242
                                                            data_delete_option));
 
1243
    
 
1244
    PYTHON_RETURN_STRING_FREE(result);
 
1245
}
 
1246
 
 
1247
/*
 
1248
 * weechat_python_api_config_search_section: search section in configuration file
 
1249
 */
 
1250
 
 
1251
static PyObject *
 
1252
weechat_python_api_config_search_section (PyObject *self, PyObject *args)
 
1253
{
 
1254
    char *config_file, *section_name, *result;
 
1255
    PyObject *object;
 
1256
    
 
1257
    /* make C compiler happy */
 
1258
    (void) self;
 
1259
    
 
1260
    if (!python_current_script)
 
1261
    {
 
1262
        WEECHAT_SCRIPT_MSG_NOT_INIT(PYTHON_CURRENT_SCRIPT_NAME, "config_search_section");
 
1263
        PYTHON_RETURN_EMPTY;
 
1264
    }
 
1265
    
 
1266
    config_file = NULL;
 
1267
    section_name = NULL;
 
1268
    
 
1269
    if (!PyArg_ParseTuple (args, "ss", &config_file, &section_name))
 
1270
    {
 
1271
        WEECHAT_SCRIPT_MSG_WRONG_ARGS(PYTHON_CURRENT_SCRIPT_NAME, "config_search_section");
 
1272
        PYTHON_RETURN_EMPTY;
 
1273
    }
 
1274
    
 
1275
    result = script_ptr2str (weechat_config_search_section (script_str2ptr (config_file),
 
1276
                                                            section_name));
 
1277
    
 
1278
    PYTHON_RETURN_STRING_FREE(result);
 
1279
}
 
1280
 
 
1281
/*
 
1282
 * weechat_python_api_config_option_check_cb: callback for checking new value
 
1283
 *                                            for option
 
1284
 */
 
1285
 
 
1286
int
 
1287
weechat_python_api_config_option_check_value_cb (void *data,
 
1288
                                                 struct t_config_option *option,
 
1289
                                                 const char *value)
 
1290
{
 
1291
    struct t_script_callback *script_callback;
 
1292
    char *python_argv[4], empty_arg[1] = { '\0' };
 
1293
    int *rc, ret;
 
1294
    
 
1295
    script_callback = (struct t_script_callback *)data;
 
1296
    
 
1297
    if (script_callback && script_callback->function && script_callback->function[0])
 
1298
    {
 
1299
        python_argv[0] = (script_callback->data) ? script_callback->data : empty_arg;
 
1300
        python_argv[1] = script_ptr2str (option);
 
1301
        python_argv[2] = (value) ? (char *)value : empty_arg;
 
1302
        python_argv[3] = NULL;
 
1303
        
 
1304
        rc = (int *) weechat_python_exec (script_callback->script,
 
1305
                                          WEECHAT_SCRIPT_EXEC_INT,
 
1306
                                          script_callback->function,
 
1307
                                          python_argv);
 
1308
        
 
1309
        if (!rc)
 
1310
            ret = 0;
 
1311
        else
 
1312
        {
 
1313
            ret = *rc;
 
1314
            free (rc);
 
1315
        }
 
1316
        if (python_argv[1])
 
1317
            free (python_argv[1]);
 
1318
        
 
1319
        return ret;
 
1320
    }
 
1321
    
 
1322
    return 0;
 
1323
}
 
1324
 
 
1325
/*
 
1326
 * weechat_python_api_config_option_change_cb: callback for option changed
 
1327
 */
 
1328
 
 
1329
void
 
1330
weechat_python_api_config_option_change_cb (void *data,
 
1331
                                            struct t_config_option *option)
 
1332
{
 
1333
    struct t_script_callback *script_callback;
 
1334
    char *python_argv[3], empty_arg[1] = { '\0' };
 
1335
    int *rc;
 
1336
    
 
1337
    script_callback = (struct t_script_callback *)data;
 
1338
 
 
1339
    if (script_callback && script_callback->function && script_callback->function[0])
 
1340
    {
 
1341
        python_argv[0] = (script_callback->data) ? script_callback->data : empty_arg;
 
1342
        python_argv[1] = script_ptr2str (option);
 
1343
        python_argv[2] = NULL;
 
1344
        
 
1345
        rc = (int *) weechat_python_exec (script_callback->script,
 
1346
                                          WEECHAT_SCRIPT_EXEC_INT,
 
1347
                                          script_callback->function,
 
1348
                                          python_argv);
 
1349
        
 
1350
        if (python_argv[1])
 
1351
            free (python_argv[1]);
 
1352
        
 
1353
        if (rc)
 
1354
            free (rc);
 
1355
    }
 
1356
}
 
1357
 
 
1358
/*
 
1359
 * weechat_python_api_config_option_delete_cb: callback when option is deleted
 
1360
 */
 
1361
 
 
1362
void
 
1363
weechat_python_api_config_option_delete_cb (void *data,
 
1364
                                            struct t_config_option *option)
 
1365
{
 
1366
    struct t_script_callback *script_callback;
 
1367
    char *python_argv[3], empty_arg[1] = { '\0' };
 
1368
    int *rc;
 
1369
    
 
1370
    script_callback = (struct t_script_callback *)data;
 
1371
 
 
1372
    if (script_callback && script_callback->function && script_callback->function[0])
 
1373
    {
 
1374
        python_argv[0] = (script_callback->data) ? script_callback->data : empty_arg;
 
1375
        python_argv[1] = script_ptr2str (option);
 
1376
        python_argv[2] = NULL;
 
1377
        
 
1378
        rc = (int *) weechat_python_exec (script_callback->script,
 
1379
                                          WEECHAT_SCRIPT_EXEC_INT,
 
1380
                                          script_callback->function,
 
1381
                                          python_argv);
 
1382
        
 
1383
        if (python_argv[1])
 
1384
            free (python_argv[1]);
 
1385
        
 
1386
        if (rc)
 
1387
            free (rc);
 
1388
    }
 
1389
}
 
1390
 
 
1391
/*
 
1392
 * weechat_python_api_config_new_option: create a new option in section
 
1393
 */
 
1394
 
 
1395
static PyObject *
 
1396
weechat_python_api_config_new_option (PyObject *self, PyObject *args)
 
1397
{
 
1398
    char *config_file, *section, *name, *type, *description, *string_values;
 
1399
    char *default_value, *value, *result;
 
1400
    char *function_check_value, *data_check_value, *function_change;
 
1401
    char *data_change, *function_delete, *data_delete;
 
1402
    int min, max, null_value_allowed;
 
1403
    PyObject *object;
 
1404
    
 
1405
    /* make C compiler happy */
 
1406
    (void) self;
 
1407
    
 
1408
    if (!python_current_script)
 
1409
    {
 
1410
        WEECHAT_SCRIPT_MSG_NOT_INIT(PYTHON_CURRENT_SCRIPT_NAME, "config_new_option");
 
1411
        PYTHON_RETURN_EMPTY;
 
1412
    }
 
1413
    
 
1414
    config_file = NULL;
 
1415
    section = NULL;
 
1416
    name = NULL;
 
1417
    type = NULL;
 
1418
    description = NULL;
 
1419
    string_values = NULL;
 
1420
    default_value = NULL;
 
1421
    value = NULL;
 
1422
    function_check_value = NULL;
 
1423
    data_check_value = NULL;
 
1424
    function_change = NULL;
 
1425
    data_change = NULL;
 
1426
    function_delete = NULL;
 
1427
    data_delete = NULL;
 
1428
    
 
1429
    if (!PyArg_ParseTuple (args, "ssssssiississssss", &config_file, &section, &name,
 
1430
                           &type, &description, &string_values, &min, &max,
 
1431
                           &default_value, &value, &null_value_allowed,
 
1432
                           &function_check_value, &data_check_value,
 
1433
                           &function_change, &data_change, &function_delete,
 
1434
                           &data_delete))
 
1435
    {
 
1436
        WEECHAT_SCRIPT_MSG_WRONG_ARGS(PYTHON_CURRENT_SCRIPT_NAME, "config_new_option");
 
1437
        PYTHON_RETURN_EMPTY;
 
1438
    }
 
1439
    
 
1440
    result = script_ptr2str (script_api_config_new_option (weechat_python_plugin,
 
1441
                                                           python_current_script,
 
1442
                                                           script_str2ptr (config_file),
 
1443
                                                           script_str2ptr (section),
 
1444
                                                           name,
 
1445
                                                           type,
 
1446
                                                           description,
 
1447
                                                           string_values,
 
1448
                                                           min,
 
1449
                                                           max,
 
1450
                                                           default_value,
 
1451
                                                           value,
 
1452
                                                           null_value_allowed,
 
1453
                                                           &weechat_python_api_config_option_check_value_cb,
 
1454
                                                           function_check_value,
 
1455
                                                           data_check_value,
 
1456
                                                           &weechat_python_api_config_option_change_cb,
 
1457
                                                           function_change,
 
1458
                                                           data_change,
 
1459
                                                           &weechat_python_api_config_option_delete_cb,
 
1460
                                                           function_delete,
 
1461
                                                           data_delete));
 
1462
    
 
1463
    PYTHON_RETURN_STRING_FREE(result);
 
1464
}
 
1465
 
 
1466
/*
 
1467
 * weechat_python_api_config_search_option: search option in configuration file or section
 
1468
 */
 
1469
 
 
1470
static PyObject *
 
1471
weechat_python_api_config_search_option (PyObject *self, PyObject *args)
 
1472
{
 
1473
    char *config_file, *section, *option_name, *result;
 
1474
    PyObject *object;
 
1475
    
 
1476
    /* make C compiler happy */
 
1477
    (void) self;
 
1478
    
 
1479
    if (!python_current_script)
 
1480
    {
 
1481
        WEECHAT_SCRIPT_MSG_NOT_INIT(PYTHON_CURRENT_SCRIPT_NAME, "config_search_option");
 
1482
        PYTHON_RETURN_EMPTY;
 
1483
    }
 
1484
    
 
1485
    config_file = NULL;
 
1486
    section = NULL;
 
1487
    option_name = NULL;
 
1488
    
 
1489
    if (!PyArg_ParseTuple (args, "sss", &config_file, &section, &option_name))
 
1490
    {
 
1491
        WEECHAT_SCRIPT_MSG_WRONG_ARGS(PYTHON_CURRENT_SCRIPT_NAME, "config_search_option");
 
1492
        PYTHON_RETURN_EMPTY;
 
1493
    }
 
1494
    
 
1495
    result = script_ptr2str (weechat_config_search_option (script_str2ptr (config_file),
 
1496
                                                           script_str2ptr (section),
 
1497
                                                           option_name));
 
1498
    
 
1499
    PYTHON_RETURN_STRING_FREE(result);
 
1500
}
 
1501
 
 
1502
/*
 
1503
 * weechat_python_api_config_string_to_boolean: return boolean value of a string
 
1504
 */
 
1505
 
 
1506
static PyObject *
 
1507
weechat_python_api_config_string_to_boolean (PyObject *self, PyObject *args)
 
1508
{
 
1509
    char *text;
 
1510
    int value;
 
1511
    
 
1512
    /* make C compiler happy */
 
1513
    (void) self;
 
1514
    
 
1515
    if (!python_current_script)
 
1516
    {
 
1517
        WEECHAT_SCRIPT_MSG_NOT_INIT(PYTHON_CURRENT_SCRIPT_NAME, "config_string_to_boolean");
 
1518
        PYTHON_RETURN_INT(0);
 
1519
    }
 
1520
    
 
1521
    text = NULL;
 
1522
    
 
1523
    if (!PyArg_ParseTuple (args, "s", &text))
 
1524
    {
 
1525
        WEECHAT_SCRIPT_MSG_WRONG_ARGS(PYTHON_CURRENT_SCRIPT_NAME, "config_string_to_boolean");
 
1526
        PYTHON_RETURN_INT(0);
 
1527
    }
 
1528
    
 
1529
    value = weechat_config_string_to_boolean (text);
 
1530
    
 
1531
    PYTHON_RETURN_INT(value);
 
1532
}
 
1533
 
 
1534
/*
 
1535
 * weechat_python_api_config_option_reset: reset an option with default value
 
1536
 */
 
1537
 
 
1538
static PyObject *
 
1539
weechat_python_api_config_option_reset (PyObject *self, PyObject *args)
 
1540
{
 
1541
    char *option;
 
1542
    int run_callback, rc;
 
1543
    
 
1544
    /* make C compiler happy */
 
1545
    (void) self;
 
1546
    
 
1547
    if (!python_current_script)
 
1548
    {
 
1549
        WEECHAT_SCRIPT_MSG_NOT_INIT(PYTHON_CURRENT_SCRIPT_NAME, "config_option_reset");
 
1550
        PYTHON_RETURN_INT(0);
 
1551
    }
 
1552
    
 
1553
    option = NULL;
 
1554
    run_callback = 0;
 
1555
    
 
1556
    if (!PyArg_ParseTuple (args, "si", &option, &run_callback))
 
1557
    {
 
1558
        WEECHAT_SCRIPT_MSG_WRONG_ARGS(PYTHON_CURRENT_SCRIPT_NAME, "config_option_reset");
 
1559
        PYTHON_RETURN_INT(0);
 
1560
    }
 
1561
    
 
1562
    rc = weechat_config_option_reset (script_str2ptr (option),
 
1563
                                      run_callback);
 
1564
    
 
1565
    PYTHON_RETURN_INT(rc);
 
1566
}
 
1567
 
 
1568
/*
 
1569
 * weechat_python_api_config_option_set: set new value for option
 
1570
 */
 
1571
 
 
1572
static PyObject *
 
1573
weechat_python_api_config_option_set (PyObject *self, PyObject *args)
 
1574
{
 
1575
    char *option, *new_value;
 
1576
    int run_callback, rc;
 
1577
    
 
1578
    /* make C compiler happy */
 
1579
    (void) self;
 
1580
    
 
1581
    if (!python_current_script)
 
1582
    {
 
1583
        WEECHAT_SCRIPT_MSG_NOT_INIT(PYTHON_CURRENT_SCRIPT_NAME, "config_option_set");
 
1584
        PYTHON_RETURN_INT(WEECHAT_CONFIG_OPTION_SET_ERROR);
 
1585
    }
 
1586
    
 
1587
    option = NULL;
 
1588
    new_value = NULL;
 
1589
    run_callback = 0;
 
1590
    
 
1591
    if (!PyArg_ParseTuple (args, "ssi", &option, &new_value, &run_callback))
 
1592
    {
 
1593
        WEECHAT_SCRIPT_MSG_WRONG_ARGS(PYTHON_CURRENT_SCRIPT_NAME, "config_option_set");
 
1594
        PYTHON_RETURN_INT(WEECHAT_CONFIG_OPTION_SET_ERROR);
 
1595
    }
 
1596
    
 
1597
    rc = weechat_config_option_set (script_str2ptr (option),
 
1598
                                    new_value,
 
1599
                                    run_callback);
 
1600
    
 
1601
    PYTHON_RETURN_INT(rc);
 
1602
}
 
1603
 
 
1604
/*
 
1605
 * weechat_python_api_config_option_set_null: set null (undefined) value for
 
1606
 *                                            option
 
1607
 */
 
1608
 
 
1609
static PyObject *
 
1610
weechat_python_api_config_option_set_null (PyObject *self, PyObject *args)
 
1611
{
 
1612
    char *option;
 
1613
    int run_callback, rc;
 
1614
    
 
1615
    /* make C compiler happy */
 
1616
    (void) self;
 
1617
    
 
1618
    if (!python_current_script)
 
1619
    {
 
1620
        WEECHAT_SCRIPT_MSG_NOT_INIT(PYTHON_CURRENT_SCRIPT_NAME, "config_option_set_null");
 
1621
        PYTHON_RETURN_INT(WEECHAT_CONFIG_OPTION_SET_ERROR);
 
1622
    }
 
1623
    
 
1624
    option = NULL;
 
1625
    run_callback = 0;
 
1626
    
 
1627
    if (!PyArg_ParseTuple (args, "si", &option, &run_callback))
 
1628
    {
 
1629
        WEECHAT_SCRIPT_MSG_WRONG_ARGS(PYTHON_CURRENT_SCRIPT_NAME, "config_option_set_null");
 
1630
        PYTHON_RETURN_INT(WEECHAT_CONFIG_OPTION_SET_ERROR);
 
1631
    }
 
1632
    
 
1633
    rc = weechat_config_option_set_null (script_str2ptr (option),
 
1634
                                         run_callback);
 
1635
    
 
1636
    PYTHON_RETURN_INT(rc);
 
1637
}
 
1638
 
 
1639
/*
 
1640
 * weechat_python_api_config_option_unset: unset an option
 
1641
 */
 
1642
 
 
1643
static PyObject *
 
1644
weechat_python_api_config_option_unset (PyObject *self, PyObject *args)
 
1645
{
 
1646
    char *option;
 
1647
    int rc;
 
1648
    
 
1649
    /* make C compiler happy */
 
1650
    (void) self;
 
1651
    
 
1652
    if (!python_current_script)
 
1653
    {
 
1654
        WEECHAT_SCRIPT_MSG_NOT_INIT(PYTHON_CURRENT_SCRIPT_NAME, "config_option_unset");
 
1655
        PYTHON_RETURN_INT(WEECHAT_CONFIG_OPTION_UNSET_ERROR);
 
1656
    }
 
1657
    
 
1658
    option = NULL;
 
1659
    
 
1660
    if (!PyArg_ParseTuple (args, "s", &option))
 
1661
    {
 
1662
        WEECHAT_SCRIPT_MSG_WRONG_ARGS(PYTHON_CURRENT_SCRIPT_NAME, "config_option_unset");
 
1663
        PYTHON_RETURN_INT(WEECHAT_CONFIG_OPTION_UNSET_ERROR);
 
1664
    }
 
1665
    
 
1666
    rc = weechat_config_option_unset (script_str2ptr (option));
 
1667
    
 
1668
    PYTHON_RETURN_INT(rc);
 
1669
}
 
1670
 
 
1671
/*
 
1672
 * weechat_python_api_config_option_rename: rename an option
 
1673
 */
 
1674
 
 
1675
static PyObject *
 
1676
weechat_python_api_config_option_rename (PyObject *self, PyObject *args)
 
1677
{
 
1678
    char *option, *new_name;
 
1679
    
 
1680
    /* make C compiler happy */
 
1681
    (void) self;
 
1682
    
 
1683
    if (!python_current_script)
 
1684
    {
 
1685
        WEECHAT_SCRIPT_MSG_NOT_INIT(PYTHON_CURRENT_SCRIPT_NAME, "config_option_rename");
 
1686
        PYTHON_RETURN_ERROR;
 
1687
    }
 
1688
    
 
1689
    option = NULL;
 
1690
    new_name = NULL;
 
1691
    
 
1692
    if (!PyArg_ParseTuple (args, "ss", &option, &new_name))
 
1693
    {
 
1694
        WEECHAT_SCRIPT_MSG_WRONG_ARGS(PYTHON_CURRENT_SCRIPT_NAME, "config_option_rename");
 
1695
        PYTHON_RETURN_ERROR;
 
1696
    }
 
1697
    
 
1698
    weechat_config_option_rename (script_str2ptr (option),
 
1699
                                  new_name);
 
1700
    
 
1701
    PYTHON_RETURN_OK;
 
1702
}
 
1703
 
 
1704
/*
 
1705
 * weechat_python_api_config_option_is_null: return 1 if value of option is null
 
1706
 */
 
1707
 
 
1708
static PyObject *
 
1709
weechat_python_api_config_option_is_null (PyObject *self, PyObject *args)
 
1710
{
 
1711
    char *option;
 
1712
    int value;
 
1713
    
 
1714
    /* make C compiler happy */
 
1715
    (void) self;
 
1716
    
 
1717
    if (!python_current_script)
 
1718
    {
 
1719
        WEECHAT_SCRIPT_MSG_NOT_INIT(PYTHON_CURRENT_SCRIPT_NAME, "config_option_is_null");
 
1720
        PYTHON_RETURN_INT(1);
 
1721
    }
 
1722
    
 
1723
    option = NULL;
 
1724
    
 
1725
    if (!PyArg_ParseTuple (args, "s", &option))
 
1726
    {
 
1727
        WEECHAT_SCRIPT_MSG_WRONG_ARGS(PYTHON_CURRENT_SCRIPT_NAME, "config_option_is_null");
 
1728
        PYTHON_RETURN_INT(1);
 
1729
    }
 
1730
    
 
1731
    value = weechat_config_option_is_null (script_str2ptr (option));
 
1732
    
 
1733
    PYTHON_RETURN_INT(value);
 
1734
}
 
1735
 
 
1736
/*
 
1737
 * weechat_python_api_config_option_default_is_null: return 1 if default value
 
1738
 *                                                   of option is null
 
1739
 */
 
1740
 
 
1741
static PyObject *
 
1742
weechat_python_api_config_option_default_is_null (PyObject *self, PyObject *args)
 
1743
{
 
1744
    char *option;
 
1745
    int value;
 
1746
    
 
1747
    /* make C compiler happy */
 
1748
    (void) self;
 
1749
    
 
1750
    if (!python_current_script)
 
1751
    {
 
1752
        WEECHAT_SCRIPT_MSG_NOT_INIT(PYTHON_CURRENT_SCRIPT_NAME, "config_option_default_is_null");
 
1753
        PYTHON_RETURN_INT(1);
 
1754
    }
 
1755
    
 
1756
    option = NULL;
 
1757
    
 
1758
    if (!PyArg_ParseTuple (args, "s", &option))
 
1759
    {
 
1760
        WEECHAT_SCRIPT_MSG_WRONG_ARGS(PYTHON_CURRENT_SCRIPT_NAME, "config_option_default_is_null");
 
1761
        PYTHON_RETURN_INT(1);
 
1762
    }
 
1763
    
 
1764
    value = weechat_config_option_default_is_null (script_str2ptr (option));
 
1765
    
 
1766
    PYTHON_RETURN_INT(value);
 
1767
}
 
1768
 
 
1769
/*
 
1770
 * weechat_python_api_config_boolean: return boolean value of option
 
1771
 */
 
1772
 
 
1773
static PyObject *
 
1774
weechat_python_api_config_boolean (PyObject *self, PyObject *args)
 
1775
{
 
1776
    char *option;
 
1777
    int value;
 
1778
    
 
1779
    /* make C compiler happy */
 
1780
    (void) self;
 
1781
    
 
1782
    if (!python_current_script)
 
1783
    {
 
1784
        WEECHAT_SCRIPT_MSG_NOT_INIT(PYTHON_CURRENT_SCRIPT_NAME, "config_boolean");
 
1785
        PYTHON_RETURN_INT(0);
 
1786
    }
 
1787
    
 
1788
    option = NULL;
 
1789
    
 
1790
    if (!PyArg_ParseTuple (args, "s", &option))
 
1791
    {
 
1792
        WEECHAT_SCRIPT_MSG_WRONG_ARGS(PYTHON_CURRENT_SCRIPT_NAME, "config_boolean");
 
1793
        PYTHON_RETURN_INT(0);
 
1794
    }
 
1795
    
 
1796
    value = weechat_config_boolean (script_str2ptr (option));
 
1797
    
 
1798
    PYTHON_RETURN_INT(value);
 
1799
}
 
1800
 
 
1801
/*
 
1802
 * weechat_python_api_config_boolean_default: return default boolean value of option
 
1803
 */
 
1804
 
 
1805
static PyObject *
 
1806
weechat_python_api_config_boolean_default (PyObject *self, PyObject *args)
 
1807
{
 
1808
    char *option;
 
1809
    int value;
 
1810
    
 
1811
    /* make C compiler happy */
 
1812
    (void) self;
 
1813
    
 
1814
    if (!python_current_script)
 
1815
    {
 
1816
        WEECHAT_SCRIPT_MSG_NOT_INIT(PYTHON_CURRENT_SCRIPT_NAME, "config_boolean_default");
 
1817
        PYTHON_RETURN_INT(0);
 
1818
    }
 
1819
    
 
1820
    option = NULL;
 
1821
    
 
1822
    if (!PyArg_ParseTuple (args, "s", &option))
 
1823
    {
 
1824
        WEECHAT_SCRIPT_MSG_WRONG_ARGS(PYTHON_CURRENT_SCRIPT_NAME, "config_boolean_default");
 
1825
        PYTHON_RETURN_INT(0);
 
1826
    }
 
1827
    
 
1828
    value = weechat_config_boolean_default (script_str2ptr (option));
 
1829
    
 
1830
    PYTHON_RETURN_INT(value);
 
1831
}
 
1832
 
 
1833
/*
 
1834
 * weechat_python_api_config_integer: return integer value of option
 
1835
 */
 
1836
 
 
1837
static PyObject *
 
1838
weechat_python_api_config_integer (PyObject *self, PyObject *args)
 
1839
{
 
1840
    char *option;
 
1841
    int value;
 
1842
    
 
1843
    /* make C compiler happy */
 
1844
    (void) self;
 
1845
    
 
1846
    if (!python_current_script)
 
1847
    {
 
1848
        WEECHAT_SCRIPT_MSG_NOT_INIT(PYTHON_CURRENT_SCRIPT_NAME, "config_integer");
 
1849
        PYTHON_RETURN_INT(0);
 
1850
    }
 
1851
    
 
1852
    option = NULL;
 
1853
    
 
1854
    if (!PyArg_ParseTuple (args, "s", &option))
 
1855
    {
 
1856
        WEECHAT_SCRIPT_MSG_WRONG_ARGS(PYTHON_CURRENT_SCRIPT_NAME, "config_integer");
 
1857
        PYTHON_RETURN_INT(0);
 
1858
    }
 
1859
    
 
1860
    value = weechat_config_integer (script_str2ptr (option));
 
1861
    
 
1862
    PYTHON_RETURN_INT(value);
 
1863
}
 
1864
 
 
1865
/*
 
1866
 * weechat_python_api_config_integer_default: return default integer value of option
 
1867
 */
 
1868
 
 
1869
static PyObject *
 
1870
weechat_python_api_config_integer_default (PyObject *self, PyObject *args)
 
1871
{
 
1872
    char *option;
 
1873
    int value;
 
1874
    
 
1875
    /* make C compiler happy */
 
1876
    (void) self;
 
1877
    
 
1878
    if (!python_current_script)
 
1879
    {
 
1880
        WEECHAT_SCRIPT_MSG_NOT_INIT(PYTHON_CURRENT_SCRIPT_NAME, "config_integer_default");
 
1881
        PYTHON_RETURN_INT(0);
 
1882
    }
 
1883
    
 
1884
    option = NULL;
 
1885
    
 
1886
    if (!PyArg_ParseTuple (args, "s", &option))
 
1887
    {
 
1888
        WEECHAT_SCRIPT_MSG_WRONG_ARGS(PYTHON_CURRENT_SCRIPT_NAME, "config_integer_default");
 
1889
        PYTHON_RETURN_INT(0);
 
1890
    }
 
1891
    
 
1892
    value = weechat_config_integer_default (script_str2ptr (option));
 
1893
    
 
1894
    PYTHON_RETURN_INT(value);
 
1895
}
 
1896
 
 
1897
/*
 
1898
 * weechat_python_api_config_string: return string value of option
 
1899
 */
 
1900
 
 
1901
static PyObject *
 
1902
weechat_python_api_config_string (PyObject *self, PyObject *args)
 
1903
{
 
1904
    char *option;
 
1905
    const char *result;
 
1906
    
 
1907
    /* make C compiler happy */
 
1908
    (void) self;
 
1909
    
 
1910
    if (!python_current_script)
 
1911
    {
 
1912
        WEECHAT_SCRIPT_MSG_NOT_INIT(PYTHON_CURRENT_SCRIPT_NAME, "config_string");
 
1913
        PYTHON_RETURN_EMPTY;
 
1914
    }
 
1915
    
 
1916
    option = NULL;
 
1917
    
 
1918
    if (!PyArg_ParseTuple (args, "s", &option))
 
1919
    {
 
1920
        WEECHAT_SCRIPT_MSG_WRONG_ARGS(PYTHON_CURRENT_SCRIPT_NAME, "config_string");
 
1921
        PYTHON_RETURN_EMPTY;
 
1922
    }
 
1923
    
 
1924
    result = weechat_config_string (script_str2ptr (option));
 
1925
    
 
1926
    PYTHON_RETURN_STRING(result);
 
1927
}
 
1928
 
 
1929
/*
 
1930
 * weechat_python_api_config_string_default: return default string value of option
 
1931
 */
 
1932
 
 
1933
static PyObject *
 
1934
weechat_python_api_config_string_default (PyObject *self, PyObject *args)
 
1935
{
 
1936
    char *option;
 
1937
    const char *result;
 
1938
    
 
1939
    /* make C compiler happy */
 
1940
    (void) self;
 
1941
    
 
1942
    if (!python_current_script)
 
1943
    {
 
1944
        WEECHAT_SCRIPT_MSG_NOT_INIT(PYTHON_CURRENT_SCRIPT_NAME, "config_string_default");
 
1945
        PYTHON_RETURN_EMPTY;
 
1946
    }
 
1947
    
 
1948
    option = NULL;
 
1949
    
 
1950
    if (!PyArg_ParseTuple (args, "s", &option))
 
1951
    {
 
1952
        WEECHAT_SCRIPT_MSG_WRONG_ARGS(PYTHON_CURRENT_SCRIPT_NAME, "config_string_default");
 
1953
        PYTHON_RETURN_EMPTY;
 
1954
    }
 
1955
    
 
1956
    result = weechat_config_string_default (script_str2ptr (option));
 
1957
    
 
1958
    PYTHON_RETURN_STRING(result);
 
1959
}
 
1960
 
 
1961
/*
 
1962
 * weechat_python_api_config_color: return color value of option
 
1963
 */
 
1964
 
 
1965
static PyObject *
 
1966
weechat_python_api_config_color (PyObject *self, PyObject *args)
 
1967
{
 
1968
    char *option;
 
1969
    const char *result;
 
1970
    
 
1971
    /* make C compiler happy */
 
1972
    (void) self;
 
1973
    
 
1974
    if (!python_current_script)
 
1975
    {
 
1976
        WEECHAT_SCRIPT_MSG_NOT_INIT(PYTHON_CURRENT_SCRIPT_NAME, "config_color");
 
1977
        PYTHON_RETURN_INT(0);
 
1978
    }
 
1979
    
 
1980
    option = NULL;
 
1981
    
 
1982
    if (!PyArg_ParseTuple (args, "s", &option))
 
1983
    {
 
1984
        WEECHAT_SCRIPT_MSG_WRONG_ARGS(PYTHON_CURRENT_SCRIPT_NAME, "config_color");
 
1985
        PYTHON_RETURN_INT(0);
 
1986
    }
 
1987
    
 
1988
    result = weechat_config_color (script_str2ptr (option));
 
1989
    
 
1990
    PYTHON_RETURN_STRING(result);
 
1991
}
 
1992
 
 
1993
/*
 
1994
 * weechat_python_api_config_color_default: return default color value of option
 
1995
 */
 
1996
 
 
1997
static PyObject *
 
1998
weechat_python_api_config_color_default (PyObject *self, PyObject *args)
 
1999
{
 
2000
    char *option;
 
2001
    const char *result;
 
2002
    
 
2003
    /* make C compiler happy */
 
2004
    (void) self;
 
2005
    
 
2006
    if (!python_current_script)
 
2007
    {
 
2008
        WEECHAT_SCRIPT_MSG_NOT_INIT(PYTHON_CURRENT_SCRIPT_NAME, "config_color_default");
 
2009
        PYTHON_RETURN_INT(0);
 
2010
    }
 
2011
    
 
2012
    option = NULL;
 
2013
    
 
2014
    if (!PyArg_ParseTuple (args, "s", &option))
 
2015
    {
 
2016
        WEECHAT_SCRIPT_MSG_WRONG_ARGS(PYTHON_CURRENT_SCRIPT_NAME, "config_color_default");
 
2017
        PYTHON_RETURN_INT(0);
 
2018
    }
 
2019
    
 
2020
    result = weechat_config_color_default (script_str2ptr (option));
 
2021
    
 
2022
    PYTHON_RETURN_STRING(result);
 
2023
}
 
2024
 
 
2025
/*
 
2026
 * weechat_python_api_config_write_option: write an option in configuration file
 
2027
 */
 
2028
 
 
2029
static PyObject *
 
2030
weechat_python_api_config_write_option (PyObject *self, PyObject *args)
 
2031
{
 
2032
    char *config_file, *option;
 
2033
    
 
2034
    /* make C compiler happy */
 
2035
    (void) self;
 
2036
    
 
2037
    if (!python_current_script)
 
2038
    {
 
2039
        WEECHAT_SCRIPT_MSG_NOT_INIT(PYTHON_CURRENT_SCRIPT_NAME, "config_write_option");
 
2040
        PYTHON_RETURN_ERROR;
 
2041
    }
 
2042
    
 
2043
    config_file = NULL;
 
2044
    option = NULL;
 
2045
    
 
2046
    if (!PyArg_ParseTuple (args, "ss", &config_file, &option))
 
2047
    {
 
2048
        WEECHAT_SCRIPT_MSG_WRONG_ARGS(PYTHON_CURRENT_SCRIPT_NAME, "config_write_option");
 
2049
        PYTHON_RETURN_ERROR;
 
2050
    }
 
2051
    
 
2052
    weechat_config_write_option (script_str2ptr (config_file),
 
2053
                                 script_str2ptr (option));
 
2054
    
 
2055
    PYTHON_RETURN_OK;
 
2056
}
 
2057
 
 
2058
/*
 
2059
 * weechat_python_api_config_write_line: write a line in configuration file
 
2060
 */
 
2061
 
 
2062
static PyObject *
 
2063
weechat_python_api_config_write_line (PyObject *self, PyObject *args)
 
2064
{
 
2065
    char *config_file, *option_name, *value;
 
2066
    
 
2067
    /* make C compiler happy */
 
2068
    (void) self;
 
2069
    
 
2070
    if (!python_current_script)
 
2071
    {
 
2072
        WEECHAT_SCRIPT_MSG_NOT_INIT(PYTHON_CURRENT_SCRIPT_NAME, "config_write_line");
 
2073
        PYTHON_RETURN_ERROR;
 
2074
    }
 
2075
    
 
2076
    config_file = NULL;
 
2077
    option_name = NULL;
 
2078
    value = NULL;
 
2079
    
 
2080
    if (!PyArg_ParseTuple (args, "sss", &config_file, &option_name, &value))
 
2081
    {
 
2082
        WEECHAT_SCRIPT_MSG_WRONG_ARGS(PYTHON_CURRENT_SCRIPT_NAME, "config_write_line");
 
2083
        PYTHON_RETURN_ERROR;
 
2084
    }
 
2085
    
 
2086
    weechat_config_write_line (script_str2ptr (config_file),
 
2087
                               option_name,
 
2088
                               "%s",
 
2089
                               value);
 
2090
    
 
2091
    PYTHON_RETURN_OK;
 
2092
}
 
2093
 
 
2094
/*
 
2095
 * weechat_python_api_config_write: write configuration file
 
2096
 */
 
2097
 
 
2098
static PyObject *
 
2099
weechat_python_api_config_write (PyObject *self, PyObject *args)
 
2100
{
 
2101
    char *config_file;
 
2102
    int rc;
 
2103
    
 
2104
    /* make C compiler happy */
 
2105
    (void) self;
 
2106
    
 
2107
    if (!python_current_script)
 
2108
    {
 
2109
        WEECHAT_SCRIPT_MSG_NOT_INIT(PYTHON_CURRENT_SCRIPT_NAME, "config_write");
 
2110
        PYTHON_RETURN_INT(-1);
 
2111
    }
 
2112
    
 
2113
    config_file = NULL;
 
2114
    
 
2115
    if (!PyArg_ParseTuple (args, "s", &config_file))
 
2116
    {
 
2117
        WEECHAT_SCRIPT_MSG_WRONG_ARGS(PYTHON_CURRENT_SCRIPT_NAME, "config_write");
 
2118
        PYTHON_RETURN_INT(-1);
 
2119
    }
 
2120
    
 
2121
    rc = weechat_config_write (script_str2ptr (config_file));
 
2122
    
 
2123
    PYTHON_RETURN_INT(rc);
 
2124
}
 
2125
 
 
2126
/*
 
2127
 * weechat_python_api_config_read: read configuration file
 
2128
 */
 
2129
 
 
2130
static PyObject *
 
2131
weechat_python_api_config_read (PyObject *self, PyObject *args)
 
2132
{
 
2133
    char *config_file;
 
2134
    int rc;
 
2135
    
 
2136
    /* make C compiler happy */
 
2137
    (void) self;
 
2138
    
 
2139
    if (!python_current_script)
 
2140
    {
 
2141
        WEECHAT_SCRIPT_MSG_NOT_INIT(PYTHON_CURRENT_SCRIPT_NAME, "config_read");
 
2142
        PYTHON_RETURN_INT(-1);
 
2143
    }
 
2144
    
 
2145
    config_file = NULL;
 
2146
    
 
2147
    if (!PyArg_ParseTuple (args, "s", &config_file))
 
2148
    {
 
2149
        WEECHAT_SCRIPT_MSG_WRONG_ARGS(PYTHON_CURRENT_SCRIPT_NAME, "config_read");
 
2150
        PYTHON_RETURN_INT(-1);
 
2151
    }
 
2152
    
 
2153
    rc = weechat_config_read (script_str2ptr (config_file));
 
2154
    
 
2155
    PYTHON_RETURN_INT(rc);
 
2156
}
 
2157
 
 
2158
/*
 
2159
 * weechat_python_api_config_reload: reload configuration file
 
2160
 */
 
2161
 
 
2162
static PyObject *
 
2163
weechat_python_api_config_reload (PyObject *self, PyObject *args)
 
2164
{
 
2165
    char *config_file;
 
2166
    int rc;
 
2167
    
 
2168
    /* make C compiler happy */
 
2169
    (void) self;
 
2170
    
 
2171
    if (!python_current_script)
 
2172
    {
 
2173
        WEECHAT_SCRIPT_MSG_NOT_INIT(PYTHON_CURRENT_SCRIPT_NAME, "config_reload");
 
2174
        PYTHON_RETURN_INT(-1);
 
2175
    }
 
2176
    
 
2177
    config_file = NULL;
 
2178
    
 
2179
    if (!PyArg_ParseTuple (args, "s", &config_file))
 
2180
    {
 
2181
        WEECHAT_SCRIPT_MSG_WRONG_ARGS(PYTHON_CURRENT_SCRIPT_NAME, "config_reload");
 
2182
        PYTHON_RETURN_INT(-1);
 
2183
    }
 
2184
    
 
2185
    rc = weechat_config_reload (script_str2ptr (config_file));
 
2186
    
 
2187
    PYTHON_RETURN_INT(rc);
 
2188
}
 
2189
 
 
2190
/*
 
2191
 * weechat_python_api_config_option_free: free an option in configuration file
 
2192
 */
 
2193
 
 
2194
static PyObject *
 
2195
weechat_python_api_config_option_free (PyObject *self, PyObject *args)
 
2196
{
 
2197
    char *option;
 
2198
    
 
2199
    /* make C compiler happy */
 
2200
    (void) self;
 
2201
    
 
2202
    if (!python_current_script)
 
2203
    {
 
2204
        WEECHAT_SCRIPT_MSG_NOT_INIT(PYTHON_CURRENT_SCRIPT_NAME, "config_option_free");
 
2205
        PYTHON_RETURN_ERROR;
 
2206
    }
 
2207
    
 
2208
    option = NULL;
 
2209
    
 
2210
    if (!PyArg_ParseTuple (args, "s", &option))
 
2211
    {
 
2212
        WEECHAT_SCRIPT_MSG_WRONG_ARGS(PYTHON_CURRENT_SCRIPT_NAME, "config_option_free");
 
2213
        PYTHON_RETURN_ERROR;
 
2214
    }
 
2215
    
 
2216
    script_api_config_option_free (weechat_python_plugin,
 
2217
                                   python_current_script,
 
2218
                                   script_str2ptr (option));
 
2219
    
 
2220
    PYTHON_RETURN_OK;
 
2221
}
 
2222
 
 
2223
/*
 
2224
 * weechat_python_api_config_section_free_options: free all options of a section
 
2225
 *                                                 in configuration file
 
2226
 */
 
2227
 
 
2228
static PyObject *
 
2229
weechat_python_api_config_section_free_options (PyObject *self, PyObject *args)
 
2230
{
 
2231
    char *section;
 
2232
    
 
2233
    /* make C compiler happy */
 
2234
    (void) self;
 
2235
    
 
2236
    if (!python_current_script)
 
2237
    {
 
2238
        WEECHAT_SCRIPT_MSG_NOT_INIT(PYTHON_CURRENT_SCRIPT_NAME, "config_section_free_options");
 
2239
        PYTHON_RETURN_ERROR;
 
2240
    }
 
2241
    
 
2242
    section = NULL;
 
2243
    
 
2244
    if (!PyArg_ParseTuple (args, "s", &section))
 
2245
    {
 
2246
        WEECHAT_SCRIPT_MSG_WRONG_ARGS(PYTHON_CURRENT_SCRIPT_NAME, "config_section_free_options");
 
2247
        PYTHON_RETURN_ERROR;
 
2248
    }
 
2249
    
 
2250
    script_api_config_section_free_options (weechat_python_plugin,
 
2251
                                            python_current_script,
 
2252
                                            script_str2ptr (section));
 
2253
    
 
2254
    PYTHON_RETURN_OK;
 
2255
}
 
2256
 
 
2257
/*
 
2258
 * weechat_python_api_config_section_free: free section in configuration file
 
2259
 */
 
2260
 
 
2261
static PyObject *
 
2262
weechat_python_api_config_section_free (PyObject *self, PyObject *args)
 
2263
{
 
2264
    char *section;
 
2265
    
 
2266
    /* make C compiler happy */
 
2267
    (void) self;
 
2268
    
 
2269
    if (!python_current_script)
 
2270
    {
 
2271
        WEECHAT_SCRIPT_MSG_NOT_INIT(PYTHON_CURRENT_SCRIPT_NAME, "config_section_free");
 
2272
        PYTHON_RETURN_ERROR;
 
2273
    }
 
2274
    
 
2275
    section = NULL;
 
2276
    
 
2277
    if (!PyArg_ParseTuple (args, "s", &section))
 
2278
    {
 
2279
        WEECHAT_SCRIPT_MSG_WRONG_ARGS(PYTHON_CURRENT_SCRIPT_NAME, "config_section_free");
 
2280
        PYTHON_RETURN_ERROR;
 
2281
    }
 
2282
    
 
2283
    script_api_config_section_free (weechat_python_plugin,
 
2284
                                    python_current_script,
 
2285
                                    script_str2ptr (section));
 
2286
    
 
2287
    PYTHON_RETURN_OK;
 
2288
}
 
2289
 
 
2290
/*
 
2291
 * weechat_python_api_config_free: free configuration file
 
2292
 */
 
2293
 
 
2294
static PyObject *
 
2295
weechat_python_api_config_free (PyObject *self, PyObject *args)
 
2296
{
 
2297
    char *config_file;
 
2298
    
 
2299
    /* make C compiler happy */
 
2300
    (void) self;
 
2301
    
 
2302
    if (!python_current_script)
 
2303
    {
 
2304
        WEECHAT_SCRIPT_MSG_NOT_INIT(PYTHON_CURRENT_SCRIPT_NAME, "config_free");
 
2305
        PYTHON_RETURN_ERROR;
 
2306
    }
 
2307
    
 
2308
    config_file = NULL;
 
2309
    
 
2310
    if (!PyArg_ParseTuple (args, "s", &config_file))
 
2311
    {
 
2312
        WEECHAT_SCRIPT_MSG_WRONG_ARGS(PYTHON_CURRENT_SCRIPT_NAME, "config_free");
 
2313
        PYTHON_RETURN_ERROR;
 
2314
    }
 
2315
    
 
2316
    script_api_config_free (weechat_python_plugin,
 
2317
                            python_current_script,
 
2318
                            script_str2ptr (config_file));
 
2319
    
 
2320
    PYTHON_RETURN_OK;
 
2321
}
 
2322
 
 
2323
/*
 
2324
 * weechat_python_api_config_get: get config option
 
2325
 */
 
2326
 
 
2327
static PyObject *
 
2328
weechat_python_api_config_get (PyObject *self, PyObject *args)
 
2329
{
 
2330
    char *option, *result;
 
2331
    PyObject *object;
 
2332
    
 
2333
    /* make C compiler happy */
 
2334
    (void) self;
 
2335
    
 
2336
    if (!python_current_script)
 
2337
    {
 
2338
        WEECHAT_SCRIPT_MSG_NOT_INIT(PYTHON_CURRENT_SCRIPT_NAME, "config_get");
 
2339
        PYTHON_RETURN_EMPTY;
 
2340
    }
 
2341
    
 
2342
    option = NULL;
 
2343
    
 
2344
    if (!PyArg_ParseTuple (args, "s", &option))
 
2345
    {
 
2346
        WEECHAT_SCRIPT_MSG_WRONG_ARGS(PYTHON_CURRENT_SCRIPT_NAME, "config_get");
 
2347
        PYTHON_RETURN_EMPTY;
 
2348
    }
 
2349
    
 
2350
    result = script_ptr2str (weechat_config_get (option));
 
2351
    
 
2352
    PYTHON_RETURN_STRING_FREE(result);
 
2353
}
 
2354
 
 
2355
/*
 
2356
 * weechat_python_api_config_get_plugin: get value of a plugin option
 
2357
 */
 
2358
 
 
2359
static PyObject *
 
2360
weechat_python_api_config_get_plugin (PyObject *self, PyObject *args)
 
2361
{
 
2362
    char *option;
 
2363
    const char *result;
 
2364
    
 
2365
    /* make C compiler happy */
 
2366
    (void) self;
 
2367
    
 
2368
    if (!python_current_script)
 
2369
    {
 
2370
        WEECHAT_SCRIPT_MSG_NOT_INIT(PYTHON_CURRENT_SCRIPT_NAME, "config_get_plugin");
 
2371
        PYTHON_RETURN_EMPTY;
 
2372
    }
 
2373
    
 
2374
    option = NULL;
 
2375
    
 
2376
    if (!PyArg_ParseTuple (args, "s", &option))
 
2377
    {
 
2378
        WEECHAT_SCRIPT_MSG_WRONG_ARGS(PYTHON_CURRENT_SCRIPT_NAME, "config_get_plugin");
 
2379
        PYTHON_RETURN_EMPTY;
 
2380
    }
 
2381
    
 
2382
    result = script_api_config_get_plugin (weechat_python_plugin,
 
2383
                                           python_current_script,
 
2384
                                           option);
 
2385
    
 
2386
    PYTHON_RETURN_STRING(result);
 
2387
}
 
2388
 
 
2389
/*
 
2390
 * weechat_python_api_config_is_set_plugin: check if a plugin option is set
 
2391
 */
 
2392
 
 
2393
static PyObject *
 
2394
weechat_python_api_config_is_set_plugin (PyObject *self, PyObject *args)
 
2395
{
 
2396
    char *option;
 
2397
    int rc;
 
2398
    
 
2399
    /* make C compiler happy */
 
2400
    (void) self;
 
2401
    
 
2402
    if (!python_current_script)
 
2403
    {
 
2404
        WEECHAT_SCRIPT_MSG_NOT_INIT(PYTHON_CURRENT_SCRIPT_NAME, "config_is_set_plugin");
 
2405
        PYTHON_RETURN_INT(0);
 
2406
    }
 
2407
    
 
2408
    option = NULL;
 
2409
    
 
2410
    if (!PyArg_ParseTuple (args, "s", &option))
 
2411
    {
 
2412
        WEECHAT_SCRIPT_MSG_WRONG_ARGS(PYTHON_CURRENT_SCRIPT_NAME, "config_is_set_plugin");
 
2413
        PYTHON_RETURN_INT(WEECHAT_CONFIG_OPTION_SET_ERROR);
 
2414
    }
 
2415
    
 
2416
    rc = script_api_config_is_set_plugin (weechat_python_plugin,
 
2417
                                          python_current_script,
 
2418
                                          option);
 
2419
    
 
2420
    PYTHON_RETURN_INT(rc);
 
2421
}
 
2422
 
 
2423
/*
 
2424
 * weechat_python_api_config_set_plugin: set value of a plugin option
 
2425
 */
 
2426
 
 
2427
static PyObject *
 
2428
weechat_python_api_config_set_plugin (PyObject *self, PyObject *args)
 
2429
{
 
2430
    char *option, *value;
 
2431
    int rc;
 
2432
    
 
2433
    /* make C compiler happy */
 
2434
    (void) self;
 
2435
    
 
2436
    if (!python_current_script)
 
2437
    {
 
2438
        WEECHAT_SCRIPT_MSG_NOT_INIT(PYTHON_CURRENT_SCRIPT_NAME, "config_set_plugin");
 
2439
        PYTHON_RETURN_INT(WEECHAT_CONFIG_OPTION_SET_ERROR);
 
2440
    }
 
2441
    
 
2442
    option = NULL;
 
2443
    value = NULL;
 
2444
    
 
2445
    if (!PyArg_ParseTuple (args, "ss", &option, &value))
 
2446
    {
 
2447
        WEECHAT_SCRIPT_MSG_WRONG_ARGS(PYTHON_CURRENT_SCRIPT_NAME, "config_set_plugin");
 
2448
        PYTHON_RETURN_INT(WEECHAT_CONFIG_OPTION_SET_ERROR);
 
2449
    }
 
2450
    
 
2451
    rc = script_api_config_set_plugin (weechat_python_plugin,
 
2452
                                       python_current_script,
 
2453
                                       option,
 
2454
                                       value);
 
2455
    
 
2456
    PYTHON_RETURN_INT(rc);
 
2457
}
 
2458
 
 
2459
/*
 
2460
 * weechat_python_api_config_unset_plugin: unset plugin option
 
2461
 */
 
2462
 
 
2463
static PyObject *
 
2464
weechat_python_api_config_unset_plugin (PyObject *self, PyObject *args)
 
2465
{
 
2466
    char *option;
 
2467
    int rc;
 
2468
    
 
2469
    /* make C compiler happy */
 
2470
    (void) self;
 
2471
    
 
2472
    if (!python_current_script)
 
2473
    {
 
2474
        WEECHAT_SCRIPT_MSG_NOT_INIT(PYTHON_CURRENT_SCRIPT_NAME, "config_unset_plugin");
 
2475
        PYTHON_RETURN_INT(WEECHAT_CONFIG_OPTION_UNSET_ERROR);
 
2476
    }
 
2477
    
 
2478
    option = NULL;
 
2479
    
 
2480
    if (!PyArg_ParseTuple (args, "s", &option))
 
2481
    {
 
2482
        WEECHAT_SCRIPT_MSG_WRONG_ARGS(PYTHON_CURRENT_SCRIPT_NAME, "config_unset_plugin");
 
2483
        PYTHON_RETURN_INT(WEECHAT_CONFIG_OPTION_UNSET_ERROR);
 
2484
    }
 
2485
    
 
2486
    rc = script_api_config_unset_plugin (weechat_python_plugin,
 
2487
                                         python_current_script,
 
2488
                                         option);
 
2489
    
 
2490
    PYTHON_RETURN_INT(rc);
 
2491
}
 
2492
 
 
2493
/*
 
2494
 * weechat_python_api_prefix: get a prefix, used for display
 
2495
 */
 
2496
 
 
2497
static PyObject *
 
2498
weechat_python_api_prefix (PyObject *self, PyObject *args)
 
2499
{
 
2500
    char *prefix;
 
2501
    const char *result;
 
2502
    
 
2503
    /* make C compiler happy */
 
2504
    (void) self;
 
2505
    
 
2506
    if (!python_current_script)
 
2507
    {
 
2508
        WEECHAT_SCRIPT_MSG_NOT_INIT(PYTHON_CURRENT_SCRIPT_NAME, "prefix");
 
2509
        PYTHON_RETURN_EMPTY;
 
2510
    }
 
2511
    
 
2512
    prefix = NULL;
 
2513
    
 
2514
    if (!PyArg_ParseTuple (args, "s", &prefix))
 
2515
    {
 
2516
        WEECHAT_SCRIPT_MSG_WRONG_ARGS(PYTHON_CURRENT_SCRIPT_NAME, "prefix");
 
2517
        PYTHON_RETURN_EMPTY;
 
2518
    }
 
2519
    
 
2520
    result = weechat_prefix (prefix);
 
2521
    
 
2522
    PYTHON_RETURN_STRING(result);
 
2523
}
 
2524
 
 
2525
/*
 
2526
 * weechat_python_api_color: get a color code, used for display
 
2527
 */
 
2528
 
 
2529
static PyObject *
 
2530
weechat_python_api_color (PyObject *self, PyObject *args)
 
2531
{
 
2532
    char *color;
 
2533
    const char *result;
 
2534
    
 
2535
    /* make C compiler happy */
 
2536
    (void) self;
 
2537
    
 
2538
    if (!python_current_script)
 
2539
    {
 
2540
        WEECHAT_SCRIPT_MSG_NOT_INIT(PYTHON_CURRENT_SCRIPT_NAME, "color");
 
2541
        PYTHON_RETURN_EMPTY;
 
2542
    }
 
2543
    
 
2544
    color = NULL;
 
2545
    
 
2546
    if (!PyArg_ParseTuple (args, "s", &color))
 
2547
    {
 
2548
        WEECHAT_SCRIPT_MSG_WRONG_ARGS(PYTHON_CURRENT_SCRIPT_NAME, "color");
 
2549
        PYTHON_RETURN_EMPTY;
 
2550
    }
 
2551
    
 
2552
    result = weechat_color (color);
 
2553
    
 
2554
    PYTHON_RETURN_STRING(result);
 
2555
}
 
2556
 
 
2557
/*
 
2558
 * weechat_python_api_prnt: print message in a buffer
 
2559
 */
 
2560
 
 
2561
static PyObject *
 
2562
weechat_python_api_prnt (PyObject *self, PyObject *args)
 
2563
{
 
2564
    char *buffer, *message;
 
2565
    
 
2566
    /* make C compiler happy */
 
2567
    (void) self;
 
2568
    
 
2569
    buffer = NULL;
 
2570
    message = NULL;
 
2571
    
 
2572
    if (!PyArg_ParseTuple (args, "ss", &buffer, &message))
 
2573
    {
 
2574
        WEECHAT_SCRIPT_MSG_WRONG_ARGS(PYTHON_CURRENT_SCRIPT_NAME, "prnt");
 
2575
        PYTHON_RETURN_ERROR;
 
2576
    }
 
2577
    
 
2578
    script_api_printf (weechat_python_plugin,
 
2579
                       python_current_script,
 
2580
                       script_str2ptr (buffer),
 
2581
                       "%s", message);
 
2582
    
 
2583
    PYTHON_RETURN_OK;
 
2584
}
 
2585
 
 
2586
/*
 
2587
 * weechat_python_api_prnt_date_tags: print message in a buffer with optional
 
2588
 *                                    date and tags
 
2589
 */
 
2590
 
 
2591
static PyObject *
 
2592
weechat_python_api_prnt_date_tags (PyObject *self, PyObject *args)
 
2593
{
 
2594
    char *buffer, *tags, *message;
 
2595
    int date;
 
2596
    
 
2597
    /* make C compiler happy */
 
2598
    (void) self;
 
2599
    
 
2600
    if (!python_current_script)
 
2601
    {
 
2602
        WEECHAT_SCRIPT_MSG_NOT_INIT(PYTHON_CURRENT_SCRIPT_NAME, "prnt_date_tags");
 
2603
        PYTHON_RETURN_ERROR;
 
2604
    }
 
2605
    
 
2606
    buffer = NULL;
 
2607
    date = 0;
 
2608
    tags = NULL;
 
2609
    message = NULL;
 
2610
    
 
2611
    if (!PyArg_ParseTuple (args, "siss", &buffer, &date, &tags, &message))
 
2612
    {
 
2613
        WEECHAT_SCRIPT_MSG_WRONG_ARGS(PYTHON_CURRENT_SCRIPT_NAME, "prnt_date_tags");
 
2614
        PYTHON_RETURN_ERROR;
 
2615
    }
 
2616
    
 
2617
    script_api_printf_date_tags (weechat_python_plugin,
 
2618
                                 python_current_script,
 
2619
                                 script_str2ptr (buffer),
 
2620
                                 date,
 
2621
                                 tags,
 
2622
                                 "%s", message);
 
2623
    
 
2624
    PYTHON_RETURN_OK;
 
2625
}
 
2626
 
 
2627
/*
 
2628
 * weechat_python_api_prnt_y: print message in a buffer with free content
 
2629
 */
 
2630
 
 
2631
static PyObject *
 
2632
weechat_python_api_prnt_y (PyObject *self, PyObject *args)
 
2633
{
 
2634
    char *buffer, *message;
 
2635
    int y;
 
2636
    
 
2637
    /* make C compiler happy */
 
2638
    (void) self;
 
2639
    
 
2640
    if (!python_current_script)
 
2641
    {
 
2642
        WEECHAT_SCRIPT_MSG_NOT_INIT(PYTHON_CURRENT_SCRIPT_NAME, "prnt_y");
 
2643
        PYTHON_RETURN_ERROR;
 
2644
    }
 
2645
    
 
2646
    buffer = NULL;
 
2647
    y = 0;
 
2648
    message = NULL;
 
2649
    
 
2650
    if (!PyArg_ParseTuple (args, "sis", &buffer, &y, &message))
 
2651
    {
 
2652
        WEECHAT_SCRIPT_MSG_WRONG_ARGS(PYTHON_CURRENT_SCRIPT_NAME, "prnt_y");
 
2653
        PYTHON_RETURN_ERROR;
 
2654
    }
 
2655
    
 
2656
    script_api_printf_y (weechat_python_plugin,
 
2657
                          python_current_script,
 
2658
                          script_str2ptr (buffer),
 
2659
                          y,
 
2660
                          "%s", message);
 
2661
    
 
2662
    PYTHON_RETURN_OK;
 
2663
}
 
2664
 
 
2665
/*
 
2666
 * weechat_python_api_log_print: print message in WeeChat log file
 
2667
 */
 
2668
 
 
2669
static PyObject *
 
2670
weechat_python_api_log_print (PyObject *self, PyObject *args)
 
2671
{
 
2672
    char *message;
 
2673
    
 
2674
    /* make C compiler happy */
 
2675
    (void) self;
 
2676
    
 
2677
    if (!python_current_script)
 
2678
    {
 
2679
        WEECHAT_SCRIPT_MSG_NOT_INIT(PYTHON_CURRENT_SCRIPT_NAME, "log_print");
 
2680
        PYTHON_RETURN_ERROR;
 
2681
    }
 
2682
    
 
2683
    message = NULL;
 
2684
    
 
2685
    if (!PyArg_ParseTuple (args, "s", &message))
 
2686
    {
 
2687
        WEECHAT_SCRIPT_MSG_WRONG_ARGS(PYTHON_CURRENT_SCRIPT_NAME, "log_print");
 
2688
        PYTHON_RETURN_ERROR;
 
2689
    }
 
2690
    
 
2691
    script_api_log_printf (weechat_python_plugin,
 
2692
                           python_current_script,
 
2693
                           "%s", message);
 
2694
    
 
2695
    PYTHON_RETURN_OK;
 
2696
}
 
2697
 
 
2698
/*
 
2699
 * weechat_python_api_hook_command_cb: callback for command hooked
 
2700
 */
 
2701
 
 
2702
int
 
2703
weechat_python_api_hook_command_cb (void *data, struct t_gui_buffer *buffer,
 
2704
                                    int argc, char **argv, char **argv_eol)
 
2705
{
 
2706
    struct t_script_callback *script_callback;
 
2707
    char *python_argv[4], empty_arg[1] = { '\0' };
 
2708
    int *rc, ret;
 
2709
 
 
2710
    /* make C compiler happy */
 
2711
    (void) argv;
 
2712
    
 
2713
    script_callback = (struct t_script_callback *)data;
 
2714
 
 
2715
    if (script_callback && script_callback->function && script_callback->function[0])
 
2716
    {
 
2717
        python_argv[0] = (script_callback->data) ? script_callback->data : empty_arg;
 
2718
        python_argv[1] = script_ptr2str (buffer);
 
2719
        python_argv[2] = (argc > 1) ? argv_eol[1] : empty_arg;
 
2720
        python_argv[3] = NULL;
 
2721
        
 
2722
        rc = (int *) weechat_python_exec (script_callback->script,
 
2723
                                          WEECHAT_SCRIPT_EXEC_INT,
 
2724
                                          script_callback->function,
 
2725
                                          python_argv);
 
2726
        
 
2727
        if (!rc)
 
2728
            ret = WEECHAT_RC_ERROR;
 
2729
        else
 
2730
        {
 
2731
            ret = *rc;
 
2732
            free (rc);
 
2733
        }
 
2734
        if (python_argv[1])
 
2735
            free (python_argv[1]);
 
2736
        
 
2737
        return ret;
 
2738
    }
 
2739
    
 
2740
    return WEECHAT_RC_ERROR;
 
2741
}
 
2742
 
 
2743
/*
 
2744
 * weechat_python_api_hook_command: hook a command
 
2745
 */
 
2746
 
 
2747
static PyObject *
 
2748
weechat_python_api_hook_command (PyObject *self, PyObject *args)
 
2749
{
 
2750
    char *command, *description, *arguments, *args_description, *completion;
 
2751
    char *function, *data, *result;
 
2752
    PyObject *object;
 
2753
    
 
2754
    /* make C compiler happy */
 
2755
    (void) self;
 
2756
    
 
2757
    if (!python_current_script)
 
2758
    {
 
2759
        WEECHAT_SCRIPT_MSG_NOT_INIT(PYTHON_CURRENT_SCRIPT_NAME, "hook_command");
 
2760
        PYTHON_RETURN_EMPTY;
 
2761
    }
 
2762
    
 
2763
    command = NULL;
 
2764
    description = NULL;
 
2765
    arguments = NULL;
 
2766
    args_description = NULL;
 
2767
    completion = NULL;
 
2768
    function = NULL;
 
2769
    data = NULL;
 
2770
    
 
2771
    if (!PyArg_ParseTuple (args, "sssssss", &command, &description, &arguments,
 
2772
                           &args_description, &completion, &function, &data))
 
2773
    {
 
2774
        WEECHAT_SCRIPT_MSG_WRONG_ARGS(PYTHON_CURRENT_SCRIPT_NAME, "hook_command");
 
2775
        PYTHON_RETURN_EMPTY;
 
2776
    }
 
2777
    
 
2778
    result = script_ptr2str (script_api_hook_command (weechat_python_plugin,
 
2779
                                                      python_current_script,
 
2780
                                                      command,
 
2781
                                                      description,
 
2782
                                                      arguments,
 
2783
                                                      args_description,
 
2784
                                                      completion,
 
2785
                                                      &weechat_python_api_hook_command_cb,
 
2786
                                                      function,
 
2787
                                                      data));
 
2788
    
 
2789
    PYTHON_RETURN_STRING_FREE(result);
 
2790
}
 
2791
 
 
2792
/*
 
2793
 * weechat_python_api_hook_command_run_cb: callback for command_run hooked
 
2794
 */
 
2795
 
 
2796
int
 
2797
weechat_python_api_hook_command_run_cb (void *data, struct t_gui_buffer *buffer,
 
2798
                                        const char *command)
 
2799
{
 
2800
    struct t_script_callback *script_callback;
 
2801
    char *python_argv[4], empty_arg[1] = { '\0' };
 
2802
    int *rc, ret;
 
2803
    
 
2804
    script_callback = (struct t_script_callback *)data;
 
2805
    
 
2806
    if (script_callback && script_callback->function && script_callback->function[0])
 
2807
    {
 
2808
        python_argv[0] = (script_callback->data) ? script_callback->data : empty_arg;
 
2809
        python_argv[1] = script_ptr2str (buffer);
 
2810
        python_argv[2] = (command) ? (char *)command : empty_arg;
 
2811
        python_argv[3] = NULL;
 
2812
        
 
2813
        rc = (int *) weechat_python_exec (script_callback->script,
 
2814
                                          WEECHAT_SCRIPT_EXEC_INT,
 
2815
                                          script_callback->function,
 
2816
                                          python_argv);
 
2817
        
 
2818
        if (!rc)
 
2819
            ret = WEECHAT_RC_ERROR;
 
2820
        else
 
2821
        {
 
2822
            ret = *rc;
 
2823
            free (rc);
 
2824
        }
 
2825
        if (python_argv[1])
 
2826
            free (python_argv[1]);
 
2827
        
 
2828
        return ret;
 
2829
    }
 
2830
    
 
2831
    return WEECHAT_RC_ERROR;
 
2832
}
 
2833
 
 
2834
/*
 
2835
 * weechat_python_api_hook_command_run: hook a command_run
 
2836
 */
 
2837
 
 
2838
static PyObject *
 
2839
weechat_python_api_hook_command_run (PyObject *self, PyObject *args)
 
2840
{
 
2841
    char *command, *function, *data, *result;
 
2842
    PyObject *object;
 
2843
    
 
2844
    /* make C compiler happy */
 
2845
    (void) self;
 
2846
    
 
2847
    if (!python_current_script)
 
2848
    {
 
2849
        WEECHAT_SCRIPT_MSG_NOT_INIT(PYTHON_CURRENT_SCRIPT_NAME, "hook_command_run");
 
2850
        PYTHON_RETURN_EMPTY;
 
2851
    }
 
2852
    
 
2853
    command = NULL;
 
2854
    function = NULL;
 
2855
    data = NULL;
 
2856
    
 
2857
    if (!PyArg_ParseTuple (args, "sss", &command, &function, &data))
 
2858
    {
 
2859
        WEECHAT_SCRIPT_MSG_WRONG_ARGS(PYTHON_CURRENT_SCRIPT_NAME, "hook_command_run");
 
2860
        PYTHON_RETURN_EMPTY;
 
2861
    }
 
2862
    
 
2863
    result = script_ptr2str (script_api_hook_command_run (weechat_python_plugin,
 
2864
                                                          python_current_script,
 
2865
                                                          command,
 
2866
                                                          &weechat_python_api_hook_command_run_cb,
 
2867
                                                          function,
 
2868
                                                          data));
 
2869
    
 
2870
    PYTHON_RETURN_STRING_FREE(result);
 
2871
}
 
2872
 
 
2873
/*
 
2874
 * weechat_python_api_hook_timer_cb: callback for timer hooked
 
2875
 */
 
2876
 
 
2877
int
 
2878
weechat_python_api_hook_timer_cb (void *data, int remaining_calls)
 
2879
{
 
2880
    struct t_script_callback *script_callback;
 
2881
    char *python_argv[3], str_remaining_calls[32], empty_arg[1] = { '\0' };
 
2882
    int *rc, ret;
 
2883
    
 
2884
    script_callback = (struct t_script_callback *)data;
 
2885
 
 
2886
    if (script_callback && script_callback->function && script_callback->function[0])
 
2887
    {
 
2888
        snprintf (str_remaining_calls, sizeof (str_remaining_calls),
 
2889
                  "%d", remaining_calls);
 
2890
 
 
2891
        python_argv[0] = (script_callback->data) ? script_callback->data : empty_arg;
 
2892
        python_argv[1] = str_remaining_calls;
 
2893
        python_argv[2] = NULL;
 
2894
        
 
2895
        rc = (int *) weechat_python_exec (script_callback->script,
 
2896
                                          WEECHAT_SCRIPT_EXEC_INT,
 
2897
                                          script_callback->function,
 
2898
                                          python_argv);
 
2899
        
 
2900
        if (!rc)
 
2901
            ret = WEECHAT_RC_ERROR;
 
2902
        else
 
2903
        {
 
2904
            ret = *rc;
 
2905
            free (rc);
 
2906
        }
 
2907
        
 
2908
        return ret;
 
2909
    }
 
2910
    
 
2911
    return WEECHAT_RC_ERROR;
 
2912
}
 
2913
 
 
2914
/*
 
2915
 * weechat_python_api_hook_timer: hook a timer
 
2916
 */
 
2917
 
 
2918
static PyObject *
 
2919
weechat_python_api_hook_timer (PyObject *self, PyObject *args)
 
2920
{
 
2921
    int interval, align_second, max_calls;
 
2922
    char *function, *data, *result;
 
2923
    PyObject *object;
 
2924
    
 
2925
    /* make C compiler happy */
 
2926
    (void) self;
 
2927
    
 
2928
    if (!python_current_script)
 
2929
    {
 
2930
        WEECHAT_SCRIPT_MSG_NOT_INIT(PYTHON_CURRENT_SCRIPT_NAME, "hook_timer");
 
2931
        PYTHON_RETURN_EMPTY;
 
2932
    }
 
2933
    
 
2934
    interval = 10;
 
2935
    align_second = 0;
 
2936
    max_calls = 0;
 
2937
    function = NULL;
 
2938
    data = NULL;
 
2939
    
 
2940
    if (!PyArg_ParseTuple (args, "iiiss", &interval, &align_second, &max_calls,
 
2941
                           &function, &data))
 
2942
    {
 
2943
        WEECHAT_SCRIPT_MSG_WRONG_ARGS(PYTHON_CURRENT_SCRIPT_NAME, "hook_timer");
 
2944
        PYTHON_RETURN_EMPTY;
 
2945
    }
 
2946
    
 
2947
    result = script_ptr2str (script_api_hook_timer (weechat_python_plugin,
 
2948
                                                    python_current_script,
 
2949
                                                    interval,
 
2950
                                                    align_second,
 
2951
                                                    max_calls,
 
2952
                                                    &weechat_python_api_hook_timer_cb,
 
2953
                                                    function,
 
2954
                                                    data));
 
2955
    
 
2956
    PYTHON_RETURN_STRING_FREE(result);
 
2957
}
 
2958
 
 
2959
/*
 
2960
 * weechat_python_api_hook_fd_cb: callback for fd hooked
 
2961
 */
 
2962
 
 
2963
int
 
2964
weechat_python_api_hook_fd_cb (void *data, int fd)
 
2965
{
 
2966
    struct t_script_callback *script_callback;
 
2967
    char *python_argv[3], str_fd[32], empty_arg[1] = { '\0' };
 
2968
    int *rc, ret;
 
2969
    
 
2970
    script_callback = (struct t_script_callback *)data;
 
2971
 
 
2972
    if (script_callback && script_callback->function && script_callback->function[0])
 
2973
    {
 
2974
        snprintf (str_fd, sizeof (str_fd), "%d", fd);
 
2975
        
 
2976
        python_argv[0] = (script_callback->data) ? script_callback->data : empty_arg;
 
2977
        python_argv[1] = str_fd;
 
2978
        python_argv[2] = NULL;
 
2979
        
 
2980
        rc = (int *) weechat_python_exec (script_callback->script,
 
2981
                                          WEECHAT_SCRIPT_EXEC_INT,
 
2982
                                          script_callback->function,
 
2983
                                          python_argv);
 
2984
        
 
2985
        if (!rc)
 
2986
            ret = WEECHAT_RC_ERROR;
 
2987
        else
 
2988
        {
 
2989
            ret = *rc;
 
2990
            free (rc);
 
2991
        }
 
2992
        
 
2993
        return ret;
 
2994
    }
 
2995
    
 
2996
    return WEECHAT_RC_ERROR;
 
2997
}
 
2998
 
 
2999
/*
 
3000
 * weechat_python_api_hook_fd: hook a fd
 
3001
 */
 
3002
 
 
3003
static PyObject *
 
3004
weechat_python_api_hook_fd (PyObject *self, PyObject *args)
 
3005
{
 
3006
    int fd, read, write, exception;
 
3007
    char *function, *data, *result;
 
3008
    PyObject *object;
 
3009
    
 
3010
    /* make C compiler happy */
 
3011
    (void) self;
 
3012
    
 
3013
    if (!python_current_script)
 
3014
    {
 
3015
        WEECHAT_SCRIPT_MSG_NOT_INIT(PYTHON_CURRENT_SCRIPT_NAME, "hook_fd");
 
3016
        PYTHON_RETURN_EMPTY;
 
3017
    }
 
3018
    
 
3019
    fd = 0;
 
3020
    read = 0;
 
3021
    write = 0;
 
3022
    exception = 0;
 
3023
    function = NULL;
 
3024
    data = NULL;
 
3025
    
 
3026
    if (!PyArg_ParseTuple (args, "iiiiss", &fd, &read, &write, &exception,
 
3027
                           &function, &data))
 
3028
    {
 
3029
        WEECHAT_SCRIPT_MSG_WRONG_ARGS(PYTHON_CURRENT_SCRIPT_NAME, "hook_fd");
 
3030
        PYTHON_RETURN_EMPTY;
 
3031
    }
 
3032
    
 
3033
    result = script_ptr2str (script_api_hook_fd (weechat_python_plugin,
 
3034
                                                 python_current_script,
 
3035
                                                 fd,
 
3036
                                                 read,
 
3037
                                                 write,
 
3038
                                                 exception,
 
3039
                                                 &weechat_python_api_hook_fd_cb,
 
3040
                                                 function,
 
3041
                                                 data));
 
3042
    
 
3043
    PYTHON_RETURN_STRING_FREE(result);
 
3044
}
 
3045
 
 
3046
/*
 
3047
 * weechat_python_api_hook_process_cb: callback for process hooked
 
3048
 */
 
3049
 
 
3050
int
 
3051
weechat_python_api_hook_process_cb (void *data,
 
3052
                                    const char *command, int return_code,
 
3053
                                    const char *out, const char *err)
 
3054
{
 
3055
    struct t_script_callback *script_callback;
 
3056
    char *python_argv[6], str_rc[32], empty_arg[1] = { '\0' };
 
3057
    int *rc, ret;
 
3058
    
 
3059
    script_callback = (struct t_script_callback *)data;
 
3060
 
 
3061
    if (script_callback && script_callback->function && script_callback->function[0])
 
3062
    {
 
3063
        snprintf (str_rc, sizeof (str_rc), "%d", return_code);
 
3064
        
 
3065
        python_argv[0] = (script_callback->data) ? script_callback->data : empty_arg;
 
3066
        python_argv[1] = (command) ? (char *)command : empty_arg;
 
3067
        python_argv[2] = str_rc;
 
3068
        python_argv[3] = (out) ? (char *)out : empty_arg;
 
3069
        python_argv[4] = (err) ? (char *)err : empty_arg;
 
3070
        python_argv[5] = NULL;
 
3071
        
 
3072
        rc = (int *) weechat_python_exec (script_callback->script,
 
3073
                                          WEECHAT_SCRIPT_EXEC_INT,
 
3074
                                          script_callback->function,
 
3075
                                          python_argv);
 
3076
        
 
3077
        if (!rc)
 
3078
            ret = WEECHAT_RC_ERROR;
 
3079
        else
 
3080
        {
 
3081
            ret = *rc;
 
3082
            free (rc);
 
3083
        }
 
3084
        
 
3085
        return ret;
 
3086
    }
 
3087
    
 
3088
    return WEECHAT_RC_ERROR;
 
3089
}
 
3090
 
 
3091
/*
 
3092
 * weechat_python_api_hook_process: hook a process
 
3093
 */
 
3094
 
 
3095
static PyObject *
 
3096
weechat_python_api_hook_process (PyObject *self, PyObject *args)
 
3097
{
 
3098
    char *command, *function, *data, *result;
 
3099
    int timeout;
 
3100
    PyObject *object;
 
3101
    
 
3102
    /* make C compiler happy */
 
3103
    (void) self;
 
3104
    
 
3105
    if (!python_current_script)
 
3106
    {
 
3107
        WEECHAT_SCRIPT_MSG_NOT_INIT(PYTHON_CURRENT_SCRIPT_NAME, "hook_process");
 
3108
        PYTHON_RETURN_EMPTY;
 
3109
    }
 
3110
    
 
3111
    command = NULL;
 
3112
    timeout = 0;
 
3113
    function = NULL;
 
3114
    data = NULL;
 
3115
    
 
3116
    if (!PyArg_ParseTuple (args, "siss", &command, &timeout, &function, &data))
 
3117
    {
 
3118
        WEECHAT_SCRIPT_MSG_WRONG_ARGS(PYTHON_CURRENT_SCRIPT_NAME, "hook_process");
 
3119
        PYTHON_RETURN_EMPTY;
 
3120
    }
 
3121
    
 
3122
    result = script_ptr2str (script_api_hook_process (weechat_python_plugin,
 
3123
                                                      python_current_script,
 
3124
                                                      command,
 
3125
                                                      timeout,
 
3126
                                                      &weechat_python_api_hook_process_cb,
 
3127
                                                      function,
 
3128
                                                      data));
 
3129
    
 
3130
    PYTHON_RETURN_STRING_FREE(result);
 
3131
}
 
3132
 
 
3133
/*
 
3134
 * weechat_python_api_hook_connect_cb: callback for connect hooked
 
3135
 */
 
3136
 
 
3137
int
 
3138
weechat_python_api_hook_connect_cb (void *data, int status,
 
3139
                                    const char *error, const char *ip_address)
 
3140
{
 
3141
    struct t_script_callback *script_callback;
 
3142
    char *python_argv[5], str_status[32], empty_arg[1] = { '\0' };
 
3143
    int *rc, ret;
 
3144
    
 
3145
    script_callback = (struct t_script_callback *)data;
 
3146
 
 
3147
    if (script_callback && script_callback->function && script_callback->function[0])
 
3148
    {
 
3149
        snprintf (str_status, sizeof (str_status), "%d", status);
 
3150
        
 
3151
        python_argv[0] = (script_callback->data) ? script_callback->data : empty_arg;
 
3152
        python_argv[1] = str_status;
 
3153
        python_argv[2] = (ip_address) ? (char *)ip_address : empty_arg;
 
3154
        python_argv[3] = (error) ? (char *)error : empty_arg;
 
3155
        python_argv[4] = NULL;
 
3156
        
 
3157
        rc = (int *) weechat_python_exec (script_callback->script,
 
3158
                                          WEECHAT_SCRIPT_EXEC_INT,
 
3159
                                          script_callback->function,
 
3160
                                          python_argv);
 
3161
        
 
3162
        if (!rc)
 
3163
            ret = WEECHAT_RC_ERROR;
 
3164
        else
 
3165
        {
 
3166
            ret = *rc;
 
3167
            free (rc);
 
3168
        }
 
3169
        
 
3170
        return ret;
 
3171
    }
 
3172
    
 
3173
    return WEECHAT_RC_ERROR;
 
3174
}
 
3175
 
 
3176
/*
 
3177
 * weechat_python_api_hook_connect: hook a connection
 
3178
 */
 
3179
 
 
3180
static PyObject *
 
3181
weechat_python_api_hook_connect (PyObject *self, PyObject *args)
 
3182
{
 
3183
    char *proxy, *address, *local_hostname, *function, *data, *result;
 
3184
    int port, sock, ipv6;
 
3185
    PyObject *object;
 
3186
    
 
3187
    /* make C compiler happy */
 
3188
    (void) self;
 
3189
    
 
3190
    if (!python_current_script)
 
3191
    {
 
3192
        WEECHAT_SCRIPT_MSG_NOT_INIT(PYTHON_CURRENT_SCRIPT_NAME, "hook_connect");
 
3193
        PYTHON_RETURN_EMPTY;
 
3194
    }
 
3195
    
 
3196
    proxy = NULL;
 
3197
    address = NULL;
 
3198
    port = 0;
 
3199
    sock = 0;
 
3200
    ipv6 = 0;
 
3201
    local_hostname = NULL;
 
3202
    function = NULL;
 
3203
    data = NULL;
 
3204
    
 
3205
    if (!PyArg_ParseTuple (args, "ssiiisss", &proxy, &address, &port, &sock,
 
3206
                           &ipv6, &local_hostname, &function, &data))
 
3207
    {
 
3208
        WEECHAT_SCRIPT_MSG_WRONG_ARGS(PYTHON_CURRENT_SCRIPT_NAME, "hook_connect");
 
3209
        PYTHON_RETURN_EMPTY;
 
3210
    }
 
3211
    
 
3212
    result = script_ptr2str (script_api_hook_connect (weechat_python_plugin,
 
3213
                                                      python_current_script,
 
3214
                                                      proxy,
 
3215
                                                      address,
 
3216
                                                      port,
 
3217
                                                      sock,
 
3218
                                                      ipv6,
 
3219
                                                      NULL, /* gnutls session */
 
3220
                                                      local_hostname,
 
3221
                                                      &weechat_python_api_hook_connect_cb,
 
3222
                                                      function,
 
3223
                                                      data));
 
3224
    
 
3225
    PYTHON_RETURN_STRING_FREE(result);
 
3226
}
 
3227
 
 
3228
/*
 
3229
 * weechat_python_api_hook_print_cb: callback for print hooked
 
3230
 */
 
3231
 
 
3232
int
 
3233
weechat_python_api_hook_print_cb (void *data, struct t_gui_buffer *buffer,
 
3234
                                  time_t date,
 
3235
                                  int tags_count, const char **tags,
 
3236
                                  int displayed, int highlight,
 
3237
                                  const char *prefix, const char *message)
 
3238
{
 
3239
    struct t_script_callback *script_callback;
 
3240
    char *python_argv[9], empty_arg[1] = { '\0' };
 
3241
    static char timebuffer[64];
 
3242
    int *rc, ret;
 
3243
    
 
3244
    /* make C compiler happy */
 
3245
    (void) tags_count;
 
3246
    
 
3247
    script_callback = (struct t_script_callback *)data;
 
3248
 
 
3249
    if (script_callback && script_callback->function && script_callback->function[0])
 
3250
    {
 
3251
        snprintf (timebuffer, sizeof (timebuffer) - 1, "%ld", (long int)date);
 
3252
        
 
3253
        python_argv[0] = (script_callback->data) ? script_callback->data : empty_arg;
 
3254
        python_argv[1] = script_ptr2str (buffer);
 
3255
        python_argv[2] = timebuffer;
 
3256
        python_argv[3] = weechat_string_build_with_split_string (tags, ",");
 
3257
        if (!python_argv[3])
 
3258
            python_argv[3] = strdup ("");
 
3259
        python_argv[4] = (displayed) ? strdup ("1") : strdup ("0");
 
3260
        python_argv[5] = (highlight) ? strdup ("1") : strdup ("0");
 
3261
        python_argv[6] = (prefix) ? (char *)prefix : empty_arg;
 
3262
        python_argv[7] = (message) ? (char *)message : empty_arg;
 
3263
        python_argv[8] = NULL;
 
3264
        
 
3265
        rc = (int *) weechat_python_exec (script_callback->script,
 
3266
                                          WEECHAT_SCRIPT_EXEC_INT,
 
3267
                                          script_callback->function,
 
3268
                                          python_argv);
 
3269
        
 
3270
        if (!rc)
 
3271
            ret = WEECHAT_RC_ERROR;
 
3272
        else
 
3273
        {
 
3274
            ret = *rc;
 
3275
            free (rc);
 
3276
        }
 
3277
        if (python_argv[1])
 
3278
            free (python_argv[1]);
 
3279
        if (python_argv[3])
 
3280
            free (python_argv[3]);
 
3281
        if (python_argv[4])
 
3282
            free (python_argv[4]);
 
3283
        if (python_argv[5])
 
3284
            free (python_argv[5]);
 
3285
        
 
3286
        return ret;
 
3287
    }
 
3288
    
 
3289
    return WEECHAT_RC_ERROR;
 
3290
}
 
3291
 
 
3292
/*
 
3293
 * weechat_python_api_hook_print: hook a print
 
3294
 */
 
3295
 
 
3296
static PyObject *
 
3297
weechat_python_api_hook_print (PyObject *self, PyObject *args)
 
3298
{
 
3299
    char *buffer, *tags, *message, *function, *data, *result;
 
3300
    int strip_colors;
 
3301
    PyObject *object;
 
3302
    
 
3303
    /* make C compiler happy */
 
3304
    (void) self;
 
3305
    
 
3306
    if (!python_current_script)
 
3307
    {
 
3308
        WEECHAT_SCRIPT_MSG_NOT_INIT(PYTHON_CURRENT_SCRIPT_NAME, "hook_print");
 
3309
        PYTHON_RETURN_EMPTY;
 
3310
    }
 
3311
    
 
3312
    buffer = NULL;
 
3313
    tags = NULL;
 
3314
    message = NULL;
 
3315
    strip_colors = 0;
 
3316
    function = NULL;
 
3317
    data = NULL;
 
3318
    
 
3319
    if (!PyArg_ParseTuple (args, "sssiss", &buffer, &tags, &message,
 
3320
                           &strip_colors, &function, &data))
 
3321
    {
 
3322
        WEECHAT_SCRIPT_MSG_WRONG_ARGS(PYTHON_CURRENT_SCRIPT_NAME, "hook_print");
 
3323
        PYTHON_RETURN_EMPTY;
 
3324
    }
 
3325
    
 
3326
    result = script_ptr2str(script_api_hook_print (weechat_python_plugin,
 
3327
                                                   python_current_script,
 
3328
                                                   script_str2ptr (buffer),
 
3329
                                                   tags,
 
3330
                                                   message,
 
3331
                                                   strip_colors,
 
3332
                                                   &weechat_python_api_hook_print_cb,
 
3333
                                                   function,
 
3334
                                                   data));
 
3335
    
 
3336
    PYTHON_RETURN_STRING_FREE(result);
 
3337
}
 
3338
 
 
3339
/*
 
3340
 * weechat_python_api_hook_signal_cb: callback for signal hooked
 
3341
 */
 
3342
 
 
3343
int
 
3344
weechat_python_api_hook_signal_cb (void *data, const char *signal, const char *type_data,
 
3345
                                   void *signal_data)
 
3346
{
 
3347
    struct t_script_callback *script_callback;
 
3348
    char *python_argv[4], empty_arg[1] = { '\0' };
 
3349
    static char value_str[64];
 
3350
    int *rc, ret, free_needed;
 
3351
    
 
3352
    script_callback = (struct t_script_callback *)data;
 
3353
    
 
3354
    if (script_callback && script_callback->function && script_callback->function[0])
 
3355
    {
 
3356
        python_argv[0] = (script_callback->data) ? script_callback->data : empty_arg;
 
3357
        python_argv[1] = (signal) ? (char *)signal : empty_arg;
 
3358
        free_needed = 0;
 
3359
        if (strcmp (type_data, WEECHAT_HOOK_SIGNAL_STRING) == 0)
 
3360
        {
 
3361
            python_argv[2] = (signal_data) ? (char *)signal_data : empty_arg;
 
3362
        }
 
3363
        else if (strcmp (type_data, WEECHAT_HOOK_SIGNAL_INT) == 0)
 
3364
        {
 
3365
            snprintf (value_str, sizeof (value_str) - 1,
 
3366
                      "%d", *((int *)signal_data));
 
3367
            python_argv[2] = value_str;
 
3368
        }
 
3369
        else if (strcmp (type_data, WEECHAT_HOOK_SIGNAL_POINTER) == 0)
 
3370
        {
 
3371
            python_argv[2] = script_ptr2str (signal_data);
 
3372
            free_needed = 1;
 
3373
        }
 
3374
        else
 
3375
            python_argv[2] = empty_arg;
 
3376
        python_argv[3] = NULL;
 
3377
        
 
3378
        rc = (int *) weechat_python_exec (script_callback->script,
 
3379
                                          WEECHAT_SCRIPT_EXEC_INT,
 
3380
                                          script_callback->function,
 
3381
                                          python_argv);
 
3382
        
 
3383
        if (!rc)
 
3384
            ret = WEECHAT_RC_ERROR;
 
3385
        else
 
3386
        {
 
3387
            ret = *rc;
 
3388
            free (rc);
 
3389
        }
 
3390
        if (free_needed && python_argv[2])
 
3391
            free (python_argv[2]);
 
3392
        
 
3393
        return ret;
 
3394
    }
 
3395
    
 
3396
    return WEECHAT_RC_ERROR;
 
3397
}
 
3398
 
 
3399
/*
 
3400
 * weechat_python_api_hook_signal: hook a signal
 
3401
 */
 
3402
 
 
3403
static PyObject *
 
3404
weechat_python_api_hook_signal (PyObject *self, PyObject *args)
 
3405
{
 
3406
    char *signal, *function, *data, *result;
 
3407
    PyObject *object;
 
3408
    
 
3409
    /* make C compiler happy */
 
3410
    (void) self;
 
3411
    
 
3412
    if (!python_current_script)
 
3413
    {
 
3414
        WEECHAT_SCRIPT_MSG_NOT_INIT(PYTHON_CURRENT_SCRIPT_NAME, "hook_signal");
 
3415
        PYTHON_RETURN_EMPTY;
 
3416
    }
 
3417
    
 
3418
    signal = NULL;
 
3419
    function = NULL;
 
3420
    data = NULL;
 
3421
    
 
3422
    if (!PyArg_ParseTuple (args, "sss", &signal, &function, &data))
 
3423
    {
 
3424
        WEECHAT_SCRIPT_MSG_WRONG_ARGS(PYTHON_CURRENT_SCRIPT_NAME, "hook_signal");
 
3425
        PYTHON_RETURN_EMPTY;
 
3426
    }
 
3427
    
 
3428
    result = script_ptr2str (script_api_hook_signal (weechat_python_plugin,
 
3429
                                                     python_current_script,
 
3430
                                                     signal,
 
3431
                                                     &weechat_python_api_hook_signal_cb,
 
3432
                                                     function,
 
3433
                                                     data));
 
3434
    
 
3435
    PYTHON_RETURN_STRING_FREE(result);
 
3436
}
 
3437
 
 
3438
/*
 
3439
 * weechat_python_api_hook_signal_send: send a signal
 
3440
 */
 
3441
 
 
3442
static PyObject *
 
3443
weechat_python_api_hook_signal_send (PyObject *self, PyObject *args)
 
3444
{
 
3445
    char *signal, *type_data, *signal_data, *error;
 
3446
    int number;
 
3447
    
 
3448
    /* make C compiler happy */
 
3449
    (void) self;
 
3450
    
 
3451
    if (!python_current_script)
 
3452
    {
 
3453
        WEECHAT_SCRIPT_MSG_NOT_INIT(PYTHON_CURRENT_SCRIPT_NAME, "hook_signal_send");
 
3454
        PYTHON_RETURN_ERROR;
 
3455
    }
 
3456
    
 
3457
    signal = NULL;
 
3458
    type_data = NULL;
 
3459
    signal_data = NULL;
 
3460
    
 
3461
    if (!PyArg_ParseTuple (args, "sss", &signal, &type_data, &signal_data))
 
3462
    {
 
3463
        WEECHAT_SCRIPT_MSG_WRONG_ARGS(PYTHON_CURRENT_SCRIPT_NAME, "hook_signal_send");
 
3464
        PYTHON_RETURN_ERROR;
 
3465
    }
 
3466
    
 
3467
    if (strcmp (type_data, WEECHAT_HOOK_SIGNAL_STRING) == 0)
 
3468
    {
 
3469
        weechat_hook_signal_send (signal, type_data, signal_data);
 
3470
        PYTHON_RETURN_OK;
 
3471
    }
 
3472
    else if (strcmp (type_data, WEECHAT_HOOK_SIGNAL_INT) == 0)
 
3473
    {
 
3474
        error = NULL;
 
3475
        number = (int)strtol (signal_data, &error, 10);
 
3476
        if (error && !error[0])
 
3477
        {
 
3478
            weechat_hook_signal_send (signal, type_data, &number);
 
3479
        }
 
3480
        PYTHON_RETURN_OK;
 
3481
    }
 
3482
    else if (strcmp (type_data, WEECHAT_HOOK_SIGNAL_POINTER) == 0)
 
3483
    {
 
3484
        weechat_hook_signal_send (signal, type_data,
 
3485
                                  script_str2ptr (signal_data));
 
3486
        PYTHON_RETURN_OK;
 
3487
    }
 
3488
    
 
3489
    PYTHON_RETURN_ERROR;
 
3490
}
 
3491
 
 
3492
/*
 
3493
 * weechat_python_api_hook_config_cb: callback for config option hooked
 
3494
 */
 
3495
 
 
3496
int
 
3497
weechat_python_api_hook_config_cb (void *data, const char *option, const char *value)
 
3498
{
 
3499
    struct t_script_callback *script_callback;
 
3500
    char *python_argv[4], empty_arg[1] = { '\0' };
 
3501
    int *rc, ret;
 
3502
    
 
3503
    script_callback = (struct t_script_callback *)data;
 
3504
 
 
3505
    if (script_callback && script_callback->function && script_callback->function[0])
 
3506
    {
 
3507
        python_argv[0] = (script_callback->data) ? script_callback->data : empty_arg;
 
3508
        python_argv[1] = (option) ? (char *)option : empty_arg;
 
3509
        python_argv[2] = (value) ? (char *)value : empty_arg;
 
3510
        python_argv[3] = NULL;
 
3511
        
 
3512
        rc = (int *) weechat_python_exec (script_callback->script,
 
3513
                                          WEECHAT_SCRIPT_EXEC_INT,
 
3514
                                          script_callback->function,
 
3515
                                          python_argv);
 
3516
        
 
3517
        if (!rc)
 
3518
            ret = WEECHAT_RC_ERROR;
 
3519
        else
 
3520
        {
 
3521
            ret = *rc;
 
3522
            free (rc);
 
3523
        }
 
3524
        
 
3525
        return ret;
 
3526
    }
 
3527
    
 
3528
    return WEECHAT_RC_ERROR;
 
3529
}
 
3530
 
 
3531
/*
 
3532
 * weechat_python_api_hook_config: hook a config option
 
3533
 */
 
3534
 
 
3535
static PyObject *
 
3536
weechat_python_api_hook_config (PyObject *self, PyObject *args)
 
3537
{
 
3538
    char *option, *function, *data, *result;
 
3539
    PyObject *object;
 
3540
    
 
3541
    /* make C compiler happy */
 
3542
    (void) self;
 
3543
    
 
3544
    if (!python_current_script)
 
3545
    {
 
3546
        WEECHAT_SCRIPT_MSG_NOT_INIT(PYTHON_CURRENT_SCRIPT_NAME, "hook_config");
 
3547
        PYTHON_RETURN_EMPTY;
 
3548
    }
 
3549
    
 
3550
    option = NULL;
 
3551
    function = NULL;
 
3552
    data = NULL;
 
3553
    
 
3554
    if (!PyArg_ParseTuple (args, "sss", &option, &function, &data))
 
3555
    {
 
3556
        WEECHAT_SCRIPT_MSG_WRONG_ARGS(PYTHON_CURRENT_SCRIPT_NAME, "hook_config");
 
3557
        PYTHON_RETURN_EMPTY;
 
3558
    }
 
3559
    
 
3560
    result = script_ptr2str(script_api_hook_config (weechat_python_plugin,
 
3561
                                                    python_current_script,
 
3562
                                                    option,
 
3563
                                                    &weechat_python_api_hook_config_cb,
 
3564
                                                    function,
 
3565
                                                    data));
 
3566
    
 
3567
    PYTHON_RETURN_STRING_FREE(result);
 
3568
}
 
3569
 
 
3570
/*
 
3571
 * weechat_python_api_hook_completion_cb: callback for completion hooked
 
3572
 */
 
3573
 
 
3574
int
 
3575
weechat_python_api_hook_completion_cb (void *data, const char *completion_item,
 
3576
                                       struct t_gui_buffer *buffer,
 
3577
                                       struct t_gui_completion *completion)
 
3578
{
 
3579
    struct t_script_callback *script_callback;
 
3580
    char *python_argv[5], empty_arg[1] = { '\0' };
 
3581
    int *rc, ret;
 
3582
    
 
3583
    script_callback = (struct t_script_callback *)data;
 
3584
 
 
3585
    if (script_callback && script_callback->function && script_callback->function[0])
 
3586
    {
 
3587
        python_argv[0] = (script_callback->data) ? script_callback->data : empty_arg;
 
3588
        python_argv[1] = (completion_item) ? (char *)completion_item : empty_arg;
 
3589
        python_argv[2] = script_ptr2str (buffer);
 
3590
        python_argv[3] = script_ptr2str (completion);
 
3591
        python_argv[4] = NULL;
 
3592
        
 
3593
        rc = (int *) weechat_python_exec (script_callback->script,
 
3594
                                          WEECHAT_SCRIPT_EXEC_INT,
 
3595
                                          script_callback->function,
 
3596
                                          python_argv);
 
3597
        
 
3598
        if (!rc)
 
3599
            ret = WEECHAT_RC_ERROR;
 
3600
        else
 
3601
        {
 
3602
            ret = *rc;
 
3603
            free (rc);
 
3604
        }
 
3605
        if (python_argv[2])
 
3606
            free (python_argv[2]);
 
3607
        if (python_argv[3])
 
3608
            free (python_argv[3]);
 
3609
        
 
3610
        return ret;
 
3611
    }
 
3612
    
 
3613
    return WEECHAT_RC_ERROR;
 
3614
}
 
3615
 
 
3616
/*
 
3617
 * weechat_python_api_hook_completion: hook a completion
 
3618
 */
 
3619
 
 
3620
static PyObject *
 
3621
weechat_python_api_hook_completion (PyObject *self, PyObject *args)
 
3622
{
 
3623
    char *completion, *description, *function, *data, *result;
 
3624
    PyObject *object;
 
3625
    
 
3626
    /* make C compiler happy */
 
3627
    (void) self;
 
3628
    
 
3629
    if (!python_current_script)
 
3630
    {
 
3631
        WEECHAT_SCRIPT_MSG_NOT_INIT(PYTHON_CURRENT_SCRIPT_NAME, "hook_completion");
 
3632
        PYTHON_RETURN_EMPTY;
 
3633
    }
 
3634
    
 
3635
    completion = NULL;
 
3636
    description = NULL;
 
3637
    function = NULL;
 
3638
    data = NULL;
 
3639
    
 
3640
    if (!PyArg_ParseTuple (args, "ssss", &completion, &description, &function,
 
3641
                           &data))
 
3642
    {
 
3643
        WEECHAT_SCRIPT_MSG_WRONG_ARGS(PYTHON_CURRENT_SCRIPT_NAME, "hook_completion");
 
3644
        PYTHON_RETURN_EMPTY;
 
3645
    }
 
3646
    
 
3647
    result = script_ptr2str(script_api_hook_completion (weechat_python_plugin,
 
3648
                                                        python_current_script,
 
3649
                                                        completion,
 
3650
                                                        description,
 
3651
                                                        &weechat_python_api_hook_completion_cb,
 
3652
                                                        function,
 
3653
                                                        data));
 
3654
    
 
3655
    PYTHON_RETURN_STRING_FREE(result);
 
3656
}
 
3657
 
 
3658
/*
 
3659
 * weechat_python_api_hook_completion_list_add: add a word to list for a completion
 
3660
 */
 
3661
 
 
3662
static PyObject *
 
3663
weechat_python_api_hook_completion_list_add (PyObject *self, PyObject *args)
 
3664
{
 
3665
    char *completion, *word, *where;
 
3666
    int nick_completion;
 
3667
    
 
3668
    /* make C compiler happy */
 
3669
    (void) self;
 
3670
    
 
3671
    if (!python_current_script)
 
3672
    {
 
3673
        WEECHAT_SCRIPT_MSG_NOT_INIT(PYTHON_CURRENT_SCRIPT_NAME, "hook_completion_list_add");
 
3674
        PYTHON_RETURN_ERROR;
 
3675
    }
 
3676
    
 
3677
    completion = NULL;
 
3678
    word = NULL;
 
3679
    nick_completion = 0;
 
3680
    where = NULL;
 
3681
    
 
3682
    if (!PyArg_ParseTuple (args, "ssis", &completion, &word, &nick_completion,
 
3683
                           &where))
 
3684
    {
 
3685
        WEECHAT_SCRIPT_MSG_WRONG_ARGS(PYTHON_CURRENT_SCRIPT_NAME, "hook_completion_list_add");
 
3686
        PYTHON_RETURN_ERROR;
 
3687
    }
 
3688
    
 
3689
    weechat_hook_completion_list_add (script_str2ptr (completion),
 
3690
                                      word,
 
3691
                                      nick_completion,
 
3692
                                      where);
 
3693
    
 
3694
    PYTHON_RETURN_OK;
 
3695
}
 
3696
 
 
3697
/*
 
3698
 * weechat_python_api_hook_modifier_cb: callback for modifier hooked
 
3699
 */
 
3700
 
 
3701
char *
 
3702
weechat_python_api_hook_modifier_cb (void *data, const char *modifier,
 
3703
                                     const char *modifier_data, const char *string)
 
3704
{
 
3705
    struct t_script_callback *script_callback;
 
3706
    char *python_argv[5], empty_arg[1] = { '\0' };
 
3707
    
 
3708
    script_callback = (struct t_script_callback *)data;
 
3709
    
 
3710
    if (script_callback && script_callback->function && script_callback->function[0])
 
3711
    {
 
3712
        python_argv[0] = (script_callback->data) ? script_callback->data : empty_arg;
 
3713
        python_argv[1] = (modifier) ? (char *)modifier : empty_arg;
 
3714
        python_argv[2] = (modifier_data) ? (char *)modifier_data : empty_arg;
 
3715
        python_argv[3] = (string) ? (char *)string : empty_arg;
 
3716
        python_argv[4] = NULL;
 
3717
        
 
3718
        return (char *)weechat_python_exec (script_callback->script,
 
3719
                                            WEECHAT_SCRIPT_EXEC_STRING,
 
3720
                                            script_callback->function,
 
3721
                                            python_argv);
 
3722
    }
 
3723
    
 
3724
    return NULL;
 
3725
}
 
3726
 
 
3727
/*
 
3728
 * weechat_python_api_hook_modifier: hook a modifier
 
3729
 */
 
3730
 
 
3731
static PyObject *
 
3732
weechat_python_api_hook_modifier (PyObject *self, PyObject *args)
 
3733
{
 
3734
    char *modifier, *function, *data, *result;
 
3735
    PyObject *object;
 
3736
    
 
3737
    /* make C compiler happy */
 
3738
    (void) self;
 
3739
    
 
3740
    if (!python_current_script)
 
3741
    {
 
3742
        WEECHAT_SCRIPT_MSG_NOT_INIT(PYTHON_CURRENT_SCRIPT_NAME, "hook_modifier");
 
3743
        PYTHON_RETURN_EMPTY;
 
3744
    }
 
3745
    
 
3746
    modifier = NULL;
 
3747
    function = NULL;
 
3748
    data = NULL;
 
3749
    
 
3750
    if (!PyArg_ParseTuple (args, "sss", &modifier, &function, &data))
 
3751
    {
 
3752
        WEECHAT_SCRIPT_MSG_WRONG_ARGS(PYTHON_CURRENT_SCRIPT_NAME, "hook_modifier");
 
3753
        PYTHON_RETURN_EMPTY;
 
3754
    }
 
3755
    
 
3756
    result = script_ptr2str(script_api_hook_modifier (weechat_python_plugin,
 
3757
                                                      python_current_script,
 
3758
                                                      modifier,
 
3759
                                                      &weechat_python_api_hook_modifier_cb,
 
3760
                                                      function,
 
3761
                                                      data));
 
3762
    
 
3763
    PYTHON_RETURN_STRING_FREE(result);
 
3764
}
 
3765
 
 
3766
/*
 
3767
 * weechat_python_api_hook_modifier_exec: execute a modifier hook
 
3768
 */
 
3769
 
 
3770
static PyObject *
 
3771
weechat_python_api_hook_modifier_exec (PyObject *self, PyObject *args)
 
3772
{
 
3773
    char *modifier, *modifier_data, *string, *result;
 
3774
    PyObject *object;
 
3775
    
 
3776
    /* make C compiler happy */
 
3777
    (void) self;
 
3778
    
 
3779
    if (!python_current_script)
 
3780
    {
 
3781
        WEECHAT_SCRIPT_MSG_NOT_INIT(PYTHON_CURRENT_SCRIPT_NAME, "hook_modifier_exec");
 
3782
        PYTHON_RETURN_EMPTY;
 
3783
    }
 
3784
    
 
3785
    modifier = NULL;
 
3786
    modifier_data = NULL;
 
3787
    string = NULL;
 
3788
    
 
3789
    if (!PyArg_ParseTuple (args, "sss", &modifier, &modifier_data, &string))
 
3790
    {
 
3791
        WEECHAT_SCRIPT_MSG_WRONG_ARGS(PYTHON_CURRENT_SCRIPT_NAME, "hook_modifier_exec");
 
3792
        PYTHON_RETURN_EMPTY;
 
3793
    }
 
3794
    
 
3795
    result = weechat_hook_modifier_exec (modifier, modifier_data, string);
 
3796
    
 
3797
    PYTHON_RETURN_STRING_FREE(result);
 
3798
}
 
3799
 
 
3800
/*
 
3801
 * weechat_python_api_hook_info_cb: callback for info hooked
 
3802
 */
 
3803
 
 
3804
const char *
 
3805
weechat_python_api_hook_info_cb (void *data, const char *info_name,
 
3806
                                 const char *arguments)
 
3807
{
 
3808
    struct t_script_callback *script_callback;
 
3809
    char *python_argv[4], empty_arg[1] = { '\0' };
 
3810
    
 
3811
    script_callback = (struct t_script_callback *)data;
 
3812
    
 
3813
    if (script_callback && script_callback->function && script_callback->function[0])
 
3814
    {
 
3815
        python_argv[0] = (script_callback->data) ? script_callback->data : empty_arg;
 
3816
        python_argv[1] = (info_name) ? (char *)info_name : empty_arg;
 
3817
        python_argv[2] = (arguments) ? (char *)arguments : empty_arg;
 
3818
        python_argv[3] = NULL;
 
3819
        
 
3820
        return (const char *)weechat_python_exec (script_callback->script,
 
3821
                                                  WEECHAT_SCRIPT_EXEC_STRING,
 
3822
                                                  script_callback->function,
 
3823
                                                  python_argv);
 
3824
    }
 
3825
    
 
3826
    return NULL;
 
3827
}
 
3828
 
 
3829
/*
 
3830
 * weechat_python_api_hook_info: hook an info
 
3831
 */
 
3832
 
 
3833
static PyObject *
 
3834
weechat_python_api_hook_info (PyObject *self, PyObject *args)
 
3835
{
 
3836
    char *info_name, *description, *function, *data, *result;
 
3837
    PyObject *object;
 
3838
    
 
3839
    /* make C compiler happy */
 
3840
    (void) self;
 
3841
    
 
3842
    if (!python_current_script)
 
3843
    {
 
3844
        WEECHAT_SCRIPT_MSG_NOT_INIT(PYTHON_CURRENT_SCRIPT_NAME, "hook_info");
 
3845
        PYTHON_RETURN_EMPTY;
 
3846
    }
 
3847
    
 
3848
    info_name = NULL;
 
3849
    description = NULL;
 
3850
    function = NULL;
 
3851
    data = NULL;
 
3852
    
 
3853
    if (!PyArg_ParseTuple (args, "ssss", &info_name, &description, &function,
 
3854
                           &data))
 
3855
    {
 
3856
        WEECHAT_SCRIPT_MSG_WRONG_ARGS(PYTHON_CURRENT_SCRIPT_NAME, "hook_info");
 
3857
        PYTHON_RETURN_EMPTY;
 
3858
    }
 
3859
    
 
3860
    result = script_ptr2str(script_api_hook_info (weechat_python_plugin,
 
3861
                                                  python_current_script,
 
3862
                                                  info_name,
 
3863
                                                  description,
 
3864
                                                  &weechat_python_api_hook_info_cb,
 
3865
                                                  function,
 
3866
                                                  data));
 
3867
    
 
3868
    PYTHON_RETURN_STRING_FREE(result);
 
3869
}
 
3870
 
 
3871
/*
 
3872
 * weechat_python_api_hook_infolist_cb: callback for infolist hooked
 
3873
 */
 
3874
 
 
3875
struct t_infolist *
 
3876
weechat_python_api_hook_infolist_cb (void *data, const char *infolist_name,
 
3877
                                     void *pointer, const char *arguments)
 
3878
{
 
3879
    struct t_script_callback *script_callback;
 
3880
    char *python_argv[5], empty_arg[1] = { '\0' };
 
3881
    struct t_infolist *result;
 
3882
    
 
3883
    script_callback = (struct t_script_callback *)data;
 
3884
    
 
3885
    if (script_callback && script_callback->function && script_callback->function[0])
 
3886
    {
 
3887
        python_argv[0] = (script_callback->data) ? script_callback->data : empty_arg;
 
3888
        python_argv[1] = (infolist_name) ? (char *)infolist_name : empty_arg;
 
3889
        python_argv[2] = script_ptr2str (pointer);
 
3890
        python_argv[3] = (arguments) ? (char *)arguments : empty_arg;
 
3891
        python_argv[4] = NULL;
 
3892
        
 
3893
        result = (struct t_infolist *)weechat_python_exec (script_callback->script,
 
3894
                                                           WEECHAT_SCRIPT_EXEC_STRING,
 
3895
                                                           script_callback->function,
 
3896
                                                           python_argv);
 
3897
        
 
3898
        if (python_argv[2])
 
3899
            free (python_argv[2]);
 
3900
        
 
3901
        return result;
 
3902
    }
 
3903
    
 
3904
    return NULL;
 
3905
}
 
3906
 
 
3907
/*
 
3908
 * weechat_python_api_hook_infolist: hook an infolist
 
3909
 */
 
3910
 
 
3911
static PyObject *
 
3912
weechat_python_api_hook_infolist (PyObject *self, PyObject *args)
 
3913
{
 
3914
    char *infolist_name, *description, *function, *data, *result;
 
3915
    PyObject *object;
 
3916
    
 
3917
    /* make C compiler happy */
 
3918
    (void) self;
 
3919
    
 
3920
    if (!python_current_script)
 
3921
    {
 
3922
        WEECHAT_SCRIPT_MSG_NOT_INIT(PYTHON_CURRENT_SCRIPT_NAME, "hook_infolist");
 
3923
        PYTHON_RETURN_EMPTY;
 
3924
    }
 
3925
    
 
3926
    infolist_name = NULL;
 
3927
    description = NULL;
 
3928
    function = NULL;
 
3929
    data = NULL;
 
3930
    
 
3931
    if (!PyArg_ParseTuple (args, "ssss", &infolist_name, &description,
 
3932
                           &function, &data))
 
3933
    {
 
3934
        WEECHAT_SCRIPT_MSG_WRONG_ARGS(PYTHON_CURRENT_SCRIPT_NAME, "hook_infolist");
 
3935
        PYTHON_RETURN_EMPTY;
 
3936
    }
 
3937
    
 
3938
    result = script_ptr2str(script_api_hook_infolist (weechat_python_plugin,
 
3939
                                                      python_current_script,
 
3940
                                                      infolist_name,
 
3941
                                                      description,
 
3942
                                                      &weechat_python_api_hook_infolist_cb,
 
3943
                                                      function,
 
3944
                                                      data));
 
3945
    
 
3946
    PYTHON_RETURN_STRING_FREE(result);
 
3947
}
 
3948
 
 
3949
/*
 
3950
 * weechat_python_api_unhook: unhook something
 
3951
 */
 
3952
 
 
3953
static PyObject *
 
3954
weechat_python_api_unhook (PyObject *self, PyObject *args)
 
3955
{
 
3956
    char *hook;
 
3957
    
 
3958
    /* make C compiler happy */
 
3959
    (void) self;
 
3960
    
 
3961
    if (!python_current_script)
 
3962
    {
 
3963
        WEECHAT_SCRIPT_MSG_NOT_INIT(PYTHON_CURRENT_SCRIPT_NAME, "unhook");
 
3964
        PYTHON_RETURN_ERROR;
 
3965
    }
 
3966
    
 
3967
    hook = NULL;
 
3968
    
 
3969
    if (!PyArg_ParseTuple (args, "s", &hook))
 
3970
    {
 
3971
        WEECHAT_SCRIPT_MSG_WRONG_ARGS(PYTHON_CURRENT_SCRIPT_NAME, "unhook");
 
3972
        PYTHON_RETURN_ERROR;
 
3973
    }
 
3974
    
 
3975
    script_api_unhook (weechat_python_plugin,
 
3976
                       python_current_script,
 
3977
                       script_str2ptr (hook));
 
3978
    
 
3979
    PYTHON_RETURN_OK;
 
3980
}
 
3981
 
 
3982
/*
 
3983
 * weechat_python_api_unhook_all: unhook all for script
 
3984
 */
 
3985
 
 
3986
static PyObject *
 
3987
weechat_python_api_unhook_all (PyObject *self, PyObject *args)
 
3988
{
 
3989
    /* make C compiler happy */
 
3990
    (void) self;
 
3991
    (void) args;
 
3992
    
 
3993
    if (!python_current_script)
 
3994
    {
 
3995
        WEECHAT_SCRIPT_MSG_NOT_INIT(PYTHON_CURRENT_SCRIPT_NAME, "unhook_all");
 
3996
        PYTHON_RETURN_ERROR;
 
3997
    }
 
3998
    
 
3999
    script_api_unhook_all (python_current_script);
 
4000
    
 
4001
    PYTHON_RETURN_OK;
 
4002
}
 
4003
 
 
4004
/*
 
4005
 * weechat_python_api_buffer_input_data_cb: callback for input data in a buffer
 
4006
 */
 
4007
 
 
4008
int
 
4009
weechat_python_api_buffer_input_data_cb (void *data, struct t_gui_buffer *buffer,
 
4010
                                         const char *input_data)
 
4011
{
 
4012
    struct t_script_callback *script_callback;
 
4013
    char *python_argv[4], empty_arg[1] = { '\0' };
 
4014
    int *rc, ret;
 
4015
    
 
4016
    script_callback = (struct t_script_callback *)data;
 
4017
    
 
4018
    if (script_callback && script_callback->function && script_callback->function[0])
 
4019
    {
 
4020
        python_argv[0] = (script_callback->data) ? script_callback->data : empty_arg;
 
4021
        python_argv[1] = script_ptr2str (buffer);
 
4022
        python_argv[2] = (input_data) ? (char *)input_data : empty_arg;
 
4023
        python_argv[3] = NULL;
 
4024
        
 
4025
        rc = (int *) weechat_python_exec (script_callback->script,
 
4026
                                          WEECHAT_SCRIPT_EXEC_INT,
 
4027
                                          script_callback->function,
 
4028
                                          python_argv);
 
4029
        if (!rc)
 
4030
            ret = WEECHAT_RC_ERROR;
 
4031
        else
 
4032
        {
 
4033
            ret = *rc;
 
4034
            free (rc);
 
4035
        }
 
4036
        if (python_argv[1])
 
4037
            free (python_argv[1]);
 
4038
        
 
4039
        return ret;
 
4040
    }
 
4041
    
 
4042
    return WEECHAT_RC_ERROR;
 
4043
}
 
4044
 
 
4045
/*
 
4046
 * weechat_python_api_buffer_close_cb: callback for buffer closed
 
4047
 */
 
4048
 
 
4049
int
 
4050
weechat_python_api_buffer_close_cb (void *data, struct t_gui_buffer *buffer)
 
4051
{
 
4052
    struct t_script_callback *script_callback;
 
4053
    char *python_argv[3], empty_arg[1] = { '\0' };
 
4054
    int *rc, ret;
 
4055
    
 
4056
    script_callback = (struct t_script_callback *)data;
 
4057
    
 
4058
    if (script_callback && script_callback->function && script_callback->function[0])
 
4059
    {
 
4060
        python_argv[0] = (script_callback->data) ? script_callback->data : empty_arg;
 
4061
        python_argv[1] = script_ptr2str (buffer);
 
4062
        python_argv[2] = NULL;
 
4063
        
 
4064
        rc = (int *) weechat_python_exec (script_callback->script,
 
4065
                                          WEECHAT_SCRIPT_EXEC_INT,
 
4066
                                          script_callback->function,
 
4067
                                          python_argv);
 
4068
        if (!rc)
 
4069
            ret = WEECHAT_RC_ERROR;
 
4070
        else
 
4071
        {
 
4072
            ret = *rc;
 
4073
            free (rc);
 
4074
        }
 
4075
        if (python_argv[1])
 
4076
            free (python_argv[1]);
 
4077
        
 
4078
        return ret;
 
4079
    }
 
4080
    
 
4081
    return WEECHAT_RC_ERROR;
 
4082
}
 
4083
 
 
4084
/*
 
4085
 * weechat_python_api_buffer_new: create a new buffer
 
4086
 */
 
4087
 
 
4088
static PyObject *
 
4089
weechat_python_api_buffer_new (PyObject *self, PyObject *args)
 
4090
{
 
4091
    char *name, *function_input, *data_input, *function_close, *data_close;
 
4092
    char *result;
 
4093
    PyObject *object;
 
4094
    
 
4095
    /* make C compiler happy */
 
4096
    (void) self;
 
4097
    
 
4098
    if (!python_current_script)
 
4099
    {
 
4100
        WEECHAT_SCRIPT_MSG_NOT_INIT(PYTHON_CURRENT_SCRIPT_NAME, "buffer_new");
 
4101
        PYTHON_RETURN_EMPTY;
 
4102
    }
 
4103
    
 
4104
    name = NULL;
 
4105
    function_input = NULL;
 
4106
    data_input = NULL;
 
4107
    function_close = NULL;
 
4108
    data_close = NULL;
 
4109
    
 
4110
    if (!PyArg_ParseTuple (args, "sssss", &name, &function_input, &data_input,
 
4111
                           &function_close, &data_close))
 
4112
    {
 
4113
        WEECHAT_SCRIPT_MSG_WRONG_ARGS(PYTHON_CURRENT_SCRIPT_NAME, "buffer_new");
 
4114
        PYTHON_RETURN_EMPTY;
 
4115
    }
 
4116
    
 
4117
    result = script_ptr2str (script_api_buffer_new (weechat_python_plugin,
 
4118
                                                    python_current_script,
 
4119
                                                    name,
 
4120
                                                    &weechat_python_api_buffer_input_data_cb,
 
4121
                                                    function_input,
 
4122
                                                    data_input,
 
4123
                                                    &weechat_python_api_buffer_close_cb,
 
4124
                                                    function_close,
 
4125
                                                    data_close));
 
4126
    
 
4127
    PYTHON_RETURN_STRING_FREE(result);
 
4128
}
 
4129
 
 
4130
/*
 
4131
 * weechat_python_api_buffer_search: search a buffer
 
4132
 */
 
4133
 
 
4134
static PyObject *
 
4135
weechat_python_api_buffer_search (PyObject *self, PyObject *args)
 
4136
{
 
4137
    char *plugin, *name;
 
4138
    char *result;
 
4139
    PyObject *object;
 
4140
    
 
4141
    /* make C compiler happy */
 
4142
    (void) self;
 
4143
    
 
4144
    if (!python_current_script)
 
4145
    {
 
4146
        WEECHAT_SCRIPT_MSG_NOT_INIT(PYTHON_CURRENT_SCRIPT_NAME, "buffer_search");
 
4147
        PYTHON_RETURN_EMPTY;
 
4148
    }
 
4149
    
 
4150
    plugin = NULL;
 
4151
    name = NULL;
 
4152
    
 
4153
    if (!PyArg_ParseTuple (args, "ss", &plugin, &name))
 
4154
    {
 
4155
        WEECHAT_SCRIPT_MSG_WRONG_ARGS(PYTHON_CURRENT_SCRIPT_NAME, "buffer_search");
 
4156
        PYTHON_RETURN_EMPTY;
 
4157
    }
 
4158
    
 
4159
    result = script_ptr2str (weechat_buffer_search (plugin, name));
 
4160
    
 
4161
    PYTHON_RETURN_STRING_FREE(result);
 
4162
}
 
4163
 
 
4164
/*
 
4165
 * weechat_python_api_buffer_search_main: search main buffer (WeeChat core buffer)
 
4166
 */
 
4167
 
 
4168
static PyObject *
 
4169
weechat_python_api_buffer_search_main (PyObject *self, PyObject *args)
 
4170
{
 
4171
    char *result;
 
4172
    PyObject *object;
 
4173
    
 
4174
    /* make C compiler happy */
 
4175
    (void) self;
 
4176
    (void) args;
 
4177
    
 
4178
    if (!python_current_script)
 
4179
    {
 
4180
        WEECHAT_SCRIPT_MSG_NOT_INIT(PYTHON_CURRENT_SCRIPT_NAME, "buffer_search_main");
 
4181
        PYTHON_RETURN_EMPTY;
 
4182
    }
 
4183
    
 
4184
    result = script_ptr2str (weechat_buffer_search_main ());
 
4185
    
 
4186
    PYTHON_RETURN_STRING_FREE(result);
 
4187
}
 
4188
 
 
4189
/*
 
4190
 * weechat_python_api_current_buffer: get current buffer
 
4191
 */
 
4192
 
 
4193
static PyObject *
 
4194
weechat_python_api_current_buffer (PyObject *self, PyObject *args)
 
4195
{
 
4196
    char *result;
 
4197
    PyObject *object;
 
4198
    
 
4199
    /* make C compiler happy */
 
4200
    (void) self;
 
4201
    (void) args;
 
4202
    
 
4203
    if (!python_current_script)
 
4204
    {
 
4205
        WEECHAT_SCRIPT_MSG_NOT_INIT(PYTHON_CURRENT_SCRIPT_NAME, "current_buffer");
 
4206
        PYTHON_RETURN_EMPTY;
 
4207
    }
 
4208
    
 
4209
    result = script_ptr2str (weechat_current_buffer ());
 
4210
    
 
4211
    PYTHON_RETURN_STRING_FREE(result);
 
4212
}
 
4213
 
 
4214
/*
 
4215
 * weechat_python_api_buffer_clear: clear a buffer
 
4216
 */
 
4217
 
 
4218
static PyObject *
 
4219
weechat_python_api_buffer_clear (PyObject *self, PyObject *args)
 
4220
{
 
4221
    char *buffer;
 
4222
    
 
4223
    /* make C compiler happy */
 
4224
    (void) self;
 
4225
    
 
4226
    if (!python_current_script)
 
4227
    {
 
4228
        WEECHAT_SCRIPT_MSG_NOT_INIT(PYTHON_CURRENT_SCRIPT_NAME, "buffer_clear");
 
4229
        PYTHON_RETURN_ERROR;
 
4230
    }
 
4231
    
 
4232
    buffer = NULL;
 
4233
    
 
4234
    if (!PyArg_ParseTuple (args, "s", &buffer))
 
4235
    {
 
4236
        WEECHAT_SCRIPT_MSG_WRONG_ARGS(PYTHON_CURRENT_SCRIPT_NAME, "buffer_clear");
 
4237
        PYTHON_RETURN_ERROR;
 
4238
    }
 
4239
    
 
4240
    weechat_buffer_clear (script_str2ptr (buffer));
 
4241
    
 
4242
    PYTHON_RETURN_OK;
 
4243
}
 
4244
 
 
4245
/*
 
4246
 * weechat_python_api_buffer_close: close a buffer
 
4247
 */
 
4248
 
 
4249
static PyObject *
 
4250
weechat_python_api_buffer_close (PyObject *self, PyObject *args)
 
4251
{
 
4252
    char *buffer;
 
4253
    
 
4254
    /* make C compiler happy */
 
4255
    (void) self;
 
4256
    
 
4257
    if (!python_current_script)
 
4258
    {
 
4259
        WEECHAT_SCRIPT_MSG_NOT_INIT(PYTHON_CURRENT_SCRIPT_NAME, "buffer_close");
 
4260
        PYTHON_RETURN_ERROR;
 
4261
    }
 
4262
    
 
4263
    buffer = NULL;
 
4264
    
 
4265
    if (!PyArg_ParseTuple (args, "s", &buffer))
 
4266
    {
 
4267
        WEECHAT_SCRIPT_MSG_WRONG_ARGS(PYTHON_CURRENT_SCRIPT_NAME, "buffer_close");
 
4268
        PYTHON_RETURN_ERROR;
 
4269
    }
 
4270
    
 
4271
    script_api_buffer_close (weechat_python_plugin,
 
4272
                             python_current_script,
 
4273
                             script_str2ptr (buffer));
 
4274
    
 
4275
    PYTHON_RETURN_OK;
 
4276
}
 
4277
 
 
4278
/*
 
4279
 * weechat_python_api_buffer_merge: merge a buffer to another buffer
 
4280
 */
 
4281
 
 
4282
static PyObject *
 
4283
weechat_python_api_buffer_merge (PyObject *self, PyObject *args)
 
4284
{
 
4285
    char *buffer, *target_buffer;
 
4286
    
 
4287
    /* make C compiler happy */
 
4288
    (void) self;
 
4289
    
 
4290
    if (!python_current_script)
 
4291
    {
 
4292
        WEECHAT_SCRIPT_MSG_NOT_INIT(PYTHON_CURRENT_SCRIPT_NAME, "buffer_merge");
 
4293
        PYTHON_RETURN_ERROR;
 
4294
    }
 
4295
    
 
4296
    buffer = NULL;
 
4297
    target_buffer = NULL;
 
4298
    
 
4299
    if (!PyArg_ParseTuple (args, "ss", &buffer, &target_buffer))
 
4300
    {
 
4301
        WEECHAT_SCRIPT_MSG_WRONG_ARGS(PYTHON_CURRENT_SCRIPT_NAME, "buffer_merge");
 
4302
        PYTHON_RETURN_ERROR;
 
4303
    }
 
4304
    
 
4305
    weechat_buffer_merge (script_str2ptr (buffer),
 
4306
                          script_str2ptr (target_buffer));
 
4307
    
 
4308
    PYTHON_RETURN_OK;
 
4309
}
 
4310
 
 
4311
/*
 
4312
 * weechat_python_api_buffer_unmerge: unmerge a buffer from group of merged
 
4313
 *                                    buffers
 
4314
 */
 
4315
 
 
4316
static PyObject *
 
4317
weechat_python_api_buffer_unmerge (PyObject *self, PyObject *args)
 
4318
{
 
4319
    char *buffer;
 
4320
    int number;
 
4321
    
 
4322
    /* make C compiler happy */
 
4323
    (void) self;
 
4324
    
 
4325
    if (!python_current_script)
 
4326
    {
 
4327
        WEECHAT_SCRIPT_MSG_NOT_INIT(PYTHON_CURRENT_SCRIPT_NAME, "buffer_unmerge");
 
4328
        PYTHON_RETURN_ERROR;
 
4329
    }
 
4330
    
 
4331
    buffer = NULL;
 
4332
    number = 0;
 
4333
    
 
4334
    if (!PyArg_ParseTuple (args, "si", &buffer, &number))
 
4335
    {
 
4336
        WEECHAT_SCRIPT_MSG_WRONG_ARGS(PYTHON_CURRENT_SCRIPT_NAME, "buffer_unmerge");
 
4337
        PYTHON_RETURN_ERROR;
 
4338
    }
 
4339
    
 
4340
    weechat_buffer_unmerge (script_str2ptr (buffer), number);
 
4341
    
 
4342
    PYTHON_RETURN_OK;
 
4343
}
 
4344
 
 
4345
/*
 
4346
 * weechat_python_api_buffer_get_integer get a buffer property as integer
 
4347
 */
 
4348
 
 
4349
static PyObject *
 
4350
weechat_python_api_buffer_get_integer (PyObject *self, PyObject *args)
 
4351
{
 
4352
    char *buffer, *property;
 
4353
    int value;
 
4354
    
 
4355
    /* make C compiler happy */
 
4356
    (void) self;
 
4357
    
 
4358
    if (!python_current_script)
 
4359
    {
 
4360
        WEECHAT_SCRIPT_MSG_NOT_INIT(PYTHON_CURRENT_SCRIPT_NAME, "buffer_get_integer");
 
4361
        PYTHON_RETURN_INT(-1);
 
4362
    }
 
4363
    
 
4364
    buffer = NULL;
 
4365
    property = NULL;
 
4366
    
 
4367
    if (!PyArg_ParseTuple (args, "ss", &buffer, &property))
 
4368
    {
 
4369
        WEECHAT_SCRIPT_MSG_WRONG_ARGS(PYTHON_CURRENT_SCRIPT_NAME, "buffer_get_integer");
 
4370
        PYTHON_RETURN_INT(-1);
 
4371
    }
 
4372
    
 
4373
    value = weechat_buffer_get_integer (script_str2ptr (buffer), property);
 
4374
    
 
4375
    PYTHON_RETURN_INT(value);
 
4376
}
 
4377
 
 
4378
/*
 
4379
 * weechat_python_api_buffer_get_string: get a buffer property as string
 
4380
 */
 
4381
 
 
4382
static PyObject *
 
4383
weechat_python_api_buffer_get_string (PyObject *self, PyObject *args)
 
4384
{
 
4385
    char *buffer, *property;
 
4386
    const char *result;
 
4387
    
 
4388
    /* make C compiler happy */
 
4389
    (void) self;
 
4390
    
 
4391
    if (!python_current_script)
 
4392
    {
 
4393
        WEECHAT_SCRIPT_MSG_NOT_INIT(PYTHON_CURRENT_SCRIPT_NAME, "buffer_get_string");
 
4394
        PYTHON_RETURN_ERROR;
 
4395
    }
 
4396
    
 
4397
    buffer = NULL;
 
4398
    property = NULL;
 
4399
    
 
4400
    if (!PyArg_ParseTuple (args, "ss", &buffer, &property))
 
4401
    {
 
4402
        WEECHAT_SCRIPT_MSG_WRONG_ARGS(PYTHON_CURRENT_SCRIPT_NAME, "buffer_get_string");
 
4403
        PYTHON_RETURN_EMPTY;
 
4404
    }
 
4405
    
 
4406
    result = weechat_buffer_get_string (script_str2ptr (buffer), property);
 
4407
    
 
4408
    PYTHON_RETURN_STRING(result);
 
4409
}
 
4410
 
 
4411
/*
 
4412
 * weechat_python_api_buffer_get_pointer: get a buffer property as pointer
 
4413
 */
 
4414
 
 
4415
static PyObject *
 
4416
weechat_python_api_buffer_get_pointer (PyObject *self, PyObject *args)
 
4417
{
 
4418
    char *buffer, *property, *result;
 
4419
    PyObject *object;
 
4420
    
 
4421
    /* make C compiler happy */
 
4422
    (void) self;
 
4423
    
 
4424
    if (!python_current_script)
 
4425
    {
 
4426
        WEECHAT_SCRIPT_MSG_NOT_INIT(PYTHON_CURRENT_SCRIPT_NAME, "buffer_get_pointer");
 
4427
        PYTHON_RETURN_EMPTY;
 
4428
    }
 
4429
    
 
4430
    buffer = NULL;
 
4431
    property = NULL;
 
4432
    
 
4433
    if (!PyArg_ParseTuple (args, "ss", &buffer, &property))
 
4434
    {
 
4435
        WEECHAT_SCRIPT_MSG_WRONG_ARGS(PYTHON_CURRENT_SCRIPT_NAME, "buffer_get_pointer");
 
4436
        PYTHON_RETURN_EMPTY;
 
4437
    }
 
4438
    
 
4439
    result = script_ptr2str (weechat_buffer_get_pointer (script_str2ptr (buffer),
 
4440
                                                         property));
 
4441
    
 
4442
    PYTHON_RETURN_STRING_FREE(result);
 
4443
}
 
4444
 
 
4445
/*
 
4446
 * weechat_python_api_buffer_set: set a buffer property
 
4447
 */
 
4448
 
 
4449
static PyObject *
 
4450
weechat_python_api_buffer_set (PyObject *self, PyObject *args)
 
4451
{
 
4452
    char *buffer, *property, *value;
 
4453
    
 
4454
    /* make C compiler happy */
 
4455
    (void) self;
 
4456
    
 
4457
    if (!python_current_script)
 
4458
    {
 
4459
        WEECHAT_SCRIPT_MSG_NOT_INIT(PYTHON_CURRENT_SCRIPT_NAME, "buffer_set");
 
4460
        PYTHON_RETURN_ERROR;
 
4461
    }
 
4462
    
 
4463
    buffer = NULL;
 
4464
    property = NULL;
 
4465
    value = NULL;
 
4466
    
 
4467
    if (!PyArg_ParseTuple (args, "sss", &buffer, &property, &value))
 
4468
    {
 
4469
        WEECHAT_SCRIPT_MSG_WRONG_ARGS(PYTHON_CURRENT_SCRIPT_NAME, "buffer_set");
 
4470
        PYTHON_RETURN_ERROR;
 
4471
    }
 
4472
    
 
4473
    weechat_buffer_set (script_str2ptr (buffer),
 
4474
                        property,
 
4475
                        value);
 
4476
    
 
4477
    PYTHON_RETURN_OK;
 
4478
}
 
4479
 
 
4480
/*
 
4481
 * weechat_python_api_current_window: get current window
 
4482
 */
 
4483
 
 
4484
static PyObject *
 
4485
weechat_python_api_current_window (PyObject *self, PyObject *args)
 
4486
{
 
4487
    char *result;
 
4488
    PyObject *object;
 
4489
    
 
4490
    /* make C compiler happy */
 
4491
    (void) self;
 
4492
    (void) args;
 
4493
    
 
4494
    if (!python_current_script)
 
4495
    {
 
4496
        WEECHAT_SCRIPT_MSG_NOT_INIT(PYTHON_CURRENT_SCRIPT_NAME, "current_window");
 
4497
        PYTHON_RETURN_EMPTY;
 
4498
    }
 
4499
    
 
4500
    result = script_ptr2str (weechat_current_window ());
 
4501
    
 
4502
    PYTHON_RETURN_STRING_FREE(result);
 
4503
}
 
4504
 
 
4505
/*
 
4506
 * weechat_python_api_window_get_integer get a window property as integer
 
4507
 */
 
4508
 
 
4509
static PyObject *
 
4510
weechat_python_api_window_get_integer (PyObject *self, PyObject *args)
 
4511
{
 
4512
    char *window, *property;
 
4513
    int value;
 
4514
    
 
4515
    /* make C compiler happy */
 
4516
    (void) self;
 
4517
    
 
4518
    if (!python_current_script)
 
4519
    {
 
4520
        WEECHAT_SCRIPT_MSG_NOT_INIT(PYTHON_CURRENT_SCRIPT_NAME, "window_get_integer");
 
4521
        PYTHON_RETURN_INT(-1);
 
4522
    }
 
4523
    
 
4524
    window = NULL;
 
4525
    property = NULL;
 
4526
    
 
4527
    if (!PyArg_ParseTuple (args, "ss", &window, &property))
 
4528
    {
 
4529
        WEECHAT_SCRIPT_MSG_WRONG_ARGS(PYTHON_CURRENT_SCRIPT_NAME, "window_get_integer");
 
4530
        PYTHON_RETURN_INT(-1);
 
4531
    }
 
4532
    
 
4533
    value = weechat_window_get_integer (script_str2ptr (window), property);
 
4534
    
 
4535
    PYTHON_RETURN_INT(value);
 
4536
}
 
4537
 
 
4538
/*
 
4539
 * weechat_python_api_window_get_string: get a window property as string
 
4540
 */
 
4541
 
 
4542
static PyObject *
 
4543
weechat_python_api_window_get_string (PyObject *self, PyObject *args)
 
4544
{
 
4545
    char *window, *property;
 
4546
    const char *result;
 
4547
    
 
4548
    /* make C compiler happy */
 
4549
    (void) self;
 
4550
    
 
4551
    if (!python_current_script)
 
4552
    {
 
4553
        WEECHAT_SCRIPT_MSG_NOT_INIT(PYTHON_CURRENT_SCRIPT_NAME, "window_get_string");
 
4554
        PYTHON_RETURN_EMPTY;
 
4555
    }
 
4556
    
 
4557
    window = NULL;
 
4558
    property = NULL;
 
4559
    
 
4560
    if (!PyArg_ParseTuple (args, "ss", &window, &property))
 
4561
    {
 
4562
        WEECHAT_SCRIPT_MSG_WRONG_ARGS(PYTHON_CURRENT_SCRIPT_NAME, "window_get_string");
 
4563
        PYTHON_RETURN_EMPTY;
 
4564
    }
 
4565
    
 
4566
    result = weechat_window_get_string (script_str2ptr (window), property);
 
4567
    
 
4568
    PYTHON_RETURN_STRING(result);
 
4569
}
 
4570
 
 
4571
/*
 
4572
 * weechat_python_api_window_get_pointer: get a window property as pointer
 
4573
 */
 
4574
 
 
4575
static PyObject *
 
4576
weechat_python_api_window_get_pointer (PyObject *self, PyObject *args)
 
4577
{
 
4578
    char *window, *property, *result;
 
4579
    PyObject *object;
 
4580
    
 
4581
    /* make C compiler happy */
 
4582
    (void) self;
 
4583
    
 
4584
    if (!python_current_script)
 
4585
    {
 
4586
        WEECHAT_SCRIPT_MSG_NOT_INIT(PYTHON_CURRENT_SCRIPT_NAME, "window_get_pointer");
 
4587
        PYTHON_RETURN_EMPTY;
 
4588
    }
 
4589
    
 
4590
    window = NULL;
 
4591
    property = NULL;
 
4592
    
 
4593
    if (!PyArg_ParseTuple (args, "ss", &window, &property))
 
4594
    {
 
4595
        WEECHAT_SCRIPT_MSG_WRONG_ARGS(PYTHON_CURRENT_SCRIPT_NAME, "window_get_pointer");
 
4596
        PYTHON_RETURN_EMPTY;
 
4597
    }
 
4598
    
 
4599
    result = script_ptr2str (weechat_window_get_pointer (script_str2ptr (window),
 
4600
                                                         property));
 
4601
    
 
4602
    PYTHON_RETURN_STRING_FREE(result);
 
4603
}
 
4604
 
 
4605
/*
 
4606
 * weechat_python_api_window_set_title: set window title
 
4607
 */
 
4608
 
 
4609
static PyObject *
 
4610
weechat_python_api_window_set_title (PyObject *self, PyObject *args)
 
4611
{
 
4612
    char *title;
 
4613
    
 
4614
    /* make C compiler happy */
 
4615
    (void) self;
 
4616
    
 
4617
    if (!python_current_script)
 
4618
    {
 
4619
        WEECHAT_SCRIPT_MSG_NOT_INIT(PYTHON_CURRENT_SCRIPT_NAME, "window_set_title");
 
4620
        PYTHON_RETURN_ERROR;
 
4621
    }
 
4622
    
 
4623
    title = NULL;
 
4624
    
 
4625
    if (!PyArg_ParseTuple (args, "s", &title))
 
4626
    {
 
4627
        WEECHAT_SCRIPT_MSG_WRONG_ARGS(PYTHON_CURRENT_SCRIPT_NAME, "window_set_title");
 
4628
        PYTHON_RETURN_ERROR;
 
4629
    }
 
4630
    
 
4631
    weechat_window_set_title (title);
 
4632
    
 
4633
    PYTHON_RETURN_OK;
 
4634
}
 
4635
 
 
4636
/*
 
4637
 * weechat_python_api_nicklist_add_group: add a group in nicklist
 
4638
 */
 
4639
 
 
4640
static PyObject *
 
4641
weechat_python_api_nicklist_add_group (PyObject *self, PyObject *args)
 
4642
{
 
4643
    char *buffer, *parent_group, *name, *color, *result;
 
4644
    int visible;
 
4645
    PyObject *object;
 
4646
    
 
4647
    /* make C compiler happy */
 
4648
    (void) self;
 
4649
    
 
4650
    if (!python_current_script)
 
4651
    {
 
4652
        WEECHAT_SCRIPT_MSG_NOT_INIT(PYTHON_CURRENT_SCRIPT_NAME, "nicklist_add_group");
 
4653
        PYTHON_RETURN_EMPTY;
 
4654
    }
 
4655
    
 
4656
    buffer = NULL;
 
4657
    parent_group = NULL;
 
4658
    name = NULL;
 
4659
    color = NULL;
 
4660
    visible = 0;
 
4661
    
 
4662
    if (!PyArg_ParseTuple (args, "ssssi", &buffer, &parent_group, &name,
 
4663
                           &color, &visible))
 
4664
    {
 
4665
        WEECHAT_SCRIPT_MSG_WRONG_ARGS(PYTHON_CURRENT_SCRIPT_NAME, "nicklist_add_group");
 
4666
        PYTHON_RETURN_EMPTY;
 
4667
    }
 
4668
    
 
4669
    result = script_ptr2str (weechat_nicklist_add_group (script_str2ptr (buffer),
 
4670
                                                         script_str2ptr (parent_group),
 
4671
                                                         name,
 
4672
                                                         color,
 
4673
                                                         visible));
 
4674
    
 
4675
    PYTHON_RETURN_STRING_FREE(result);
 
4676
}
 
4677
 
 
4678
/*
 
4679
 * weechat_python_api_nicklist_search_group: search a group in nicklist
 
4680
 */
 
4681
 
 
4682
static PyObject *
 
4683
weechat_python_api_nicklist_search_group (PyObject *self, PyObject *args)
 
4684
{
 
4685
    char *buffer, *from_group, *name, *result;
 
4686
    PyObject *object;
 
4687
    
 
4688
    /* make C compiler happy */
 
4689
    (void) self;
 
4690
    
 
4691
    if (!python_current_script)
 
4692
    {
 
4693
        WEECHAT_SCRIPT_MSG_NOT_INIT(PYTHON_CURRENT_SCRIPT_NAME, "nicklist_search_group");
 
4694
        PYTHON_RETURN_EMPTY;
 
4695
    }
 
4696
    
 
4697
    buffer = NULL;
 
4698
    from_group = NULL;
 
4699
    name = NULL;
 
4700
    
 
4701
    if (!PyArg_ParseTuple (args, "sss", &buffer, &from_group, &name))
 
4702
    {
 
4703
        WEECHAT_SCRIPT_MSG_WRONG_ARGS(PYTHON_CURRENT_SCRIPT_NAME, "nicklist_search_group");
 
4704
        PYTHON_RETURN_EMPTY;
 
4705
    }
 
4706
    
 
4707
    result = script_ptr2str (weechat_nicklist_search_group (script_str2ptr (buffer),
 
4708
                                                            script_str2ptr (from_group),
 
4709
                                                            name));
 
4710
    
 
4711
    PYTHON_RETURN_STRING_FREE(result);
 
4712
}
 
4713
 
 
4714
/*
 
4715
 * weechat_python_api_nicklist_add_nick: add a nick in nicklist
 
4716
 */
 
4717
 
 
4718
static PyObject *
 
4719
weechat_python_api_nicklist_add_nick (PyObject *self, PyObject *args)
 
4720
{
 
4721
    char *buffer, *group, *name, *color, *prefix, *prefix_color, *result;
 
4722
    int visible;
 
4723
    PyObject *object;
 
4724
    
 
4725
    /* make C compiler happy */
 
4726
    (void) self;
 
4727
    
 
4728
    if (!python_current_script)
 
4729
    {
 
4730
        WEECHAT_SCRIPT_MSG_NOT_INIT(PYTHON_CURRENT_SCRIPT_NAME, "nicklist_add_nick");
 
4731
        PYTHON_RETURN_EMPTY;
 
4732
    }
 
4733
    
 
4734
    buffer = NULL;
 
4735
    group = NULL;
 
4736
    name = NULL;
 
4737
    color = NULL;
 
4738
    prefix = NULL;
 
4739
    prefix_color = NULL;
 
4740
    visible = 0;
 
4741
    
 
4742
    if (!PyArg_ParseTuple (args, "ssssssi", &buffer, &group, &name, &color,
 
4743
                           &prefix, &prefix_color, &visible))
 
4744
    {
 
4745
        WEECHAT_SCRIPT_MSG_WRONG_ARGS(PYTHON_CURRENT_SCRIPT_NAME, "nicklist_add_nick");
 
4746
        PYTHON_RETURN_EMPTY;
 
4747
    }
 
4748
    
 
4749
    result = script_ptr2str (weechat_nicklist_add_nick (script_str2ptr (buffer),
 
4750
                                                        script_str2ptr (group),
 
4751
                                                        name,
 
4752
                                                        color,
 
4753
                                                        prefix,
 
4754
                                                        prefix_color,
 
4755
                                                        visible));
 
4756
    
 
4757
    PYTHON_RETURN_STRING_FREE(result);
 
4758
}
 
4759
 
 
4760
/*
 
4761
 * weechat_python_api_nicklist_search_nick: search a nick in nicklist
 
4762
 */
 
4763
 
 
4764
static PyObject *
 
4765
weechat_python_api_nicklist_search_nick (PyObject *self, PyObject *args)
 
4766
{
 
4767
    char *buffer, *from_group, *name, *result;
 
4768
    PyObject *object;
 
4769
    
 
4770
    /* make C compiler happy */
 
4771
    (void) self;
 
4772
    
 
4773
    if (!python_current_script)
 
4774
    {
 
4775
        WEECHAT_SCRIPT_MSG_NOT_INIT(PYTHON_CURRENT_SCRIPT_NAME, "nicklist_search_nick");
 
4776
        PYTHON_RETURN_EMPTY;
 
4777
    }
 
4778
    
 
4779
    buffer = NULL;
 
4780
    from_group = NULL;
 
4781
    name = NULL;
 
4782
    
 
4783
    if (!PyArg_ParseTuple (args, "sss", &buffer, &from_group, &name))
 
4784
    {
 
4785
        WEECHAT_SCRIPT_MSG_WRONG_ARGS(PYTHON_CURRENT_SCRIPT_NAME, "nicklist_search_nick");
 
4786
        PYTHON_RETURN_EMPTY;
 
4787
    }
 
4788
    
 
4789
    result = script_ptr2str (weechat_nicklist_search_nick (script_str2ptr (buffer),
 
4790
                                                           script_str2ptr (from_group),
 
4791
                                                           name));
 
4792
    
 
4793
    PYTHON_RETURN_STRING_FREE(result);
 
4794
}
 
4795
 
 
4796
/*
 
4797
 * weechat_python_api_nicklist_remove_group: remove a group from nicklist
 
4798
 */
 
4799
 
 
4800
static PyObject *
 
4801
weechat_python_api_nicklist_remove_group (PyObject *self, PyObject *args)
 
4802
{
 
4803
    char *buffer, *group;
 
4804
    
 
4805
    /* make C compiler happy */
 
4806
    (void) self;
 
4807
    
 
4808
    if (!python_current_script)
 
4809
    {
 
4810
        WEECHAT_SCRIPT_MSG_NOT_INIT(PYTHON_CURRENT_SCRIPT_NAME, "nicklist_remove_group");
 
4811
        PYTHON_RETURN_ERROR;
 
4812
    }
 
4813
    
 
4814
    buffer = NULL;
 
4815
    group = NULL;
 
4816
    
 
4817
    if (!PyArg_ParseTuple (args, "ss", &buffer, &group))
 
4818
    {
 
4819
        WEECHAT_SCRIPT_MSG_WRONG_ARGS(PYTHON_CURRENT_SCRIPT_NAME, "nicklist_remove_group");
 
4820
        PYTHON_RETURN_ERROR;
 
4821
    }
 
4822
    
 
4823
    weechat_nicklist_remove_group (script_str2ptr (buffer),
 
4824
                                   script_str2ptr (group));
 
4825
    
 
4826
    PYTHON_RETURN_OK;
 
4827
}
 
4828
 
 
4829
/*
 
4830
 * weechat_python_api_nicklist_remove_nick: remove a nick from nicklist
 
4831
 */
 
4832
 
 
4833
static PyObject *
 
4834
weechat_python_api_nicklist_remove_nick (PyObject *self, PyObject *args)
 
4835
{
 
4836
    char *buffer, *nick;
 
4837
    
 
4838
    /* make C compiler happy */
 
4839
    (void) self;
 
4840
    
 
4841
    if (!python_current_script)
 
4842
    {
 
4843
        WEECHAT_SCRIPT_MSG_NOT_INIT(PYTHON_CURRENT_SCRIPT_NAME, "nicklist_remove_nick");
 
4844
        PYTHON_RETURN_ERROR;
 
4845
    }
 
4846
    
 
4847
    buffer = NULL;
 
4848
    nick = NULL;
 
4849
    
 
4850
    if (!PyArg_ParseTuple (args, "ss", &buffer, &nick))
 
4851
    {
 
4852
        WEECHAT_SCRIPT_MSG_WRONG_ARGS(PYTHON_CURRENT_SCRIPT_NAME, "nicklist_remove_nick");
 
4853
        PYTHON_RETURN_ERROR;
 
4854
    }
 
4855
    
 
4856
    weechat_nicklist_remove_group (script_str2ptr (buffer),
 
4857
                                   script_str2ptr (nick));
 
4858
    
 
4859
    PYTHON_RETURN_OK;
 
4860
}
 
4861
 
 
4862
/*
 
4863
 * weechat_python_api_nicklist_remove_all: remove all groups/nicks from nicklist
 
4864
 */
 
4865
 
 
4866
static PyObject *
 
4867
weechat_python_api_nicklist_remove_all (PyObject *self, PyObject *args)
 
4868
{
 
4869
    char *buffer;
 
4870
    
 
4871
    /* make C compiler happy */
 
4872
    (void) self;
 
4873
    
 
4874
    if (!python_current_script)
 
4875
    {
 
4876
        WEECHAT_SCRIPT_MSG_NOT_INIT(PYTHON_CURRENT_SCRIPT_NAME, "nicklist_remove_all");
 
4877
        PYTHON_RETURN_ERROR;
 
4878
    }
 
4879
    
 
4880
    buffer = NULL;
 
4881
    
 
4882
    if (!PyArg_ParseTuple (args, "s", &buffer))
 
4883
    {
 
4884
        WEECHAT_SCRIPT_MSG_WRONG_ARGS(PYTHON_CURRENT_SCRIPT_NAME, "nicklist_remove_all");
 
4885
        PYTHON_RETURN_ERROR;
 
4886
    }
 
4887
    
 
4888
    weechat_nicklist_remove_all (script_str2ptr (buffer));
 
4889
    
 
4890
    PYTHON_RETURN_OK;
 
4891
}
 
4892
 
 
4893
/*
 
4894
 * weechat_python_api_bar_item_search: search a bar item
 
4895
 */
 
4896
 
 
4897
static PyObject *
 
4898
weechat_python_api_bar_item_search (PyObject *self, PyObject *args)
 
4899
{
 
4900
    char *name, *result;
 
4901
    PyObject *object;
 
4902
    
 
4903
    /* make C compiler happy */
 
4904
    (void) self;
 
4905
    
 
4906
    if (!python_current_script)
 
4907
    {
 
4908
        WEECHAT_SCRIPT_MSG_NOT_INIT(PYTHON_CURRENT_SCRIPT_NAME, "bar_item_search");
 
4909
        PYTHON_RETURN_EMPTY;
 
4910
    }
 
4911
    
 
4912
    name = NULL;
 
4913
    
 
4914
    if (!PyArg_ParseTuple (args, "s", &name))
 
4915
    {
 
4916
        WEECHAT_SCRIPT_MSG_WRONG_ARGS(PYTHON_CURRENT_SCRIPT_NAME, "bar_item_search");
 
4917
        PYTHON_RETURN_EMPTY;
 
4918
    }
 
4919
    
 
4920
    result = script_ptr2str (weechat_bar_item_search (name));
 
4921
    
 
4922
    PYTHON_RETURN_STRING_FREE(result);
 
4923
}
 
4924
 
 
4925
/*
 
4926
 * weechat_python_api_bar_item_build_cb: callback for building bar item
 
4927
 */
 
4928
 
 
4929
char *
 
4930
weechat_python_api_bar_item_build_cb (void *data, struct t_gui_bar_item *item,
 
4931
                                      struct t_gui_window *window)
 
4932
{
 
4933
    struct t_script_callback *script_callback;
 
4934
    char *python_argv[4], empty_arg[1] = { '\0' }, *ret;
 
4935
    
 
4936
    script_callback = (struct t_script_callback *)data;
 
4937
 
 
4938
    if (script_callback && script_callback->function && script_callback->function[0])
 
4939
    {
 
4940
        python_argv[0] = (script_callback->data) ? script_callback->data : empty_arg;
 
4941
        python_argv[1] = script_ptr2str (item);
 
4942
        python_argv[2] = script_ptr2str (window);
 
4943
        python_argv[3] = NULL;
 
4944
        
 
4945
        ret = (char *)weechat_python_exec (script_callback->script,
 
4946
                                           WEECHAT_SCRIPT_EXEC_STRING,
 
4947
                                           script_callback->function,
 
4948
                                           python_argv);
 
4949
        
 
4950
        if (python_argv[1])
 
4951
            free (python_argv[1]);
 
4952
        if (python_argv[2])
 
4953
            free (python_argv[2]);
 
4954
        
 
4955
        return ret;
 
4956
    }
 
4957
    
 
4958
    return NULL;
 
4959
}
 
4960
 
 
4961
/*
 
4962
 * weechat_python_api_bar_item_new: add a new bar item
 
4963
 */
 
4964
 
 
4965
static PyObject *
 
4966
weechat_python_api_bar_item_new (PyObject *self, PyObject *args)
 
4967
{
 
4968
    char *name, *function, *data, *result;
 
4969
    PyObject *object;
 
4970
    
 
4971
    /* make C compiler happy */
 
4972
    (void) self;
 
4973
    
 
4974
    if (!python_current_script)
 
4975
    {
 
4976
        WEECHAT_SCRIPT_MSG_NOT_INIT(PYTHON_CURRENT_SCRIPT_NAME, "bar_item_new");
 
4977
        PYTHON_RETURN_EMPTY;
 
4978
    }
 
4979
    
 
4980
    name = NULL;
 
4981
    function = NULL;
 
4982
    data = NULL;
 
4983
    
 
4984
    if (!PyArg_ParseTuple (args, "sss", &name, &function, &data))
 
4985
    {
 
4986
        WEECHAT_SCRIPT_MSG_WRONG_ARGS(PYTHON_CURRENT_SCRIPT_NAME, "bar_item_new");
 
4987
        PYTHON_RETURN_EMPTY;
 
4988
    }
 
4989
    
 
4990
    result = script_ptr2str (script_api_bar_item_new (weechat_python_plugin,
 
4991
                                                      python_current_script,
 
4992
                                                      name,
 
4993
                                                      &weechat_python_api_bar_item_build_cb,
 
4994
                                                      function,
 
4995
                                                      data));
 
4996
    
 
4997
    PYTHON_RETURN_STRING_FREE(result);
 
4998
}
 
4999
 
 
5000
/*
 
5001
 * weechat_python_api_bar_item_update: update a bar item on screen
 
5002
 */
 
5003
 
 
5004
static PyObject *
 
5005
weechat_python_api_bar_item_update (PyObject *self, PyObject *args)
 
5006
{
 
5007
    char *name;
 
5008
    
 
5009
    /* make C compiler happy */
 
5010
    (void) self;
 
5011
    
 
5012
    if (!python_current_script)
 
5013
    {
 
5014
        WEECHAT_SCRIPT_MSG_NOT_INIT(PYTHON_CURRENT_SCRIPT_NAME, "bar_item_update");
 
5015
        PYTHON_RETURN_ERROR;
 
5016
    }
 
5017
    
 
5018
    name = NULL;
 
5019
    
 
5020
    if (!PyArg_ParseTuple (args, "s", &name))
 
5021
    {
 
5022
        WEECHAT_SCRIPT_MSG_WRONG_ARGS(PYTHON_CURRENT_SCRIPT_NAME, "bar_item_update");
 
5023
        PYTHON_RETURN_ERROR;
 
5024
    }
 
5025
    
 
5026
    weechat_bar_item_update (name);
 
5027
    
 
5028
    PYTHON_RETURN_OK;
 
5029
}
 
5030
 
 
5031
/*
 
5032
 * weechat_python_api_bar_item_remove: remove a bar item
 
5033
 */
 
5034
 
 
5035
static PyObject *
 
5036
weechat_python_api_bar_item_remove (PyObject *self, PyObject *args)
 
5037
{
 
5038
    char *item;
 
5039
    
 
5040
    /* make C compiler happy */
 
5041
    (void) self;
 
5042
    
 
5043
    if (!python_current_script)
 
5044
    {
 
5045
        WEECHAT_SCRIPT_MSG_NOT_INIT(PYTHON_CURRENT_SCRIPT_NAME, "bar_item_remove");
 
5046
        PYTHON_RETURN_ERROR;
 
5047
    }
 
5048
    
 
5049
    item = NULL;
 
5050
    
 
5051
    if (!PyArg_ParseTuple (args, "s", &item))
 
5052
    {
 
5053
        WEECHAT_SCRIPT_MSG_WRONG_ARGS(PYTHON_CURRENT_SCRIPT_NAME, "bar_item_remove");
 
5054
        PYTHON_RETURN_ERROR;
 
5055
    }
 
5056
    
 
5057
    script_api_bar_item_remove (weechat_python_plugin,
 
5058
                                python_current_script,
 
5059
                                script_str2ptr (item));
 
5060
    
 
5061
    PYTHON_RETURN_OK;
 
5062
}
 
5063
 
 
5064
/*
 
5065
 * weechat_python_api_bar_search: search a bar
 
5066
 */
 
5067
 
 
5068
static PyObject *
 
5069
weechat_python_api_bar_search (PyObject *self, PyObject *args)
 
5070
{
 
5071
    char *name, *result;
 
5072
    PyObject *object;
 
5073
    
 
5074
    /* make C compiler happy */
 
5075
    (void) self;
 
5076
    
 
5077
    if (!python_current_script)
 
5078
    {
 
5079
        WEECHAT_SCRIPT_MSG_NOT_INIT(PYTHON_CURRENT_SCRIPT_NAME, "bar_search");
 
5080
        PYTHON_RETURN_EMPTY;
 
5081
    }
 
5082
    
 
5083
    name = NULL;
 
5084
    
 
5085
    if (!PyArg_ParseTuple (args, "s", &name))
 
5086
    {
 
5087
        WEECHAT_SCRIPT_MSG_WRONG_ARGS(PYTHON_CURRENT_SCRIPT_NAME, "bar_search");
 
5088
        PYTHON_RETURN_EMPTY;
 
5089
    }
 
5090
    
 
5091
    result = script_ptr2str (weechat_bar_search (name));
 
5092
    
 
5093
    PYTHON_RETURN_STRING_FREE(result);
 
5094
}
 
5095
 
 
5096
/*
 
5097
 * weechat_python_api_bar_new: add a new bar
 
5098
 */
 
5099
 
 
5100
static PyObject *
 
5101
weechat_python_api_bar_new (PyObject *self, PyObject *args)
 
5102
{
 
5103
    char *name, *hidden, *priority, *type, *conditions, *position;
 
5104
    char *filling_top_bottom, *filling_left_right, *size, *size_max;
 
5105
    char *color_fg, *color_delim, *color_bg, *separator, *items, *result;
 
5106
    PyObject *object;
 
5107
    
 
5108
    /* make C compiler happy */
 
5109
    (void) self;
 
5110
    
 
5111
    if (!python_current_script)
 
5112
    {
 
5113
        WEECHAT_SCRIPT_MSG_NOT_INIT(PYTHON_CURRENT_SCRIPT_NAME, "bar_new");
 
5114
        PYTHON_RETURN_EMPTY;
 
5115
    }
 
5116
    
 
5117
    name = NULL;
 
5118
    hidden = NULL;
 
5119
    priority = NULL;
 
5120
    type = NULL;
 
5121
    conditions = NULL;
 
5122
    position = NULL;
 
5123
    filling_top_bottom = NULL;
 
5124
    filling_left_right = NULL;
 
5125
    size = NULL;
 
5126
    size_max = NULL;
 
5127
    color_fg = NULL;
 
5128
    color_delim = NULL;
 
5129
    color_bg = NULL;
 
5130
    separator = NULL;
 
5131
    items = NULL;
 
5132
    
 
5133
    if (!PyArg_ParseTuple (args, "sssssssssssssss", &name, &hidden, &priority,
 
5134
                           &type, &conditions, &position, &filling_top_bottom,
 
5135
                           &filling_left_right, &size, &size_max, &color_fg,
 
5136
                           &color_delim, &color_bg, &separator, &items))
 
5137
    {
 
5138
        WEECHAT_SCRIPT_MSG_WRONG_ARGS(PYTHON_CURRENT_SCRIPT_NAME, "bar_new");
 
5139
        PYTHON_RETURN_EMPTY;
 
5140
    }
 
5141
    
 
5142
    result = script_ptr2str (weechat_bar_new (name,
 
5143
                                              hidden,
 
5144
                                              priority,
 
5145
                                              type,
 
5146
                                              conditions,
 
5147
                                              position,
 
5148
                                              filling_top_bottom,
 
5149
                                              filling_left_right,
 
5150
                                              size,
 
5151
                                              size_max,
 
5152
                                              color_fg,
 
5153
                                              color_delim,
 
5154
                                              color_bg,
 
5155
                                              separator,
 
5156
                                              items));
 
5157
    
 
5158
    PYTHON_RETURN_STRING_FREE(result);
 
5159
}
 
5160
 
 
5161
/*
 
5162
 * weechat_python_api_bar_set: set a bar property
 
5163
 */
 
5164
 
 
5165
static PyObject *
 
5166
weechat_python_api_bar_set (PyObject *self, PyObject *args)
 
5167
{
 
5168
    char *bar, *property, *value;
 
5169
    
 
5170
    /* make C compiler happy */
 
5171
    (void) self;
 
5172
    
 
5173
    if (!python_current_script)
 
5174
    {
 
5175
        WEECHAT_SCRIPT_MSG_NOT_INIT(PYTHON_CURRENT_SCRIPT_NAME, "bar_set");
 
5176
        PYTHON_RETURN_ERROR;
 
5177
    }
 
5178
    
 
5179
    bar = NULL;
 
5180
    property = NULL;
 
5181
    value = NULL;
 
5182
    
 
5183
    if (!PyArg_ParseTuple (args, "sss", &bar, &property, &value))
 
5184
    {
 
5185
        WEECHAT_SCRIPT_MSG_WRONG_ARGS(PYTHON_CURRENT_SCRIPT_NAME, "bar_set");
 
5186
        PYTHON_RETURN_ERROR;
 
5187
    }
 
5188
    
 
5189
    weechat_buffer_set (script_str2ptr (bar),
 
5190
                        property,
 
5191
                        value);
 
5192
    
 
5193
    PYTHON_RETURN_OK;
 
5194
}
 
5195
 
 
5196
/*
 
5197
 * weechat_python_api_bar_update: update a bar on screen
 
5198
 */
 
5199
 
 
5200
static PyObject *
 
5201
weechat_python_api_bar_update (PyObject *self, PyObject *args)
 
5202
{
 
5203
    char *name;
 
5204
    
 
5205
    /* make C compiler happy */
 
5206
    (void) self;
 
5207
    
 
5208
    if (!python_current_script)
 
5209
    {
 
5210
        WEECHAT_SCRIPT_MSG_NOT_INIT(PYTHON_CURRENT_SCRIPT_NAME, "bar_item");
 
5211
        PYTHON_RETURN_ERROR;
 
5212
    }
 
5213
    
 
5214
    name = NULL;
 
5215
    
 
5216
    if (!PyArg_ParseTuple (args, "s", &name))
 
5217
    {
 
5218
        WEECHAT_SCRIPT_MSG_WRONG_ARGS(PYTHON_CURRENT_SCRIPT_NAME, "bar_item");
 
5219
        PYTHON_RETURN_ERROR;
 
5220
    }
 
5221
    
 
5222
    weechat_bar_update (name);
 
5223
    
 
5224
    PYTHON_RETURN_OK;
 
5225
}
 
5226
 
 
5227
/*
 
5228
 * weechat_python_api_bar_remove: remove a bar
 
5229
 */
 
5230
 
 
5231
static PyObject *
 
5232
weechat_python_api_bar_remove (PyObject *self, PyObject *args)
 
5233
{
 
5234
    char *bar;
 
5235
    
 
5236
    /* make C compiler happy */
 
5237
    (void) self;
 
5238
    
 
5239
    if (!python_current_script)
 
5240
    {
 
5241
        WEECHAT_SCRIPT_MSG_NOT_INIT(PYTHON_CURRENT_SCRIPT_NAME, "bar_remove");
 
5242
        PYTHON_RETURN_ERROR;
 
5243
    }
 
5244
    
 
5245
    bar = NULL;
 
5246
    
 
5247
    if (!PyArg_ParseTuple (args, "s", &bar))
 
5248
    {
 
5249
        WEECHAT_SCRIPT_MSG_WRONG_ARGS(PYTHON_CURRENT_SCRIPT_NAME, "bar_remove");
 
5250
        PYTHON_RETURN_ERROR;
 
5251
    }
 
5252
    
 
5253
    weechat_bar_remove (script_str2ptr (bar));
 
5254
    
 
5255
    PYTHON_RETURN_OK;
 
5256
}
 
5257
 
 
5258
/*
 
5259
 * weechat_python_api_command: send command to server
 
5260
 */
 
5261
 
 
5262
static PyObject *
 
5263
weechat_python_api_command (PyObject *self, PyObject *args)
 
5264
{
 
5265
    char *buffer, *command;
 
5266
    
 
5267
    /* make C compiler happy */
 
5268
    (void) self;
 
5269
    
 
5270
    if (!python_current_script)
 
5271
    {
 
5272
        WEECHAT_SCRIPT_MSG_NOT_INIT(PYTHON_CURRENT_SCRIPT_NAME, "command");
 
5273
        PYTHON_RETURN_ERROR;
 
5274
    }
 
5275
    
 
5276
    buffer = NULL;
 
5277
    command = NULL;
 
5278
    
 
5279
    if (!PyArg_ParseTuple (args, "ss", &buffer, &command))
 
5280
    {
 
5281
        WEECHAT_SCRIPT_MSG_WRONG_ARGS(PYTHON_CURRENT_SCRIPT_NAME, "command");
 
5282
        PYTHON_RETURN_ERROR;
 
5283
    }
 
5284
    
 
5285
    script_api_command (weechat_python_plugin,
 
5286
                        python_current_script,
 
5287
                        script_str2ptr (buffer),
 
5288
                        command);
 
5289
    
 
5290
    PYTHON_RETURN_OK;
 
5291
}
 
5292
 
 
5293
/*
 
5294
 * weechat_python_api_info_get: get info about WeeChat
 
5295
 */
 
5296
 
 
5297
static PyObject *
 
5298
weechat_python_api_info_get (PyObject *self, PyObject *args)
 
5299
{
 
5300
    char *info_name, *arguments;
 
5301
    const char *result;
 
5302
    
 
5303
    /* make C compiler happy */
 
5304
    (void) self;
 
5305
    
 
5306
    if (!python_current_script)
 
5307
    {
 
5308
        WEECHAT_SCRIPT_MSG_NOT_INIT(PYTHON_CURRENT_SCRIPT_NAME, "info_get");
 
5309
        PYTHON_RETURN_EMPTY;
 
5310
    }
 
5311
    
 
5312
    info_name = NULL;
 
5313
    
 
5314
    if (!PyArg_ParseTuple (args, "ss", &info_name, &arguments))
 
5315
    {
 
5316
        WEECHAT_SCRIPT_MSG_WRONG_ARGS(PYTHON_CURRENT_SCRIPT_NAME, "info_get");
 
5317
        PYTHON_RETURN_EMPTY;
 
5318
    }
 
5319
    
 
5320
    result = weechat_info_get (info_name, arguments);
 
5321
    
 
5322
    PYTHON_RETURN_STRING(result);
 
5323
}
 
5324
 
 
5325
/*
 
5326
 * weechat_python_api_infolist_new: create new infolist
 
5327
 */
 
5328
 
 
5329
static PyObject *
 
5330
weechat_python_api_infolist_new (PyObject *self, PyObject *args)
 
5331
{
 
5332
    char *result;
 
5333
    PyObject *object;
 
5334
    
 
5335
    /* make C compiler happy */
 
5336
    (void) self;
 
5337
    (void) args;
 
5338
    
 
5339
    if (!python_current_script)
 
5340
    {
 
5341
        WEECHAT_SCRIPT_MSG_NOT_INIT(PYTHON_CURRENT_SCRIPT_NAME, "infolist_new");
 
5342
        PYTHON_RETURN_EMPTY;
 
5343
    }
 
5344
    
 
5345
    result = script_ptr2str (weechat_infolist_new ());
 
5346
    
 
5347
    PYTHON_RETURN_STRING_FREE(result);
 
5348
}
 
5349
 
 
5350
/*
 
5351
 * weechat_python_api_infolist_new_var_integer: create new integer variable in
 
5352
 *                                              infolist
 
5353
 */
 
5354
 
 
5355
static PyObject *
 
5356
weechat_python_api_infolist_new_var_integer (PyObject *self, PyObject *args)
 
5357
{
 
5358
    char *infolist, *name, *result;
 
5359
    int value;
 
5360
    PyObject *object;
 
5361
    
 
5362
    /* make C compiler happy */
 
5363
    (void) self;
 
5364
    
 
5365
    if (!python_current_script)
 
5366
    {
 
5367
        WEECHAT_SCRIPT_MSG_NOT_INIT(PYTHON_CURRENT_SCRIPT_NAME, "infolist_new_var_integer");
 
5368
        PYTHON_RETURN_EMPTY;
 
5369
    }
 
5370
    
 
5371
    infolist = NULL;
 
5372
    name = NULL;
 
5373
    value = 0;
 
5374
    
 
5375
    if (!PyArg_ParseTuple (args, "ssi", &infolist, &name, &value))
 
5376
    {
 
5377
        WEECHAT_SCRIPT_MSG_WRONG_ARGS(PYTHON_CURRENT_SCRIPT_NAME, "infolist_new_var_integer");
 
5378
        PYTHON_RETURN_EMPTY;
 
5379
    }
 
5380
    
 
5381
    result = script_ptr2str (weechat_infolist_new_var_integer (script_str2ptr (infolist),
 
5382
                                                               name,
 
5383
                                                               value));
 
5384
    
 
5385
    PYTHON_RETURN_STRING_FREE(result);
 
5386
}
 
5387
 
 
5388
/*
 
5389
 * weechat_python_api_infolist_new_var_string: create new string variable in
 
5390
 *                                             infolist
 
5391
 */
 
5392
 
 
5393
static PyObject *
 
5394
weechat_python_api_infolist_new_var_string (PyObject *self, PyObject *args)
 
5395
{
 
5396
    char *infolist, *name, *value, *result;
 
5397
    PyObject *object;
 
5398
    
 
5399
    /* make C compiler happy */
 
5400
    (void) self;
 
5401
    
 
5402
    if (!python_current_script)
 
5403
    {
 
5404
        WEECHAT_SCRIPT_MSG_NOT_INIT(PYTHON_CURRENT_SCRIPT_NAME, "infolist_new_var_string");
 
5405
        PYTHON_RETURN_EMPTY;
 
5406
    }
 
5407
    
 
5408
    infolist = NULL;
 
5409
    name = NULL;
 
5410
    value = NULL;
 
5411
    
 
5412
    if (!PyArg_ParseTuple (args, "sss", &infolist, &name, &value))
 
5413
    {
 
5414
        WEECHAT_SCRIPT_MSG_WRONG_ARGS(PYTHON_CURRENT_SCRIPT_NAME, "infolist_new_var_string");
 
5415
        PYTHON_RETURN_EMPTY;
 
5416
    }
 
5417
    
 
5418
    result = script_ptr2str (weechat_infolist_new_var_string (script_str2ptr (infolist),
 
5419
                                                              name,
 
5420
                                                              value));
 
5421
    
 
5422
    PYTHON_RETURN_STRING_FREE(result);
 
5423
}
 
5424
 
 
5425
/*
 
5426
 * weechat_python_api_infolist_new_var_pointer: create new pointer variable in
 
5427
 *                                              infolist
 
5428
 */
 
5429
 
 
5430
static PyObject *
 
5431
weechat_python_api_infolist_new_var_pointer (PyObject *self, PyObject *args)
 
5432
{
 
5433
    char *infolist, *name, *value, *result;
 
5434
    PyObject *object;
 
5435
    
 
5436
    /* make C compiler happy */
 
5437
    (void) self;
 
5438
    
 
5439
    if (!python_current_script)
 
5440
    {
 
5441
        WEECHAT_SCRIPT_MSG_NOT_INIT(PYTHON_CURRENT_SCRIPT_NAME, "infolist_new_var_pointer");
 
5442
        PYTHON_RETURN_EMPTY;
 
5443
    }
 
5444
    
 
5445
    infolist = NULL;
 
5446
    name = NULL;
 
5447
    value = NULL;
 
5448
    
 
5449
    if (!PyArg_ParseTuple (args, "sss", &infolist, &name, &value))
 
5450
    {
 
5451
        WEECHAT_SCRIPT_MSG_WRONG_ARGS(PYTHON_CURRENT_SCRIPT_NAME, "infolist_new_var_pointer");
 
5452
        PYTHON_RETURN_EMPTY;
 
5453
    }
 
5454
    
 
5455
    result = script_ptr2str (weechat_infolist_new_var_pointer (script_str2ptr (infolist),
 
5456
                                                               name,
 
5457
                                                               script_str2ptr (value)));
 
5458
    
 
5459
    PYTHON_RETURN_STRING_FREE(result);
 
5460
}
 
5461
 
 
5462
/*
 
5463
 * weechat_python_api_infolist_new_var_time: create new time variable in
 
5464
 *                                           infolist
 
5465
 */
 
5466
 
 
5467
static PyObject *
 
5468
weechat_python_api_infolist_new_var_time (PyObject *self, PyObject *args)
 
5469
{
 
5470
    char *infolist, *name, *result;
 
5471
    int value;
 
5472
    PyObject *object;
 
5473
    
 
5474
    /* make C compiler happy */
 
5475
    (void) self;
 
5476
    
 
5477
    if (!python_current_script)
 
5478
    {
 
5479
        WEECHAT_SCRIPT_MSG_NOT_INIT(PYTHON_CURRENT_SCRIPT_NAME, "infolist_new_var_time");
 
5480
        PYTHON_RETURN_EMPTY;
 
5481
    }
 
5482
    
 
5483
    infolist = NULL;
 
5484
    name = NULL;
 
5485
    value = 0;
 
5486
    
 
5487
    if (!PyArg_ParseTuple (args, "ssi", &infolist, &name, &value))
 
5488
    {
 
5489
        WEECHAT_SCRIPT_MSG_WRONG_ARGS(PYTHON_CURRENT_SCRIPT_NAME, "infolist_new_var_time");
 
5490
        PYTHON_RETURN_EMPTY;
 
5491
    }
 
5492
    
 
5493
    result = script_ptr2str (weechat_infolist_new_var_time (script_str2ptr (infolist),
 
5494
                                                            name,
 
5495
                                                            value));
 
5496
    
 
5497
    PYTHON_RETURN_STRING_FREE(result);
 
5498
}
 
5499
 
 
5500
/*
 
5501
 * weechat_python_api_infolist_get: get list with infos
 
5502
 */
 
5503
 
 
5504
static PyObject *
 
5505
weechat_python_api_infolist_get (PyObject *self, PyObject *args)
 
5506
{
 
5507
    char *name, *pointer, *arguments, *result;
 
5508
    PyObject *object;
 
5509
    
 
5510
    /* make C compiler happy */
 
5511
    (void) self;
 
5512
    
 
5513
    if (!python_current_script)
 
5514
    {
 
5515
        WEECHAT_SCRIPT_MSG_NOT_INIT(PYTHON_CURRENT_SCRIPT_NAME, "infolist_get");
 
5516
        PYTHON_RETURN_EMPTY;
 
5517
    }
 
5518
    
 
5519
    name = NULL;
 
5520
    pointer = NULL;
 
5521
    arguments = NULL;
 
5522
    
 
5523
    if (!PyArg_ParseTuple (args, "sss", &name, &pointer, &arguments))
 
5524
    {
 
5525
        WEECHAT_SCRIPT_MSG_WRONG_ARGS(PYTHON_CURRENT_SCRIPT_NAME, "infolist_get");
 
5526
        PYTHON_RETURN_EMPTY;
 
5527
    }
 
5528
    
 
5529
    result = script_ptr2str (weechat_infolist_get (name,
 
5530
                                                   script_str2ptr (pointer),
 
5531
                                                   arguments));
 
5532
    
 
5533
    PYTHON_RETURN_STRING_FREE(result);
 
5534
}
 
5535
 
 
5536
/*
 
5537
 * weechat_python_api_infolist_next: move item pointer to next item in infolist
 
5538
 */
 
5539
 
 
5540
static PyObject *
 
5541
weechat_python_api_infolist_next (PyObject *self, PyObject *args)
 
5542
{
 
5543
    char *infolist;
 
5544
    int value;
 
5545
    
 
5546
    /* make C compiler happy */
 
5547
    (void) self;
 
5548
    
 
5549
    if (!python_current_script)
 
5550
    {
 
5551
        WEECHAT_SCRIPT_MSG_NOT_INIT(PYTHON_CURRENT_SCRIPT_NAME, "infolist_next");
 
5552
        PYTHON_RETURN_INT(0);
 
5553
    }
 
5554
    
 
5555
    infolist = NULL;
 
5556
    
 
5557
    if (!PyArg_ParseTuple (args, "s", &infolist))
 
5558
    {
 
5559
        WEECHAT_SCRIPT_MSG_WRONG_ARGS(PYTHON_CURRENT_SCRIPT_NAME, "infolist_next");
 
5560
        PYTHON_RETURN_INT(0);
 
5561
    }
 
5562
    
 
5563
    value = weechat_infolist_next (script_str2ptr (infolist));
 
5564
    
 
5565
    PYTHON_RETURN_INT(value);
 
5566
}
 
5567
 
 
5568
/*
 
5569
 * weechat_python_api_infolist_prev: move item pointer to previous item in infolist
 
5570
 */
 
5571
 
 
5572
static PyObject *
 
5573
weechat_python_api_infolist_prev (PyObject *self, PyObject *args)
 
5574
{
 
5575
    char *infolist;
 
5576
    int value;
 
5577
    
 
5578
    /* make C compiler happy */
 
5579
    (void) self;
 
5580
    
 
5581
    if (!python_current_script)
 
5582
    {
 
5583
        WEECHAT_SCRIPT_MSG_NOT_INIT(PYTHON_CURRENT_SCRIPT_NAME, "infolist_prev");
 
5584
        PYTHON_RETURN_INT(0);
 
5585
    }
 
5586
    
 
5587
    infolist = NULL;
 
5588
    
 
5589
    if (!PyArg_ParseTuple (args, "s", &infolist))
 
5590
    {
 
5591
        WEECHAT_SCRIPT_MSG_WRONG_ARGS(PYTHON_CURRENT_SCRIPT_NAME, "infolist_prev");
 
5592
        PYTHON_RETURN_INT(0);
 
5593
    }
 
5594
    
 
5595
    value = weechat_infolist_prev (script_str2ptr (infolist));
 
5596
    
 
5597
    PYTHON_RETURN_INT(value);
 
5598
}
 
5599
 
 
5600
/*
 
5601
 * weechat_python_api_infolist_fields: get list of fields for current item of infolist
 
5602
 */
 
5603
 
 
5604
static PyObject *
 
5605
weechat_python_api_infolist_fields (PyObject *self, PyObject *args)
 
5606
{
 
5607
    char *infolist;
 
5608
    const char *result;
 
5609
    
 
5610
    /* make C compiler happy */
 
5611
    (void) self;
 
5612
    
 
5613
    if (!python_current_script)
 
5614
    {
 
5615
        WEECHAT_SCRIPT_MSG_NOT_INIT(PYTHON_CURRENT_SCRIPT_NAME, "infolist_fields");
 
5616
        PYTHON_RETURN_EMPTY;
 
5617
    }
 
5618
    
 
5619
    infolist = NULL;
 
5620
    
 
5621
    if (!PyArg_ParseTuple (args, "s", &infolist))
 
5622
    {
 
5623
        WEECHAT_SCRIPT_MSG_WRONG_ARGS(PYTHON_CURRENT_SCRIPT_NAME, "infolist_fields");
 
5624
        PYTHON_RETURN_EMPTY;
 
5625
    }
 
5626
    
 
5627
    result = weechat_infolist_fields (script_str2ptr (infolist));
 
5628
    
 
5629
    PYTHON_RETURN_STRING(result);
 
5630
}
 
5631
 
 
5632
/*
 
5633
 * weechat_python_api_infolist_integer: get integer value of a variable in infolist
 
5634
 */
 
5635
 
 
5636
static PyObject *
 
5637
weechat_python_api_infolist_integer (PyObject *self, PyObject *args)
 
5638
{
 
5639
    char *infolist, *variable;
 
5640
    int value;
 
5641
    
 
5642
    /* make C compiler happy */
 
5643
    (void) self;
 
5644
    
 
5645
    if (!python_current_script)
 
5646
    {
 
5647
        WEECHAT_SCRIPT_MSG_NOT_INIT(PYTHON_CURRENT_SCRIPT_NAME, "infolist_integer");
 
5648
        PYTHON_RETURN_INT(0);
 
5649
    }
 
5650
    
 
5651
    infolist = NULL;
 
5652
    variable = NULL;
 
5653
    
 
5654
    if (!PyArg_ParseTuple (args, "ss", &infolist, &variable))
 
5655
    {
 
5656
        WEECHAT_SCRIPT_MSG_WRONG_ARGS(PYTHON_CURRENT_SCRIPT_NAME, "infolist_integer");
 
5657
        PYTHON_RETURN_INT(0);
 
5658
    }
 
5659
    
 
5660
    value = weechat_infolist_integer (script_str2ptr (infolist),
 
5661
                                      variable);
 
5662
    
 
5663
    PYTHON_RETURN_INT(value);
 
5664
}
 
5665
 
 
5666
/*
 
5667
 * weechat_python_api_infolist_string: get string value of a variable in infolist
 
5668
 */
 
5669
 
 
5670
static PyObject *
 
5671
weechat_python_api_infolist_string (PyObject *self, PyObject *args)
 
5672
{
 
5673
    char *infolist, *variable;
 
5674
    const char *result;
 
5675
    
 
5676
    /* make C compiler happy */
 
5677
    (void) self;
 
5678
    
 
5679
    if (!python_current_script)
 
5680
    {
 
5681
        WEECHAT_SCRIPT_MSG_NOT_INIT(PYTHON_CURRENT_SCRIPT_NAME, "infolist_string");
 
5682
        PYTHON_RETURN_EMPTY;
 
5683
    }
 
5684
    
 
5685
    infolist = NULL;
 
5686
    variable = NULL;
 
5687
    
 
5688
    if (!PyArg_ParseTuple (args, "ss", &infolist, &variable))
 
5689
    {
 
5690
        WEECHAT_SCRIPT_MSG_WRONG_ARGS(PYTHON_CURRENT_SCRIPT_NAME, "infolist_string");
 
5691
        PYTHON_RETURN_EMPTY;
 
5692
    }
 
5693
    
 
5694
    result = weechat_infolist_string (script_str2ptr (infolist),
 
5695
                                      variable);
 
5696
    
 
5697
    PYTHON_RETURN_STRING(result);
 
5698
}
 
5699
 
 
5700
/*
 
5701
 * weechat_python_api_infolist_pointer: get pointer value of a variable in infolist
 
5702
 */
 
5703
 
 
5704
static PyObject *
 
5705
weechat_python_api_infolist_pointer (PyObject *self, PyObject *args)
 
5706
{
 
5707
    char *infolist, *variable, *result;
 
5708
    PyObject *object;
 
5709
    
 
5710
    /* make C compiler happy */
 
5711
    (void) self;
 
5712
    
 
5713
    if (!python_current_script)
 
5714
    {
 
5715
        WEECHAT_SCRIPT_MSG_NOT_INIT(PYTHON_CURRENT_SCRIPT_NAME, "infolist_pointer");
 
5716
        PYTHON_RETURN_EMPTY;
 
5717
    }
 
5718
    
 
5719
    infolist = NULL;
 
5720
    variable = NULL;
 
5721
    
 
5722
    if (!PyArg_ParseTuple (args, "ss", &infolist, &variable))
 
5723
    {
 
5724
        WEECHAT_SCRIPT_MSG_WRONG_ARGS(PYTHON_CURRENT_SCRIPT_NAME, "infolist_pointer");
 
5725
        PYTHON_RETURN_EMPTY;
 
5726
    }
 
5727
    
 
5728
    result = script_ptr2str (weechat_infolist_pointer (script_str2ptr (infolist),
 
5729
                                                       variable));
 
5730
    
 
5731
    PYTHON_RETURN_STRING_FREE(result);
 
5732
}
 
5733
 
 
5734
/*
 
5735
 * weechat_python_api_infolist_time: get time value of a variable in infolist
 
5736
 */
 
5737
 
 
5738
static PyObject *
 
5739
weechat_python_api_infolist_time (PyObject *self, PyObject *args)
 
5740
{
 
5741
    char *infolist, *variable, timebuffer[64], *result;
 
5742
    time_t time;
 
5743
    PyObject *object;
 
5744
    
 
5745
    /* make C compiler happy */
 
5746
    (void) self;
 
5747
    
 
5748
    if (!python_current_script)
 
5749
    {
 
5750
        WEECHAT_SCRIPT_MSG_NOT_INIT(PYTHON_CURRENT_SCRIPT_NAME, "infolist_time");
 
5751
        PYTHON_RETURN_EMPTY;
 
5752
    }
 
5753
    
 
5754
    infolist = NULL;
 
5755
    variable = NULL;
 
5756
    
 
5757
    if (!PyArg_ParseTuple (args, "ss", &infolist, &variable))
 
5758
    {
 
5759
        WEECHAT_SCRIPT_MSG_WRONG_ARGS(PYTHON_CURRENT_SCRIPT_NAME, "infolist_time");
 
5760
        PYTHON_RETURN_EMPTY;
 
5761
    }
 
5762
    
 
5763
    time = weechat_infolist_time (script_str2ptr (infolist),
 
5764
                                  variable);
 
5765
    strftime (timebuffer, sizeof (timebuffer), "%F %T", localtime (&time));
 
5766
    result = strdup (timebuffer);
 
5767
    
 
5768
    PYTHON_RETURN_STRING_FREE(result);
 
5769
}
 
5770
 
 
5771
/*
 
5772
 * weechat_python_api_infolist_free: free infolist
 
5773
 */
 
5774
 
 
5775
static PyObject *
 
5776
weechat_python_api_infolist_free (PyObject *self, PyObject *args)
 
5777
{
 
5778
    char *infolist;
 
5779
    
 
5780
    /* make C compiler happy */
 
5781
    (void) self;
 
5782
    
 
5783
    if (!python_current_script)
 
5784
    {
 
5785
        WEECHAT_SCRIPT_MSG_NOT_INIT(PYTHON_CURRENT_SCRIPT_NAME, "infolist_free");
 
5786
        PYTHON_RETURN_ERROR;
 
5787
    }
 
5788
    
 
5789
    infolist = NULL;
 
5790
    
 
5791
    if (!PyArg_ParseTuple (args, "s", &infolist))
 
5792
    {
 
5793
        WEECHAT_SCRIPT_MSG_WRONG_ARGS(PYTHON_CURRENT_SCRIPT_NAME, "infolist_free");
 
5794
        PYTHON_RETURN_ERROR;
 
5795
    }
 
5796
    
 
5797
    weechat_infolist_free (script_str2ptr (infolist));
 
5798
    
 
5799
    PYTHON_RETURN_OK;
 
5800
}
 
5801
 
 
5802
/*
 
5803
 * weechat_python_api_upgrade_new: create an upgrade file
 
5804
 */
 
5805
 
 
5806
static PyObject *
 
5807
weechat_python_api_upgrade_new (PyObject *self, PyObject *args)
 
5808
{
 
5809
    char *filename, *result;
 
5810
    int write;
 
5811
    PyObject *object;
 
5812
    
 
5813
    /* make C compiler happy */
 
5814
    (void) self;
 
5815
    
 
5816
    if (!python_current_script)
 
5817
    {
 
5818
        WEECHAT_SCRIPT_MSG_NOT_INIT(PYTHON_CURRENT_SCRIPT_NAME, "upgrade_new");
 
5819
        PYTHON_RETURN_EMPTY;
 
5820
    }
 
5821
    
 
5822
    filename = NULL;
 
5823
    write = 0;
 
5824
    
 
5825
    if (!PyArg_ParseTuple (args, "si", &filename, &write))
 
5826
    {
 
5827
        WEECHAT_SCRIPT_MSG_WRONG_ARGS(PYTHON_CURRENT_SCRIPT_NAME, "upgrade_new");
 
5828
        PYTHON_RETURN_EMPTY;
 
5829
    }
 
5830
    
 
5831
    result = script_ptr2str (weechat_upgrade_new (filename, write));
 
5832
    
 
5833
    PYTHON_RETURN_STRING_FREE(result);
 
5834
}
 
5835
 
 
5836
/*
 
5837
 * weechat_python_api_upgrade_write_object: write object in upgrade file
 
5838
 */
 
5839
 
 
5840
static PyObject *
 
5841
weechat_python_api_upgrade_write_object (PyObject *self, PyObject *args)
 
5842
{
 
5843
    char *upgrade_file, *infolist;
 
5844
    int object_id, rc;
 
5845
    
 
5846
    /* make C compiler happy */
 
5847
    (void) self;
 
5848
    
 
5849
    if (!python_current_script)
 
5850
    {
 
5851
        WEECHAT_SCRIPT_MSG_NOT_INIT(PYTHON_CURRENT_SCRIPT_NAME, "upgrade_write_object");
 
5852
        PYTHON_RETURN_INT(0);
 
5853
    }
 
5854
    
 
5855
    upgrade_file = NULL;
 
5856
    object_id = 0;
 
5857
    infolist = NULL;
 
5858
    
 
5859
    if (!PyArg_ParseTuple (args, "sis", &upgrade_file, &object_id, &infolist))
 
5860
    {
 
5861
        WEECHAT_SCRIPT_MSG_WRONG_ARGS(PYTHON_CURRENT_SCRIPT_NAME, "upgrade_write_object");
 
5862
        PYTHON_RETURN_INT(0);
 
5863
    }
 
5864
    
 
5865
    rc = weechat_upgrade_write_object (script_str2ptr (upgrade_file),
 
5866
                                       object_id,
 
5867
                                       script_str2ptr (infolist));
 
5868
    
 
5869
    PYTHON_RETURN_INT(rc);
 
5870
}
 
5871
 
 
5872
/*
 
5873
 * weechat_python_api_upgrade_read_cb: callback for reading object in upgrade file
 
5874
 */
 
5875
 
 
5876
int
 
5877
weechat_python_api_upgrade_read_cb (void *data,
 
5878
                                    struct t_upgrade_file *upgrade_file,
 
5879
                                    int object_id,
 
5880
                                    struct t_infolist *infolist)
 
5881
{
 
5882
    struct t_script_callback *script_callback;
 
5883
    char *python_argv[5], empty_arg[1] = { '\0' }, str_object_id[32];
 
5884
    int *rc, ret;
 
5885
    
 
5886
    script_callback = (struct t_script_callback *)data;
 
5887
    
 
5888
    if (script_callback && script_callback->function && script_callback->function[0])
 
5889
    {
 
5890
        snprintf (str_object_id, sizeof (str_object_id), "%d", object_id);
 
5891
        
 
5892
        python_argv[0] = (script_callback->data) ? script_callback->data : empty_arg;
 
5893
        python_argv[1] = script_ptr2str (upgrade_file);
 
5894
        python_argv[2] = str_object_id;
 
5895
        python_argv[3] = script_ptr2str (infolist);
 
5896
        python_argv[4] = NULL;
 
5897
        
 
5898
        rc = (int *) weechat_python_exec (script_callback->script,
 
5899
                                          WEECHAT_SCRIPT_EXEC_INT,
 
5900
                                          script_callback->function,
 
5901
                                          python_argv);
 
5902
        
 
5903
        if (!rc)
 
5904
            ret = WEECHAT_RC_ERROR;
 
5905
        else
 
5906
        {
 
5907
            ret = *rc;
 
5908
            free (rc);
 
5909
        }
 
5910
        if (python_argv[1])
 
5911
            free (python_argv[1]);
 
5912
        if (python_argv[3])
 
5913
            free (python_argv[3]);
 
5914
        
 
5915
        return ret;
 
5916
    }
 
5917
    
 
5918
    return WEECHAT_RC_ERROR;
 
5919
}
 
5920
 
 
5921
/*
 
5922
 * weechat_python_api_upgrade_read: read upgrade file
 
5923
 */
 
5924
 
 
5925
static PyObject *
 
5926
weechat_python_api_upgrade_read (PyObject *self, PyObject *args)
 
5927
{
 
5928
    char *upgrade_file, *function, *data;
 
5929
    int rc;
 
5930
    
 
5931
    /* make C compiler happy */
 
5932
    (void) self;
 
5933
    
 
5934
    if (!python_current_script)
 
5935
    {
 
5936
        WEECHAT_SCRIPT_MSG_NOT_INIT(PYTHON_CURRENT_SCRIPT_NAME, "upgrade_read");
 
5937
        PYTHON_RETURN_INT(0);
 
5938
    }
 
5939
    
 
5940
    upgrade_file = NULL;
 
5941
    function = NULL;
 
5942
    data = NULL;
 
5943
    
 
5944
    if (!PyArg_ParseTuple (args, "sss", &upgrade_file, &function, &data))
 
5945
    {
 
5946
        WEECHAT_SCRIPT_MSG_WRONG_ARGS(PYTHON_CURRENT_SCRIPT_NAME, "upgrade_read");
 
5947
        PYTHON_RETURN_INT(0);
 
5948
    }
 
5949
    
 
5950
    rc = script_api_upgrade_read (weechat_python_plugin,
 
5951
                                  python_current_script,
 
5952
                                  script_str2ptr (upgrade_file),
 
5953
                                  &weechat_python_api_upgrade_read_cb,
 
5954
                                  function,
 
5955
                                  data);
 
5956
    
 
5957
    PYTHON_RETURN_INT(rc);
 
5958
}
 
5959
 
 
5960
/*
 
5961
 * weechat_python_api_upgrade_close: close upgrade file
 
5962
 */
 
5963
 
 
5964
static PyObject *
 
5965
weechat_python_api_upgrade_close (PyObject *self, PyObject *args)
 
5966
{
 
5967
    char *upgrade_file;
 
5968
    
 
5969
    /* make C compiler happy */
 
5970
    (void) self;
 
5971
    
 
5972
    if (!python_current_script)
 
5973
    {
 
5974
        WEECHAT_SCRIPT_MSG_NOT_INIT(PYTHON_CURRENT_SCRIPT_NAME, "upgrade_close");
 
5975
        PYTHON_RETURN_ERROR;
 
5976
    }
 
5977
    
 
5978
    upgrade_file = NULL;
 
5979
    
 
5980
    if (!PyArg_ParseTuple (args, "s", &upgrade_file))
 
5981
    {
 
5982
        WEECHAT_SCRIPT_MSG_WRONG_ARGS(PYTHON_CURRENT_SCRIPT_NAME, "upgrade_close");
 
5983
        PYTHON_RETURN_ERROR;
 
5984
    }
 
5985
    
 
5986
    weechat_upgrade_close (script_str2ptr (upgrade_file));
 
5987
    
 
5988
    PYTHON_RETURN_OK;
 
5989
}
 
5990
 
 
5991
/*
 
5992
 * Python subroutines
 
5993
 */
 
5994
 
 
5995
PyMethodDef weechat_python_funcs[] =
 
5996
{
 
5997
    { "register", &weechat_python_api_register, METH_VARARGS, "" },
 
5998
    { "plugin_get_name", &weechat_python_api_plugin_get_name, METH_VARARGS, "" },
 
5999
    { "charset_set", &weechat_python_api_charset_set, METH_VARARGS, "" },
 
6000
    { "iconv_to_internal", &weechat_python_api_iconv_to_internal, METH_VARARGS, "" },
 
6001
    { "iconv_from_internal", &weechat_python_api_iconv_from_internal, METH_VARARGS, "" },
 
6002
    { "gettext", &weechat_python_api_gettext, METH_VARARGS, "" },
 
6003
    { "ngettext", &weechat_python_api_ngettext, METH_VARARGS, "" },
 
6004
    { "string_remove_color", &weechat_python_api_string_remove_color, METH_VARARGS, "" },
 
6005
    { "mkdir_home", &weechat_python_api_mkdir_home, METH_VARARGS, "" },
 
6006
    { "mkdir", &weechat_python_api_mkdir, METH_VARARGS, "" },
 
6007
    { "mkdir_parents", &weechat_python_api_mkdir_parents, METH_VARARGS, "" },
 
6008
    { "list_new", &weechat_python_api_list_new, METH_VARARGS, "" },
 
6009
    { "list_add", &weechat_python_api_list_add, METH_VARARGS, "" },
 
6010
    { "list_search", &weechat_python_api_list_search, METH_VARARGS, "" },
 
6011
    { "list_casesearch", &weechat_python_api_list_casesearch, METH_VARARGS, "" },
 
6012
    { "list_get", &weechat_python_api_list_get, METH_VARARGS, "" },
 
6013
    { "list_set", &weechat_python_api_list_set, METH_VARARGS, "" },
 
6014
    { "list_next", &weechat_python_api_list_next, METH_VARARGS, "" },
 
6015
    { "list_prev", &weechat_python_api_list_prev, METH_VARARGS, "" },
 
6016
    { "list_string", &weechat_python_api_list_string, METH_VARARGS, "" },
 
6017
    { "list_size", &weechat_python_api_list_size, METH_VARARGS, "" },
 
6018
    { "list_remove", &weechat_python_api_list_remove, METH_VARARGS, "" },
 
6019
    { "list_remove_all", &weechat_python_api_list_remove_all, METH_VARARGS, "" },
 
6020
    { "list_free", &weechat_python_api_list_free, METH_VARARGS, "" },
 
6021
    { "config_new", &weechat_python_api_config_new, METH_VARARGS, "" },
 
6022
    { "config_new_section", &weechat_python_api_config_new_section, METH_VARARGS, "" },
 
6023
    { "config_search_section", &weechat_python_api_config_search_section, METH_VARARGS, "" },
 
6024
    { "config_new_option", &weechat_python_api_config_new_option, METH_VARARGS, "" },
 
6025
    { "config_search_option", &weechat_python_api_config_search_option, METH_VARARGS, "" },
 
6026
    { "config_string_to_boolean", &weechat_python_api_config_string_to_boolean, METH_VARARGS, "" },
 
6027
    { "config_option_reset", &weechat_python_api_config_option_reset, METH_VARARGS, "" },
 
6028
    { "config_option_set", &weechat_python_api_config_option_set, METH_VARARGS, "" },
 
6029
    { "config_option_set_null", &weechat_python_api_config_option_set_null, METH_VARARGS, "" },
 
6030
    { "config_option_unset", &weechat_python_api_config_option_unset, METH_VARARGS, "" },
 
6031
    { "config_option_rename", &weechat_python_api_config_option_rename, METH_VARARGS, "" },
 
6032
    { "config_option_is_null", &weechat_python_api_config_option_is_null, METH_VARARGS, "" },
 
6033
    { "config_option_default_is_null", &weechat_python_api_config_option_default_is_null, METH_VARARGS, "" },
 
6034
    { "config_boolean", &weechat_python_api_config_boolean, METH_VARARGS, "" },
 
6035
    { "config_boolean_default", &weechat_python_api_config_boolean_default, METH_VARARGS, "" },
 
6036
    { "config_integer", &weechat_python_api_config_integer, METH_VARARGS, "" },
 
6037
    { "config_integer_default", &weechat_python_api_config_integer_default, METH_VARARGS, "" },
 
6038
    { "config_string", &weechat_python_api_config_string, METH_VARARGS, "" },
 
6039
    { "config_string_default", &weechat_python_api_config_string_default, METH_VARARGS, "" },
 
6040
    { "config_color", &weechat_python_api_config_color, METH_VARARGS, "" },
 
6041
    { "config_color_default", &weechat_python_api_config_color_default, METH_VARARGS, "" },
 
6042
    { "config_write_option", &weechat_python_api_config_write_option, METH_VARARGS, "" },
 
6043
    { "config_write_line", &weechat_python_api_config_write_line, METH_VARARGS, "" },
 
6044
    { "config_write", &weechat_python_api_config_write, METH_VARARGS, "" },
 
6045
    { "config_read", &weechat_python_api_config_read, METH_VARARGS, "" },
 
6046
    { "config_reload", &weechat_python_api_config_reload, METH_VARARGS, "" },
 
6047
    { "config_option_free", &weechat_python_api_config_option_free, METH_VARARGS, "" },
 
6048
    { "config_section_free_options", &weechat_python_api_config_section_free_options, METH_VARARGS, "" },
 
6049
    { "config_section_free", &weechat_python_api_config_section_free, METH_VARARGS, "" },
 
6050
    { "config_free", &weechat_python_api_config_free, METH_VARARGS, "" },
 
6051
    { "config_get", &weechat_python_api_config_get, METH_VARARGS, "" },
 
6052
    { "config_get_plugin", &weechat_python_api_config_get_plugin, METH_VARARGS, "" },
 
6053
    { "config_is_set_plugin", &weechat_python_api_config_is_set_plugin, METH_VARARGS, "" },
 
6054
    { "config_set_plugin", &weechat_python_api_config_set_plugin, METH_VARARGS, "" },
 
6055
    { "config_unset_plugin", &weechat_python_api_config_unset_plugin, METH_VARARGS, "" },
 
6056
    { "prefix", &weechat_python_api_prefix, METH_VARARGS, "" },
 
6057
    { "color", &weechat_python_api_color, METH_VARARGS, "" },
 
6058
    { "prnt", &weechat_python_api_prnt, METH_VARARGS, "" },
 
6059
    { "prnt_date_tags", &weechat_python_api_prnt_date_tags, METH_VARARGS, "" },
 
6060
    { "prnt_y", &weechat_python_api_prnt_y, METH_VARARGS, "" },
 
6061
    { "log_print", &weechat_python_api_log_print, METH_VARARGS, "" },
 
6062
    { "hook_command", &weechat_python_api_hook_command, METH_VARARGS, "" },
 
6063
    { "hook_command_run", &weechat_python_api_hook_command_run, METH_VARARGS, "" },
 
6064
    { "hook_timer", &weechat_python_api_hook_timer, METH_VARARGS, "" },
 
6065
    { "hook_fd", &weechat_python_api_hook_fd, METH_VARARGS, "" },
 
6066
    { "hook_process", &weechat_python_api_hook_process, METH_VARARGS, "" },
 
6067
    { "hook_connect", &weechat_python_api_hook_connect, METH_VARARGS, "" },
 
6068
    { "hook_print", &weechat_python_api_hook_print, METH_VARARGS, "" },
 
6069
    { "hook_signal", &weechat_python_api_hook_signal, METH_VARARGS, "" },
 
6070
    { "hook_signal_send", &weechat_python_api_hook_signal_send, METH_VARARGS, "" },
 
6071
    { "hook_config", &weechat_python_api_hook_config, METH_VARARGS, "" },
 
6072
    { "hook_completion", &weechat_python_api_hook_completion, METH_VARARGS, "" },
 
6073
    { "hook_completion_list_add", &weechat_python_api_hook_completion_list_add, METH_VARARGS, "" },
 
6074
    { "hook_modifier", &weechat_python_api_hook_modifier, METH_VARARGS, "" },
 
6075
    { "hook_modifier_exec", &weechat_python_api_hook_modifier_exec, METH_VARARGS, "" },
 
6076
    { "hook_info", &weechat_python_api_hook_info, METH_VARARGS, "" },
 
6077
    { "hook_infolist", &weechat_python_api_hook_infolist, METH_VARARGS, "" },
 
6078
    { "unhook", &weechat_python_api_unhook, METH_VARARGS, "" },
 
6079
    { "unhook_all", &weechat_python_api_unhook_all, METH_VARARGS, "" },
 
6080
    { "buffer_new", &weechat_python_api_buffer_new, METH_VARARGS, "" },
 
6081
    { "buffer_search", &weechat_python_api_buffer_search, METH_VARARGS, "" },
 
6082
    { "buffer_search_main", &weechat_python_api_buffer_search_main, METH_VARARGS, "" },
 
6083
    { "current_buffer", &weechat_python_api_current_buffer, METH_VARARGS, "" },
 
6084
    { "buffer_clear", &weechat_python_api_buffer_clear, METH_VARARGS, "" },
 
6085
    { "buffer_close", &weechat_python_api_buffer_close, METH_VARARGS, "" },
 
6086
    { "buffer_merge", &weechat_python_api_buffer_merge, METH_VARARGS, "" },
 
6087
    { "buffer_unmerge", &weechat_python_api_buffer_unmerge, METH_VARARGS, "" },
 
6088
    { "buffer_get_integer", &weechat_python_api_buffer_get_integer, METH_VARARGS, "" },
 
6089
    { "buffer_get_string", &weechat_python_api_buffer_get_string, METH_VARARGS, "" },
 
6090
    { "buffer_get_pointer", &weechat_python_api_buffer_get_pointer, METH_VARARGS, "" },
 
6091
    { "buffer_set", &weechat_python_api_buffer_set, METH_VARARGS, "" },
 
6092
    { "current_window", &weechat_python_api_current_window, METH_VARARGS, "" },
 
6093
    { "window_get_integer", &weechat_python_api_window_get_integer, METH_VARARGS, "" },
 
6094
    { "window_get_string", &weechat_python_api_window_get_string, METH_VARARGS, "" },
 
6095
    { "window_get_pointer", &weechat_python_api_window_get_pointer, METH_VARARGS, "" },
 
6096
    { "window_set_title", &weechat_python_api_window_set_title, METH_VARARGS, "" },
 
6097
    { "nicklist_add_group", &weechat_python_api_nicklist_add_group, METH_VARARGS, "" },
 
6098
    { "nicklist_search_group", &weechat_python_api_nicklist_search_group, METH_VARARGS, "" },
 
6099
    { "nicklist_add_nick", &weechat_python_api_nicklist_add_nick, METH_VARARGS, "" },
 
6100
    { "nicklist_search_nick", &weechat_python_api_nicklist_search_nick, METH_VARARGS, "" },
 
6101
    { "nicklist_remove_group", &weechat_python_api_nicklist_remove_group, METH_VARARGS, "" },
 
6102
    { "nicklist_remove_nick", &weechat_python_api_nicklist_remove_nick, METH_VARARGS, "" },
 
6103
    { "nicklist_remove_all", &weechat_python_api_nicklist_remove_all, METH_VARARGS, "" },
 
6104
    { "bar_item_search", &weechat_python_api_bar_item_search, METH_VARARGS, "" },
 
6105
    { "bar_item_new", &weechat_python_api_bar_item_new, METH_VARARGS, "" },
 
6106
    { "bar_item_update", &weechat_python_api_bar_item_update, METH_VARARGS, "" },
 
6107
    { "bar_item_remove", &weechat_python_api_bar_item_remove, METH_VARARGS, "" },
 
6108
    { "bar_search", &weechat_python_api_bar_search, METH_VARARGS, "" },
 
6109
    { "bar_new", &weechat_python_api_bar_new, METH_VARARGS, "" },
 
6110
    { "bar_set", &weechat_python_api_bar_set, METH_VARARGS, "" },
 
6111
    { "bar_update", &weechat_python_api_bar_update, METH_VARARGS, "" },
 
6112
    { "bar_remove", &weechat_python_api_bar_remove, METH_VARARGS, "" },
 
6113
    { "command", &weechat_python_api_command, METH_VARARGS, "" },
 
6114
    { "info_get", &weechat_python_api_info_get, METH_VARARGS, "" },
 
6115
    { "infolist_new", &weechat_python_api_infolist_new, METH_VARARGS, "" },
 
6116
    { "infolist_new_var_integer", &weechat_python_api_infolist_new_var_integer, METH_VARARGS, "" },
 
6117
    { "infolist_new_var_string", &weechat_python_api_infolist_new_var_string, METH_VARARGS, "" },
 
6118
    { "infolist_new_var_pointer", &weechat_python_api_infolist_new_var_pointer, METH_VARARGS, "" },
 
6119
    { "infolist_new_var_time", &weechat_python_api_infolist_new_var_time, METH_VARARGS, "" },
 
6120
    { "infolist_get", &weechat_python_api_infolist_get, METH_VARARGS, "" },
 
6121
    { "infolist_next", &weechat_python_api_infolist_next, METH_VARARGS, "" },
 
6122
    { "infolist_prev", &weechat_python_api_infolist_prev, METH_VARARGS, "" },
 
6123
    { "infolist_fields", &weechat_python_api_infolist_fields, METH_VARARGS, "" },
 
6124
    { "infolist_integer", &weechat_python_api_infolist_integer, METH_VARARGS, "" },
 
6125
    { "infolist_string", &weechat_python_api_infolist_string, METH_VARARGS, "" },
 
6126
    { "infolist_pointer", &weechat_python_api_infolist_pointer, METH_VARARGS, "" },
 
6127
    { "infolist_time", &weechat_python_api_infolist_time, METH_VARARGS, "" },
 
6128
    { "infolist_free", &weechat_python_api_infolist_free, METH_VARARGS, "" },
 
6129
    { "upgrade_new", &weechat_python_api_upgrade_new, METH_VARARGS, "" },
 
6130
    { "upgrade_write_object", &weechat_python_api_upgrade_write_object, METH_VARARGS, "" },
 
6131
    { "upgrade_read", &weechat_python_api_upgrade_read, METH_VARARGS, "" },
 
6132
    { "upgrade_close", &weechat_python_api_upgrade_close, METH_VARARGS, "" },
 
6133
    { NULL, NULL, 0, NULL }
 
6134
};