File: generic-connect.c

package info (click to toggle)
cheops 0.61-15.1
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 1,272 kB
  • ctags: 1,312
  • sloc: ansic: 12,731; sh: 155; makefile: 151
file content (89 lines) | stat: -rw-r--r-- 1,524 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
/*
 * Cheops Network User Interface
 *
 * Copyright (C) 1999, Adtran, Inc.
 * 
 * Distributed under the terms of the GNU GPL
 *
 */

#include <gtk/gtk.h>
#include <netinet/in.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "cheops.h"
#include "plugins.h"

char *plugin_name()
{
	return "standard";
}

char *plugin_label()
{
	return "Generic";
}

int plugin_type()
{
	return TYPE_SERVICE;
}

int service_connect(struct service *svc, char *hostname, char *ip, char *username, int porti)
{
	char buf[1024];
	char port[40];
	char *s;
	int x=0;
	memset(buf, 0, sizeof(buf));
	s=svc->format;	
	g_snprintf(port, sizeof(port), "%d", porti);
	while(*s && x < sizeof(buf)) {
		switch(*s) {
		case '%':
			s++;
			switch(*s) {
			case 'i':
				strncat(buf, ip, sizeof(buf) - x);
				x = strlen(buf) - 1;
				break;
			case 'h':
				strncat(buf, hostname, sizeof(buf) - x);
				x = strlen(buf) - 1;
				break;
			case 'u':
				strncat(buf, username, sizeof(buf) - x);
				x = strlen(buf) - 1;
				break;
			case 'p':
				strncat(buf, port, sizeof(buf) - x);
				x = strlen(buf) - 1;
				break;
			case 'x':
				strncat(buf, xterm, sizeof(buf) - x);
				x = strlen(buf) - 1;
				break;
			case '%':
				strncat(buf, "%", sizeof(buf) - x);
				x = strlen(buf) - 1;
				break;
			default:
				if (x < sizeof(buf) - 2) {
					buf[x++]='%';
					buf[x]=*s;
				}
			}
			break;
		default:
			buf[x]=*s;
		}
		x++;
		s++;
	}
	if (x > sizeof(buf) - 3)
		x -= 3;
	buf[x++]='&';
	return system(buf);
}