Commit c754bb7e c754bb7ef1c0a668f8c672aaae9a5de16e68a355 by Sam Roberts

tcp_stream_create now has more informative errors for no host or port

1 parent 108f892c
...@@ -60,6 +60,9 @@ extern "C" { ...@@ -60,6 +60,9 @@ extern "C" {
60 #define MU_ERR_MAILER_NO_RCPT_TO (MU_ERR_BASE | 0x015) 60 #define MU_ERR_MAILER_NO_RCPT_TO (MU_ERR_BASE | 0x015)
61 #define MU_ERR_SMTP_RCPT_FAILED (MU_ERR_BASE | 0x016) 61 #define MU_ERR_SMTP_RCPT_FAILED (MU_ERR_BASE | 0x016)
62 62
63 #define MU_ERR_TCP_NO_HOST (MU_ERR_BASE | 0x017)
64 #define MU_ERR_TCP_NO_PORT (MU_ERR_BASE | 0x018)
65
63 const char* mu_errname __P((int e)); 66 const char* mu_errname __P((int e));
64 const char* mu_errstring __P((int e)); 67 const char* mu_errstring __P((int e));
65 68
......
...@@ -64,13 +64,16 @@ mu_errname (int e) ...@@ -64,13 +64,16 @@ mu_errname (int e)
64 EN(MU_ERR_LOCK_EXT_FAIL) 64 EN(MU_ERR_LOCK_EXT_FAIL)
65 EN(MU_ERR_LOCK_EXT_ERR) 65 EN(MU_ERR_LOCK_EXT_ERR)
66 EN(MU_ERR_LOCK_EXT_KILLED) 66 EN(MU_ERR_LOCK_EXT_KILLED)
67 EN(MU_ERR_NO_SUCH_USER) 67
68 EN(MU_ERR_GETHOSTBYNAME) 68 EN(MU_ERR_NO_SUCH_USER)
69 EN(MU_ERR_BAD_RESUMPTION) 69 EN(MU_ERR_GETHOSTBYNAME)
70 EN(MU_ERR_MAILER_BAD_FROM) 70 EN(MU_ERR_BAD_RESUMPTION)
71 EN(MU_ERR_MAILER_BAD_TO) 71 EN(MU_ERR_MAILER_BAD_FROM)
72 EN(MU_ERR_MAILER_NO_RCPT_TO) 72 EN(MU_ERR_MAILER_BAD_TO)
73 EN(MU_ERR_SMTP_RCPT_FAILED) 73 EN(MU_ERR_MAILER_NO_RCPT_TO)
74 EN(MU_ERR_SMTP_RCPT_FAILED)
75 EN(MU_ERR_TCP_NO_HOST)
76 EN(MU_ERR_TCP_NO_PORT)
74 } 77 }
75 78
76 return "SYSTEM ERROR"; 79 return "SYSTEM ERROR";
...@@ -105,12 +108,14 @@ const char* mu_errstring (int e) ...@@ -105,12 +108,14 @@ const char* mu_errstring (int e)
105 108
106 ES(MU_ERR_NO_SUCH_USER, "No such user name") 109 ES(MU_ERR_NO_SUCH_USER, "No such user name")
107 110
108 ES(MU_ERR_GETHOSTBYNAME, "gethostbyname() failed, check h_errno") 111 ES(MU_ERR_GETHOSTBYNAME, "DNS name resolution failed")
109 ES(MU_ERR_BAD_RESUMPTION, "State busy, must resume operation") 112 ES(MU_ERR_BAD_RESUMPTION, "State busy, must resume operation")
110 ES(MU_ERR_MAILER_BAD_FROM, "Not a valid mailer from address") 113 ES(MU_ERR_MAILER_BAD_FROM, "Not a valid mailer from address")
111 ES(MU_ERR_MAILER_BAD_TO, "Not a valid mailer to address") 114 ES(MU_ERR_MAILER_BAD_TO, "Not a valid mailer to address")
112 ES(MU_ERR_MAILER_NO_RCPT_TO,"No receipt addresses found") 115 ES(MU_ERR_MAILER_NO_RCPT_TO,"No receipt addresses found")
113 ES(MU_ERR_SMTP_RCPT_FAILED, "SMTP rcpt to command failed") 116 ES(MU_ERR_SMTP_RCPT_FAILED, "SMTP rcpt to command failed")
117 ES(MU_ERR_TCP_NO_HOST, "Tcp connections need a host")
118 ES(MU_ERR_TCP_NO_PORT, "Tcp connections need a postive port")
114 } 119 }
115 120
116 return strerror(e); 121 return strerror(e);
......
...@@ -232,8 +232,11 @@ tcp_stream_create (stream_t * stream, const char* host, int port, int flags) ...@@ -232,8 +232,11 @@ tcp_stream_create (stream_t * stream, const char* host, int port, int flags)
232 struct _tcp_instance *tcp; 232 struct _tcp_instance *tcp;
233 int ret; 233 int ret;
234 234
235 if (host == NULL || port < 1) 235 if (host == NULL)
236 return EINVAL; 236 return MU_ERR_TCP_NO_HOST
237
238 if (port < 1)
239 return MU_ERR_TCP_NO_PORT;
237 240
238 if ((tcp = malloc (sizeof (*tcp))) == NULL) 241 if ((tcp = malloc (sizeof (*tcp))) == NULL)
239 return ENOMEM; 242 return ENOMEM;
......