*/
/********************************************************/
/* */
-/* Procedure to prepare plain incoming channel */
+/* Procedure to open plain incoming channel */
/* */
/********************************************************/
-static _Bool plainsoc(SOCTYP *soc)
+static _Bool openplain(SOCTYP *soc)
{
#define OPEP "devsoc:plainsoc"
while (proceed==true) {
switch (phase) {
case 0 : //First prepare a new socket
- if ((newhandle=getnewhandle(soc))<0) {
+ if ((newhandle=getnewhandle(soc))<0)
phase=999; //no newhandle troub trouble
- }
break;
case 1 : //getting newhandle flag
if ((flags=fcntl(newhandle,F_GETFL,0))<0) {
*/
/********************************************************/
/* */
+/* Procedure to close plain incoming channel */
+/* */
+/********************************************************/
+static void closeplain(SOCTYP *soc)
+
+{
+#define OPEP "devsoc.c:closeplain"
+
+int phase;
+_Bool proceed;
+
+phase=0;
+proceed=true;
+while (proceed==true) {
+ switch (phase) {
+ case 0 : //shutting down the link
+ if (shutdown(soc->handle,SHUT_RDWR)<0) {
+ switch (errno) {
+ case ENOTCONN : //already disconnect by other side!
+ (void) rou_alert(0,"%s [%s:%s] Already disconnected (errno=<%s>)",
+ OPEP,soc->ip,soc->port,strerror(errno));
+ break;
+ default :
+ (void) rou_alert(0,"%s unable to shutdown [%s:%s] (errno=<%s>)",
+ OPEP,soc->ip,soc->port,strerror(errno));
+ break;
+ }
+ }
+ break;
+ case 1 : //closing connexion
+ if (close(soc->handle)<0) {
+ (void) rou_alert(0,"%s unable to close channel [%s:%s] properly "
+ "(errno=<%s>)",
+ OPEP,soc->ip,soc->port,strerror(errno));
+ }
+ break;
+ default : //SAFE Guard
+ proceed=false;
+ break;
+ }
+ phase++;
+ }
+#undef OPEP
+}
+/*
+\f
+*/
+/********************************************************/
+/* */
/* Procedure to wait and get a new handle */
/* */
/********************************************************/
switch (phase) {
case 0 : //First prepare a new socket
newsoc=dupsocket(soc);
- if (plainsoc(newsoc)==false) {
- phase=999; //trouble trouble
- }
+ if (openplain(newsoc)==false)
+ proceed=false; //received a termination signal
break;
case 1 : //wait for incoming connexion
switch (newsoc->proto) {
phase=999; //No End Of Line yet
break;
case 3 : //duplicating carpile
- (void) printf("JMPDBG carpil=<%s>\n",soc->carpile);
*lineptr=calloc(soc->carin+1,sizeof(char));
*eol='\000';
(void) strcpy(*lineptr,soc->carpile);
(void) strcat(*lineptr,soc->EOL);
- (void) printf("JMPDBG *lineptr=<%s>\n",*lineptr);
got=strlen(*lineptr);
break;
case 4 : //managing carpile
/* socket. */
/* */
/********************************************************/
-PUBLIC void soc_receive(SOCPTR *socptr)
+PUBLIC int soc_receive(SOCPTR *socptr)
{
#define OPEP "devsoc.c:soc_receive"
+int got;
SOCTYP *soc;
+got=0;
soc=(SOCTYP *)socptr;
if (soc!=(SOCTYP *)0) {
- int got;
int limit;
char *buffer;
switch (soc->modtls) {
case true :
got=tls_read(soc->tls,buffer,limit);
- (void) printf("JMPDBG tls_read got='%d'\n",got);
break;
case false :
got=recv(soc->handle,buffer,limit,MSG_DONTWAIT);
break;
}
break;
- case 0 : //EOL?
+ case 0 : //Premature EOF?
break;
default : //we got some char from remote
break;
if (got>0) { //we have recived some character
soc->carin+=got; //managing carpile
soc->carpile[soc->carin]='\000';
- (void) printf("JMPDBG soc_receive carpile=<%s>\n",soc->carpile);
}
}
+return got;
#undef OPEP
}
/*
}
break;
case 1 : //shuting dow the TCP link
- if (shutdown(soc->handle,SHUT_RDWR)<0) {
- switch (errno) {
- case ENOTCONN : //already disconnect by other side!
- (void) rou_alert(0,"%s [%s:%s] Already disconnected (errno=<%s>)",
- OPEP,soc->ip,soc->port,strerror(errno));
- break;
- default :
- (void) rou_alert(0,"%s unable to shutdown [%s:%s] (errno=<%s>)",
- OPEP,soc->ip,soc->port,strerror(errno));
- break;
- }
+ switch (soc->proto) {
+ case pro_smtp : //plain socket
+ case pro_starttls : //plain socket + STARTTLS
+ //nothing to do
+ break;
+ case pro_smtps : //set secure socket
+ soc->tls=tls_closetls(soc->tls);
+ break;
+ default :
+ (void) rou_alert(0,"%s Protocol '%d' unset (Bug?)",
+ OPEP,(int)(soc->proto));
+ break;
}
break;
case 2 : //closing connexion
- if (close(soc->handle)<0) {
- (void) rou_alert(0,"%s unable to close channel [%s:%s] properly "
- "(errno=<%s>)",
- OPEP,soc->ip,soc->port,strerror(errno));
- }
- break;
- case 3 : //freeing the SSL contaxt
- soc->tls=tls_closetls(soc->tls);
+ (void) closeplain(soc);
break;
case 4 : //fee memory used by socket
soc=freesocket(soc);