ze-filter  (ze-filter-0.8.0-develop-180218)
ze-rcpt-list.c
Go to the documentation of this file.
1 
2 /*
3  *
4  * ze-filter - Mail Server Filter for sendmail
5  *
6  * Copyright (c) 2001-2018 - Jose-Marcio Martins da Cruz
7  *
8  * Auteur : Jose Marcio Martins da Cruz
9  * jose.marcio.mc@gmail.org
10  *
11  * Historique :
12  * Creation : Tue Feb 21 22:09:21 CET 2006
13  *
14  * This program is free software, but with restricted license :
15  *
16  *
17  * This program is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
20  *
21  * More details about ze-filter license can be found at ze-filter
22  * web site : http://foss.jose-marcio.org
23  */
24 
25 
26 #include <ze-sys.h>
27 #include <ze-filter.h>
28 #include <ze-rcpt-list.h>
29 
30 
31 /* ****************************************************************************
32  * *
33  * *
34  **************************************************************************** */
37  rcpt_addr_T *head;
38 {
39  rcpt_addr_T *p;
40 
41  if (head == NULL)
42  return NULL;
43 
44  while (head != NULL) {
45  p = head->next;
46  FREE(head->rcpt);
47  FREE(head->email);
48  FREE(head->host);
49  FREE(head->user);
50 
51  FREE(head);
52  head = p;
53  }
54  return head;
55 }
56 
57 /* ****************************************************************************
58  * *
59  * *
60  **************************************************************************** */
62 rcpt_list_add(head, rcpt, access)
63  rcpt_addr_T **head;
64  char *rcpt;
65  int access;
66 {
67  rcpt_addr_T *p, *q;
68  bool res = TRUE;
69  rcpt_addr_T *new = NULL;
70 
71  char *s;
72 
73  p = q = new = NULL;
74 
75  if (rcpt == NULL || strlen(rcpt) == 0)
76  return FALSE;
77 
78  if ((p = malloc(sizeof (rcpt_addr_T))) == NULL) {
79  ZE_LogSysError("malloc(rcpt_addr_T)");
80  res = FALSE;
81  goto fin;
82  }
83 
84  memset(p, 0, sizeof (*p));
85 
86  if ((p->rcpt = strdup(rcpt)) == NULL) {
87  ZE_LogSysError("strdup(rcpt)");
88  res = FALSE;
89  goto fin;
90  }
91 
92  if ((p->email = strdup(rcpt)) == NULL) {
93  ZE_LogSysError("strdup(rcpt)");
94  res = FALSE;
95  goto fin;
96  }
97  extract_email_address(p->email, rcpt, strlen(p->email) + 1);
98 
99  if ((p->user = strdup(p->email)) == NULL) {
100  ZE_LogSysError("strdup(p->email)");
101  res = FALSE;
102  goto fin;
103  }
104  if ((s = strrchr(p->user, '@')) != NULL)
105  *s = '\0';
106 
107  if ((p->host = strdup(p->email)) == NULL) {
108  ZE_LogSysError("strdup(p->email)");
109  res = FALSE;
110  goto fin;
111  }
112  if ((s = strrchr(p->email, '@')) != NULL)
113  strlcpy(p->host, ++s, strlen(p->host) + 1);
114  else
115  strlcpy(p->host, "", strlen(p->host) + 1);
116 
117  if (*head == NULL) {
118  *head = p;
119  } else {
120  q = *head;
121  while (q->next != NULL)
122  q = q->next;
123  q->next = p;
124  }
125 
126 fin:
127  if (!res) {
128  if (p != NULL) {
129  FREE(p->rcpt);
130  FREE(p->email);
131  FREE(p->user);
132  FREE(p->host);
133  }
134  FREE(p);
135  }
136 
137  new = p;
138  return new;
139 }
140 
141 /* ****************************************************************************
142  * *
143  * *
144  **************************************************************************** */
145 #if 0
146 int
147 rcpt_list_del(head, rcpt)
148  rcpt_addr_T **head;
149  char *rcpt;
150 {
151  rcpt_addr_T *p, *q;
152 
153  if (rcpt == NULL || strlen(rcpt) == 0)
154  return 0;
155  if (*head == NULL)
156  return 0;
157 
158  return 0;
159 }
160 #endif
char * host
Definition: ze-rcpt-list.h:33
char * rcpt
Definition: ze-rcpt-list.h:31
rcpt_addr_T * rcpt_list_free(rcpt_addr_T *head)
Definition: ze-rcpt-list.c:36
#define strrchr
Definition: ze-sys.h:219
#define FREE(x)
Definition: macros.h:37
#define FALSE
Definition: macros.h:160
#define strlcpy
Definition: zeString.h:32
char * extract_email_address(char *, char *, size_t)
char * user
Definition: ze-rcpt-list.h:34
char * email
Definition: ze-rcpt-list.h:32
rcpt_addr_T * next
Definition: ze-rcpt-list.h:39
rcpt_addr_T * rcpt_list_add(rcpt_addr_T **head, char *rcpt, int access)
Definition: ze-rcpt-list.c:62
#define TRUE
Definition: macros.h:157
#define ZE_LogSysError(...)
Definition: zeSyslog.h:129
int rcpt_list_del(rcpt_addr_T **, char *rcpt)