2
* This program is free software; you can redistribute it and/or modify
3
* it under the terms of the GNU General Public License as published by
4
* the Free Software Foundation; either version 2 of the License, or
5
* (at your option) any later version.
7
* This program is distributed in the hope that it will be useful,
8
* but WITHOUT ANY WARRANTY; without even the implied warranty of
9
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10
* GNU General Public License for more details.
12
* You should have received a copy of the GNU General Public License
13
* along with this program; if not, write to the Free Software
14
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16
* Author : Richard GAYRAUD - 04 Nov 2003
18
* From Hewlett Packard Company.
19
* Charles P Wright from IBM Research
23
/* This is a fun sample of creating your own extensible keyword. */
24
int fortune(call *call, MessageComponent *comp, char *buf, int len) {
26
char localbuf[SIPP_MAX_MSG_SIZE];
31
if (pipe(pipes) == -1) {
32
ERROR("Could not create pipes!\n");
37
ERROR("Fork failed: %s\n", strerror(errno));
39
/* We are the child. */
41
dup2(pipes[1], fileno(stdout));
42
dup2(pipes[1], fileno(stderr));
44
system("/usr/bin/fortune");
47
/* We are the parent*/
49
while ((ret = read(pipes[0], p, sizeof(localbuf) - (p - localbuf))) > 0) {
55
if (len > p - localbuf) {
81
/* On initialization we register our keywords. */
82
extern "C" int init(void) {
83
registerKeyword("fortune", fortune);