/*************************************************************************** tools.c Network component (c) 2003-2004 Daniel Campos Fernández This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 1, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. ***************************************************************************/ #include "tools.h" #include "main.h" #include "gambas.h" #include #include #include #include #include #include #include #include #include #include #ifdef __CYGWIN__ #define FIONREAD TIOCINQ #endif void correct_url(char **buf,char *protocol) { char *buftmp; int len; int myloop,myloop2; int pos=-1; int myok=1; len=strlen(*buf); for (myloop=0;myloop0x39) ) { myok=0; break; } } if (!myok) pos=myloop; break; } } } } myok=0; if (pos==-1) { GB.Alloc(POINTER(&buftmp),len+1); strcpy(buftmp,*buf); GB.Free(POINTER(buf)); GB.Alloc(POINTER(buf),len+strlen(protocol)+1); strcpy(*buf,protocol); if (strlen(buftmp)>=2) { if ( buftmp[0]=='/') myok++; if ( buftmp[1]=='/') myok++; } strcat(*buf,buftmp+myok); GB.Free(POINTER(&buftmp)); } else { GB.Alloc(POINTER(&buftmp),(len-pos)+1); strcpy(buftmp,*buf+pos+1); GB.Free(POINTER(buf)); GB.Alloc(POINTER(buf),strlen(buftmp)+strlen(protocol)+1); strcpy(*buf,protocol); if (strlen(buftmp)>=2) { if ( buftmp[0]=='/') myok++; if ( buftmp[1]=='/') myok++; } strcat(*buf,buftmp+myok); GB.Free(POINTER(&buftmp)); } } void Alloc_CallBack_Pointers(long nobjs,long **objs,long **scks) { if (!nobjs) { if (*objs) { GB.Free((void**)objs); GB.Free((void**)scks); *objs=NULL; } return; } if (*objs) { GB.Realloc((void**)objs,nobjs*sizeof(long)); GB.Realloc((void**)scks,nobjs*sizeof(long)); } else { GB.Alloc((void**)objs,sizeof(long)); GB.Alloc((void**)scks,sizeof(long)); } } int CheckConnection(int Socket) { struct pollfd mypoll; int numpoll; int retval=6; mypoll.fd=Socket; mypoll.events=POLLERR; mypoll.revents=0; numpoll=poll(&mypoll,1,0); if (numpoll>=0) { if (!numpoll) { mypoll.fd=Socket; mypoll.events=POLLIN | POLLOUT; mypoll.revents=0; numpoll=poll(&mypoll,1,0); if (numpoll<0) { retval=0; } else { if (numpoll>0) retval=7; } } else { retval=0; } } else { retval=0; } return retval; } /* free "buf" after using it! */ int IsHostPath(char *sCad,char **buf,int *port) { /******************* 0 --> Error 1 --> TCP 2 -> Unix *******************/ int npos=0; int npoint=0; int myloop; int bufport=0; *port=0; *buf=NULL; if ( sCad[0] == '/' ) { return 2; } for (myloop=0;myloop'9') ) return 0; bufport*=10; bufport+= (sCad[myloop]-48); if ( (bufport) >65535) return 0; } *port=bufport; if (npos>0) { GB.Alloc((void**)buf,npos); *buf[0]=0; sCad[npos]=0; strcpy(*buf,sCad); sCad[npos]=':'; } return 1; } /******************************************************** Watching stuff ********************************************************/ int search_by_integer(long *objlist,long nobj,long iData) { int myloop; int position=0; for (myloop=0;myloop