File: register.c

package info (click to toggle)
garlic 1.6-3
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 4,516 kB
  • sloc: ansic: 52,465; makefile: 2,254
file content (98 lines) | stat: -rw-r--r-- 2,389 bytes parent folder | download | duplicates (5)
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
90
91
92
93
94
95
96
97
98
/* Copyright (C) 2000 Damir Zucic */

/*=============================================================================

				register.c

Purpose:
	Register the user - try to send short e-mail message to the author.

Input:
	No input.

Output:
	(1) E-mail send to the author.
	(2) Return value.

Return value:
	(1) Positive on success.
	(2) Negative on failure.

Notes:
	(1) This function tryes to send mail, but it does not try too hard.

========includes:============================================================*/

#include <stdio.h>
#include <string.h>
#include <stdlib.h>

#include "defines.h"

/*======register:============================================================*/

int Register_ (void)
{
char		outfile_nameA[SHORTSTRINGSIZE];
char		command_stringA[STRINGSIZE];
FILE		*outfileP;
int		n;

/* Open the output (message) file: */
do
	{
	/** The first attempt: **/
	strcpy (outfile_nameA, "garlic_reg.txt");
	if ((outfileP = fopen (outfile_nameA, "w")) != NULL) break;

	/** The second attempt: **/
	strcpy (outfile_nameA, "/tmp/garlic_reg.txt");
	if ((outfileP = fopen (outfile_nameA, "w")) != NULL) break;

	/** If this point is reached, both attempts failed: **/
	printf ("Unable to prepare the message file - registration failed!\n");
	return -1;
	} while (0);

/* Write the message: */
fprintf (outfileP, "Hi!\n");

/* Close the file: */
fclose (outfileP);

/* Send the message: */
do
	{
	/** The first attempt (no path): **/
	strcpy (command_stringA, "mailx zucic@garlic.mefos.hr < ");
	strcat (command_stringA, outfile_nameA);
	n = system (command_stringA);
	if (n >= 0) break;

	/** The second attempt (using Digital Unix mailx pathname): **/
	strcpy (command_stringA, "/bin/mailx zucic@garlic.mefos.hr < ");
	strcat (command_stringA, outfile_nameA);
	n = system (command_stringA);
	if (n >= 0) break;

	/** The third attempt (using SunOS mailx pathname): **/
	strcpy (command_stringA, "/usr/bin/mailx zucic@garlic.mefos.hr < ");
	strcat (command_stringA, outfile_nameA);
	n = system (command_stringA);
	if (n >= 0) break;

	/** If this point is reached, all attempts to send mail failed: **/
	remove (outfile_nameA);
	return -2;
	} while (0);

/* Remove (delete) the message file: */
remove (outfile_nameA);

/* If this point is reached, registration might be successful: */
return 1;
}

/*===========================================================================*/