summaryrefslogtreecommitdiffstats
path: root/Bachelor/Verteilte Systeme/Praktikum2/loesung/telbuch_server.c
blob: 67109988353a07d9f14408a61fdc7c0f9124f677 (plain)
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
/*
 * This is sample code generated by rpcgen.
 * These are only templates and you can use them
 * as a guideline for developing your own functions.
 */

#include "telbuch.h"

Ergebnis *
addentry_1_svc(addStruct *argp, struct svc_req *rqstp)
{
	static Ergebnis  result;

	/* my code START */

	FILE* out;

	if ((out = fopen("telbuch", "a")) == NULL)	// Datei zum Schreiben �ffnen
	{
		strcpy(result.Eintrag,"Oeffnen der Telefonbuchdatei fehgeschlagen");
		return &result;
	}
	fseek(out,0,SEEK_END);	// Dateizeiger an Ende setzen

	// neuen Eintrag reinschreiben
	fprintf(out, "%s %s\n", argp->Name, argp->TelNr);

	fclose(out);

	strcpy(result.Eintrag,"Eintrag erfolgreich");

	/* my code END */

	return &result;
}

Ergebnis *
searchentry_1_svc(searchStruct *argp, struct svc_req *rqstp)
{
	static Ergebnis  result;

	/* my code START */
	char name[41];
	char nname[20];
	char vname[20];
	char telnr[20];

	FILE* in;

	if ((in = fopen("telbuch", "r")) == NULL)	// Datei zum Lesen �ffnen
	{
		strcpy(result.Eintrag,"Oeffnen der Telefonbuchdatei fehgeschlagen");
		return &result;
	}

	while (!feof(in))	// Nach dem Eintrag suchen
	{
		fscanf(in, "%s %s %s", nname, vname, telnr);
		strcpy(name, nname);
		strcat(name, " ");
		strcat(name, vname);
		if (strcmp(argp->Name, name) == 0)	// Eintrag gefunden
		{
			strcpy(result.Eintrag, "gefunden: ");
			strcat(result.Eintrag, name);
			strcat(result.Eintrag, " ");
			strcat(result.Eintrag, telnr);
			return &result;
		}
	}
	
	// soweit kommt die Funktion nur, wenn kein Eintrag gefunden wurde.
	strcpy(result.Eintrag, "Eintrag nicht gefunden");

	/* my code END */

	return &result;
}