/*----------------------------------------------------------------------* rtp_net_setreuseaddr *----------------------------------------------------------------------*/ int rtp_net_setreuseaddr (RTP_HANDLE sockHandle, unsigned int onBool) { #ifdef LINUXTOBEIMPLEMENTED #ifdef RTP_DEBUG int result; /* ----------------------------------- */ /* Clear the error state by setting */ /* to 0. */ /* ----------------------------------- */ WSASetLastError (0); #endif if ( setsockopt((SOCKET) sockHandle, SOL_SOCKET, SO_REUSEADDR, (char *) &onBool, sizeof (int)) == SOCKET_ERROR ) { #ifdef RTP_DEBUG result = WSAGetLastError(); RTP_DEBUG_OUTPUT_STR("rtp_net_setreuseaddr: error returned "); RTP_DEBUG_OUTPUT_INT(result); RTP_DEBUG_OUTPUT_STR(".\n"); #endif return (-1); } return (0); #else return (0); #endif }
/*----------------------------------------------------------------------* rtp_net_setnagle *----------------------------------------------------------------------*/ int rtp_net_setnagle (RTP_HANDLE sockHandle, unsigned int onBool) { #ifdef LINUXTOBEIMPLEMENTED int option; #ifdef RTP_DEBUG int result; /* ----------------------------------- */ /* Clear the error state by setting */ /* to 0. */ /* ----------------------------------- */ WSASetLastError (0); #endif option = (int)(!onBool); if ( setsockopt((SOCKET) sockHandle, IPPROTO_TCP, TCP_NODELAY, (char *) &option, sizeof (int)) == SOCKET_ERROR ) { #ifdef RTP_DEBUG result = WSAGetLastError(); RTP_DEBUG_OUTPUT_STR("rtp_net_setnagle: error returned "); RTP_DEBUG_OUTPUT_INT(result); RTP_DEBUG_OUTPUT_STR(".\n"); #endif return (-1); } return (0); #else return (0); #endif }
/*----------------------------------------------------------------------* rtp_file_get_free *----------------------------------------------------------------------*/ int rtp_file_get_free (const char * name, unsigned long *total, unsigned long *free, unsigned long *sectors_per_unit, unsigned short *bytes_per_sector) { struct statfs stats; #ifdef RTP_DEBUG /* ----------------------------------- */ /* Clear the error state by setting */ /* to 0. */ /* ----------------------------------- */ errno = 0; #endif if (statfs ((const char *) name, &stats) != 0) { #ifdef RTP_DEBUG RTP_DEBUG_OUTPUT_STR("rtp_file_get_free: error returned "); RTP_DEBUG_OUTPUT_INT(errno); RTP_DEBUG_OUTPUT_STR(".\n"); #endif return (-1); } *total = (unsigned long) stats.f_blocks; *free = (unsigned long) stats.f_bavail; *sectors_per_unit = (unsigned long) 1; *bytes_per_sector = (unsigned short) stats.f_bsize; return (0); }
/*----------------------------------------------------------------------* rtp_net_setblocking *----------------------------------------------------------------------*/ int rtp_net_setblocking (RTP_HANDLE sockHandle, unsigned int onBool) { #ifdef LINUXTOBEIMPLEMENTED u_long arg; #ifdef RTP_DEBUG int result; /* ----------------------------------- */ /* Clear the error state by setting */ /* to 0. */ /* ----------------------------------- */ WSASetLastError (0); #endif arg = (u_long)(!onBool); if (ioctlsocket((SOCKET) sockHandle, FIONBIO, (u_long *) &arg) == SOCKET_ERROR) { #ifdef RTP_DEBUG result = WSAGetLastError(); RTP_DEBUG_OUTPUT_STR("rtp_net_setblocking: error returned "); RTP_DEBUG_OUTPUT_INT(result); RTP_DEBUG_OUTPUT_STR(".\n"); #endif return (-1); } return (0); #else return (0); #endif }
/*----------------------------------------------------------------------* rtp_file_delete *----------------------------------------------------------------------*/ int rtp_file_delete (const char * name) { #ifdef RTP_DEBUG /* ----------------------------------- */ /* Clear the error state by setting */ /* to 0. */ /* ----------------------------------- */ errno = 0; #endif if (unlink ((const char *)name) != 0) { #ifdef RTP_DEBUG RTP_DEBUG_OUTPUT_STR("rtp_file_delete: error returned "); RTP_DEBUG_OUTPUT_INT(errno); RTP_DEBUG_OUTPUT_STR(".\n"); #endif return (-1); } #ifdef RTP_DEBUG RTP_DEBUG_OUTPUT_STR("rtp_file_delete: "); RTP_DEBUG_OUTPUT_STR("...success"); RTP_DEBUG_OUTPUT_STR(".\n"); #endif return (0); }
/** @memo Wait for a semaphore to be signaled. @doc Wait for a semaphore to be signaled. If the semaphore has already been signaled this function returns immediatley, otherwise it should block until the semaphore is signaled or the millisecond time value has expired. Use 0 to poll the signal and return with its state immediately. Use -1 to indicate that an infinite timeout value should be used, blocking indefinitely for the signal. @precondition Must not call directly. Use the <b>rtp_sig_semaphore_wait_timed</b> macro in rtpsignl.h. @return 0 if successful, -1 on error, and 1 if the call timed out. For debugging purposes; if the cause of the error is obtainable at the native Kernel layer, turn on RTP_DEBUG in rtpdebug.h to display the native error value. */ int _rtp_sig_semaphore_wait_timed ( RTP_HANDLE semHandle, /** Handle to the semaphore to be checked. */ long msecs /** Timeout value in milliseconds:<br> <pre> | 0 To poll. | -1 To indicate use of infinite. </pre> */ ) { INT16U timeout; INT8U err; INT16U currentCount; if (msecs == 0) { currentCount = ((OS_EVENT*)semHandle)->OSEventCnt; if (!currentCount) { return(-1); } } if (msecs == -1) { timeout = 0; } else { timeout = msecs * OS_TICKS_PER_SEC / 1000; } OSSemPend ((OS_EVENT *) semHandle, timeout, &err); if (err == OS_NO_ERR) { /* success, return */ return (0); } #if (RTP_DEBUG_SIGNAL) if (err == OS_TIMEOUT) { RTP_DEBUG_OUTPUT_STR("The semaphore was not received within the specified timeout."); } if (err == OS_ERR_EVENT_TYPE) { RTP_DEBUG_OUTPUT_STR("If you didnt pass a pointer to a semaphore."); } if (err == OS_ERR_PEND_ISR) { RTP_DEBUG_OUTPUT_STR("If you called this function from an ISR and the result would lead to a suspension."); } if (err == OS_ERR_PEVENT_NULL) { RTP_DEBUG_OUTPUT_STR("If pevent is a NULL pointer."); } #endif return (-1); }
/*----------------------------------------------------------------------* rtp_net_bind *----------------------------------------------------------------------*/ int rtp_net_bind (RTP_HANDLE sockHandle, unsigned char *ipAddr, int port, int type) { struct sockaddr_in sin; unsigned long in_addr = 0; memset(&sin, 0, sizeof (sin)); if (ipAddr) { unsigned char *ptr = (unsigned char *) &in_addr; ptr[0] = ipAddr[0]; ptr[1] = ipAddr[1]; ptr[2] = ipAddr[2]; ptr[3] = ipAddr[3]; /* ----------------------------------- */ /* RTP_NET_TYPE_IPV6 not yet supported */ /* ----------------------------------- */ } else { in_addr = INADDR_ANY; } sin.sin_family = AF_INET; sin.sin_addr.s_addr = in_addr; sin.sin_port = htons((unsigned short)port); if (bind ((int) sockHandle, (struct sockaddr *) &sin, sizeof (sin)) != 0) { int errVal = _rtp_get_last_socket_error(sockHandle); if (errVal == EINVAL) { #ifdef RTP_DEBUG RTP_DEBUG_OUTPUT_STR("rtp_net_bind: non-fatal error returned "); RTP_DEBUG_OUTPUT_INT(errVal); RTP_DEBUG_OUTPUT_STR(".\n"); #endif return (-2); } else { #ifdef RTP_DEBUG RTP_DEBUG_OUTPUT_STR("rtp_net_bind: error returned "); RTP_DEBUG_OUTPUT_INT(errVal); RTP_DEBUG_OUTPUT_STR(".\n"); #endif return (-1); } } return (0); }
/*----------------------------------------------------------------------* rtp_net_recvfrom *----------------------------------------------------------------------*/ long rtp_net_recvfrom (RTP_HANDLE sockHandle, unsigned char *buffer, long size, unsigned char *ipAddr, int *port, int *type) { ssize_t result; int remoteLen; struct sockaddr_in remote; remoteLen = sizeof(remote); memset(&remote, 0, remoteLen); /* ----------------------------------- */ /* Clear the error state by setting */ /* to 0. */ /* ----------------------------------- */ errno = 0; result = recvfrom((int) sockHandle, (char *) buffer, (int) size, 0, (struct sockaddr *) &remote, (int *) &remoteLen); if (result == -1) { if ((errno == EINTR) || (errno == EAGAIN)) { #ifdef RTP_DEBUG RTP_DEBUG_OUTPUT_STR("rtp_net_recvfrom: non-fatal error returned "); RTP_DEBUG_OUTPUT_INT(errno); RTP_DEBUG_OUTPUT_STR(".\n"); #endif return (-2); } #ifdef RTP_DEBUG RTP_DEBUG_OUTPUT_STR("rtp_net_recvfrom: error returned "); RTP_DEBUG_OUTPUT_INT(errno); RTP_DEBUG_OUTPUT_STR(".\n"); #endif return (-1); } if (ipAddr) { unsigned long d = remote.sin_addr.s_addr; unsigned char *ptr = (unsigned char *) &d; ipAddr[0] = ptr[0]; ipAddr[1] = ptr[1]; ipAddr[2] = ptr[2]; ipAddr[3] = ptr[3]; *type = RTP_NET_TYPE_IPV4; *port = ntohs(remote.sin_port); } return ((long) result); }
/*----------------------------------------------------------------------* rtp_net_gethostbyname *----------------------------------------------------------------------*/ int rtp_net_gethostbyname (unsigned char *ipAddr, int *type, char *name) { #if (INCLUDE_DNS) #ifdef RTP_DEBUG int result; #endif PFHOSTENT hp = NULL; #ifdef RTP_DEBUG /* ----------------------------------- */ /* Clear the error state by setting */ /* to 0. */ /* ----------------------------------- */ set_errno (0); #endif if (!(hp = gethostbyname(name))) { #ifdef RTP_DEBUG result = xn_getlasterror(); RTP_DEBUG_OUTPUT_STR("rtp_net_gethostbyname: error returned "); RTP_DEBUG_OUTPUT_INT(result); RTP_DEBUG_OUTPUT_STR(".\n"); #endif return (-1); } if (hp->h_addrtype != AF_INET) { #ifdef RTP_DEBUG set_errno (EAFNOSUPPORT); result = xn_getlasterror(); RTP_DEBUG_OUTPUT_STR("rtp_net_gethostbyname: error returned "); RTP_DEBUG_OUTPUT_INT(result); RTP_DEBUG_OUTPUT_STR(".\n"); #endif return (-1); } *type = RTP_NET_TYPE_IPV4; ipAddr[0] = (unsigned char) hp->h_addr_list[0][0]; ipAddr[1] = (unsigned char) hp->h_addr_list[0][1]; ipAddr[2] = (unsigned char) hp->h_addr_list[0][2]; ipAddr[3] = (unsigned char) hp->h_addr_list[0][3]; return (0); #else rtp_not_yet_implemented(); return (-1); #endif /* INCLUDE_DNS */ }
/*----------------------------------------------------------------------* rtp_net_read_select *----------------------------------------------------------------------*/ int rtp_net_read_select (RTP_HANDLE sockHandle, long msecTimeout) { struct timeval selectTime; fd_set read_set; int result; /* ----------------------------------- */ /* read list */ /* ----------------------------------- */ FD_ZERO(&read_set); FD_SET(sockHandle, &read_set); #ifdef RTP_DEBUG /* ----------------------------------- */ /* Clear the error state by setting */ /* to 0. */ /* ----------------------------------- */ set_errno (0); #endif if (msecTimeout >= 0) { selectTime.tv_sec = msecTimeout / 1000; selectTime.tv_usec = (msecTimeout % 1000) * 1000; result = select(1, (PFDSET) &read_set, (PFDSET) 0, (PFDSET) 0, (PCTIMEVAL) &selectTime); } else { result = select(1, (PFDSET) &read_set, (PFDSET) 0, (PFDSET) 0, (PCTIMEVAL) NULL); } /* if (result == 1) | { | if (!xn_tcp_is_read(sockHandle)) | { | result = (-1); | } | } */ /* if an error or if it timed out */ if (result <= 0) { #ifdef RTP_DEBUG result = xn_getlasterror(); RTP_DEBUG_OUTPUT_STR("rtp_net_read_select: error returned "); RTP_DEBUG_OUTPUT_INT(result); RTP_DEBUG_OUTPUT_STR(".\n"); #endif return (-1); } return (0); }
/*----------------------------------------------------------------------* rtp_wfile_open *----------------------------------------------------------------------*/ int rtp_wfile_open (RTP_HANDLE * fdPtr, const unsigned short * name, unsigned short flag, unsigned short mode) { #if (_WIN32_WINNT) >= 0x0400 long fileHandle; int result; #ifdef RTP_DEBUG /* ----------------------------------- */ /* Clear the error state by setting */ /* to 0. */ /* ----------------------------------- */ SetLastError(0); #endif name = (unsigned short *)_rtp_unicode_name_to_winname ((unsigned short *) name); fileHandle = (long) _wopen (name, _rtp_flag_to_operation(flag), _rtp_mode_to_permission(mode)); if (fileHandle == (-1)) { result = GetLastError(); /* ----------------------------------- */ /* If trying to open a directory or */ /* opening a read only file with */ /* write privilages. This can be */ /* non-fatal if doing an open to */ /* determine the existance of a */ /* directory. */ /* ----------------------------------- */ if (result == ERROR_ACCESS_DENIED) { #ifdef RTP_DEBUG RTP_DEBUG_OUTPUT_STR("rtp_wfile_open: non-fatal error returned "); RTP_DEBUG_OUTPUT_INT(result); RTP_DEBUG_OUTPUT_STR(".\n"); #endif return (-2); } #ifdef RTP_DEBUG RTP_DEBUG_OUTPUT_STR("rtp_wfile_open: error returned "); RTP_DEBUG_OUTPUT_INT(result); RTP_DEBUG_OUTPUT_STR(".\n"); #endif return (-1); } *fdPtr = (RTP_HANDLE) fileHandle; return (0); #endif return (-1); }
/*----------------------------------------------------------------------* rtp_net_recvfrom *----------------------------------------------------------------------*/ long rtp_net_recvfrom (RTP_HANDLE sockHandle, unsigned char *buffer, long size, unsigned char *ipAddr, int *port, int *type) { long result; int remoteLen; struct sockaddr_in remote; remoteLen = sizeof (remote); memset (&remote, 0, remoteLen); /* ----------------------------------- */ /* Clear the error state by setting */ /* to 0. */ /* ----------------------------------- */ set_errno (0); result = (long) recvfrom ((int) sockHandle, (PFCHAR) buffer, (int) size, 0, (PSOCKADDR) &remote, (PFINT) &remoteLen); if (result < 0) { result = (long) xn_getlasterror(); if ((result == EINPROGRESS) || (result == EWOULDBLOCK)) { RTP_DEBUG_OUTPUT_STR("rtp_net_recvfrom: non-fatal error returned "); RTP_DEBUG_OUTPUT_INT(result); RTP_DEBUG_OUTPUT_STR(".\n"); return (-2); } RTP_DEBUG_OUTPUT_STR("rtp_net_recvfrom: error returned "); RTP_DEBUG_OUTPUT_INT(result); RTP_DEBUG_OUTPUT_STR(".\n"); return (-1); } if (ipAddr) { unsigned long d = remote.sin_addr.s_addr; unsigned char *ptr = (unsigned char *) &d; ipAddr[0] = ptr[0]; ipAddr[1] = ptr[1]; ipAddr[2] = ptr[2]; ipAddr[3] = ptr[3]; *type = RTP_NET_TYPE_IPV4; *port = ntohs (remote.sin_port); } return (result); }
/*----------------------------------------------------------------------* rtp_net_getsockname *----------------------------------------------------------------------*/ int rtp_net_getsockname (RTP_HANDLE sockHandle, unsigned char *ipAddr, int *port, int *type) { struct sockaddr_in localAddr; int localLen; #ifdef RTP_DEBUG int result; #endif localLen = sizeof (localAddr); memset(&localAddr, 0, localLen); #ifdef RTP_DEBUG /* ----------------------------------- */ /* Clear the error state by setting */ /* to 0. */ /* ----------------------------------- */ set_errno (0); #endif if (getsockname ((int) sockHandle, (PSOCKADDR) &localAddr, (PFINT) &localLen) != 0) { #ifdef RTP_DEBUG result = xn_getlasterror(); RTP_DEBUG_OUTPUT_STR("rtp_net_getsockname: error returned "); RTP_DEBUG_OUTPUT_INT(result); RTP_DEBUG_OUTPUT_STR(".\n"); #endif return (-1); } if (ipAddr) { unsigned long d = localAddr.sin_addr.s_addr; unsigned char *ptr = (unsigned char *) &d; *type = RTP_NET_TYPE_IPV4; ipAddr[0] = ptr[0]; ipAddr[1] = ptr[1]; ipAddr[2] = ptr[2]; ipAddr[3] = ptr[3]; } if (port) { *port = ntohs (localAddr.sin_port); } return (0); }
/*----------------------------------------------------------------------* _rtp_sig_semaphore_wait_timed *----------------------------------------------------------------------*/ int _rtp_sig_semaphore_wait_timed (RTP_HANDLE semHandle, long msecs) { #ifdef LINUXTOBEIMPLEMENTED DWORD result; #ifdef RTP_DEBUG int err; /* ----------------------------------- */ /* Clear the error state by setting */ /* to 0. */ /* ----------------------------------- */ SetLastError (0); #endif if (msecs == (-1)) { result = WaitForSingleObject((HANDLE)semHandle, INFINITE); } else { result = WaitForSingleObject((HANDLE)semHandle, msecs); } if (result == WAIT_FAILED) { #ifdef RTP_DEBUG err = GetLastError(); RTP_DEBUG_OUTPUT_STR("rtp_sig_semaphore_wait_timed: error returned "); RTP_DEBUG_OUTPUT_INT(err); RTP_DEBUG_OUTPUT_STR(".\n"); #endif return (-1); } else if (result == WAIT_ABANDONED) { #ifdef RTP_DEBUG RTP_DEBUG_OUTPUT_STR("rtp_sig_semaphore_wait_timed: wait abandoned.\n"); #endif return (-1); } else if (result == WAIT_TIMEOUT) { return (-1); } return (0); #else return (0); #endif }
/*----------------------------------------------------------------------* rtp_net_read_select *----------------------------------------------------------------------*/ int rtp_net_read_select (RTP_HANDLE sockHandle, long msecTimeout) { #ifdef LINUXTOBEIMPLEMENTED struct timeval selectTime; fd_set read_set; int result; /* ----------------------------------- */ /* write list */ /* ----------------------------------- */ FD_ZERO(&read_set); FD_SET((SOCKET) sockHandle, &read_set); #ifdef RTP_DEBUG /* ----------------------------------- */ /* Clear the error state by setting */ /* to 0. */ /* ----------------------------------- */ WSASetLastError(0); #endif if (msecTimeout >= 0) { selectTime.tv_sec = msecTimeout / 1000; selectTime.tv_usec = (msecTimeout % 1000) * 1000; result = select(1, (fd_set *) &read_set, (fd_set *) 0, (fd_set *) 0, (const struct timeval *) &selectTime); } else { result = select(1, (fd_set *) &read_set, (fd_set *) 0, (fd_set *) 0, (const struct timeval *) NULL); } /* if an error or if it timed out */ if ((result == SOCKET_ERROR) || (result == 0)) { #ifdef RTP_DEBUG result = WSAGetLastError(); RTP_DEBUG_OUTPUT_STR("rtp_net_read_select: error returned "); RTP_DEBUG_OUTPUT_INT(result); RTP_DEBUG_OUTPUT_STR(".\n"); #endif return (-1); } return (0); #else return (0); #endif }
/*----------------------------------------------------------------------* rtp_net_write_select *----------------------------------------------------------------------*/ int rtp_net_write_select (RTP_HANDLE sockHandle, long msecTimeout) { #ifdef LINUXTOBEIMPLEMENTED long selectTime; fd_set write_set; int result; /* ----------------------------------- */ /* write list */ /* ----------------------------------- */ IP_FD_ZERO(&write_set); IP_FD_SET((SOCKET) sockHandle, &write_set); #ifdef RTP_DEBUG /* ----------------------------------- */ /* Clear the error state by setting */ /* to 0. */ /* ----------------------------------- */ WSASetLastError(0); #endif if (msecTimeout >= 0) { selectTime = msecTimeout / 1000; result = select(1, (fd_set *) 0, (fd_set *) &write_set, (fd_set *) 0, selectTime); } else { result = select(1, (fd_set *) 0, (fd_set *) &write_set, (fd_set *) 0, 0); } /* if an error or if it timed out */ if ((result == SOCKET_ERROR) || (result == 0)) { #ifdef RTP_DEBUG result = WSAGetLastError(); RTP_DEBUG_OUTPUT_STR("rtp_net_write_select: error returned "); RTP_DEBUG_OUTPUT_INT(result); RTP_DEBUG_OUTPUT_STR(".\n"); #endif return (-1); } return (0); #else return (0); #endif }
/*----------------------------------------------------------------------* rtp_file_get_attrib *----------------------------------------------------------------------*/ int rtp_file_get_attrib (void * dirobj, unsigned char * attributes) { int readable, writable; if (!dirobj || ((FSOBJ *)dirobj)->currentPath >= ((FSOBJ *)dirobj)->globdata.gl_pathc) { #ifdef RTP_DEBUG RTP_DEBUG_OUTPUT_STR("rtp_file_get_size: error invalid dirobj.\n"); #endif return (-1); } *attributes = S_ISDIR (((FSOBJ *)dirobj)->statdata.st_mode) ? RTP_FILE_ATTRIB_ISDIR : 0; *attributes |= S_ISBLK (((FSOBJ *)dirobj)->statdata.st_mode) ? RTP_FILE_ATTRIB_ISVOL : 0; readable = ((FSOBJ *)dirobj)->statdata.st_mode & S_IRUSR; writable = ((FSOBJ *)dirobj)->statdata.st_mode & S_IWUSR; if (readable && writable) *attributes |= RTP_FILE_ATTRIB_RDWR; else if (readable) *attributes |= RTP_FILE_ATTRIB_RDONLY; else if (writable) *attributes |= RTP_FILE_ATTRIB_WRONLY; return (0); }
/*---------------------------------------------------------------------- ----------------------------------------------------------------------*/ static int _rtp_lindate_to_date (time_t * lindate, RTP_DATE * rtpdate) { struct tm * ptime; ptime = localtime((const time_t *)lindate); if (!ptime) { #ifdef RTP_DEBUG RTP_DEBUG_OUTPUT_STR("_rtp_lindate_to_date: error returned.\n"); #endif return (-1); } (*rtpdate).year = ptime->tm_year + 1900; (*rtpdate).month = ptime->tm_mon + 1; (*rtpdate).day = ptime->tm_mday; (*rtpdate).hour = ptime->tm_hour; (*rtpdate).minute = ptime->tm_min; (*rtpdate).second = ptime->tm_sec; (*rtpdate).msec = 0; (*rtpdate).dlsTime = ptime->tm_isdst; /* always 0 for gmtime */ (*rtpdate).tzOffset = timezone; return (0); }
/*----------------------------------------------------------------------* rtp_file_get_name *----------------------------------------------------------------------*/ int rtp_file_get_name (void * dirobj, char * name, int size) { unsigned int sizelimit; const char *end; if (!dirobj || ((FSOBJ *)dirobj)->currentPath >= ((FSOBJ *)dirobj)->globdata.gl_pathc) { #ifdef RTP_DEBUG RTP_DEBUG_OUTPUT_STR("rtp_file_get_name: error invalid dirobj.\n"); #endif return (-1); } if (size < 1) { return (0); } end = strrchr(((FSOBJ *)dirobj)->globdata.gl_pathv[((FSOBJ *)dirobj)->currentPath], '/'); if (end) { end++; sizelimit = strlen(end); if (sizelimit > (unsigned int)(size - 1)) { sizelimit = size - 1; } strncpy(name, end, sizelimit); name[sizelimit] = '\0'; } else name[0] = '\0'; return (0); }
/*---------------------------------------------------------------------- ----------------------------------------------------------------------*/ static int _rtp_date_to_windate (RTP_DATE * rtpdate, time_t * windate) { struct tm ptime = {0,0,0,0,0,0,0,0,0}; #ifdef RTP_DEBUG /* ----------------------------------- */ /* Clear the error state by setting */ /* to 0. */ /* ----------------------------------- */ SetLastError (0); #endif ptime.tm_year = (*rtpdate).year - 1900; ptime.tm_mon = (*rtpdate).month - 1; ptime.tm_mday = (*rtpdate).day; ptime.tm_hour = (*rtpdate).hour; ptime.tm_min = (*rtpdate).minute; ptime.tm_sec = (*rtpdate).second; ptime.tm_isdst = (*rtpdate).dlsTime; _timezone = (*rtpdate).tzOffset; *windate = mktime (&ptime); if (*windate == -1) { #ifdef RTP_DEBUG RTP_DEBUG_OUTPUT_STR("_rtp_date_to_windate: error returned.\n"); #endif return (-1); } return (0); }
/*----------------------------------------------------------------------* rtp_file_get_time *----------------------------------------------------------------------*/ int rtp_file_get_time (void * dirobj, RTP_DATE * adate, RTP_DATE * wdate, RTP_DATE * cdate, RTP_DATE * hdate) { RTP_TIMESTAMP rtpTimeStamp; if (!dirobj) { RTP_DEBUG_OUTPUT_STR("rtp_file_get_time: error returned."); return (-1); } /* Temporarily returning this value for all inquiries. */ rtpTimeStamp.year = ((VDSTAT*)dirobj)->ebs_mod_time.year; rtpTimeStamp.second = ((VDSTAT*)dirobj)->ebs_mod_time.second; if (adate) { rtp_timestamp_to_date(adate, &rtpTimeStamp); } if (wdate) { rtp_timestamp_to_date(wdate, &rtpTimeStamp); } if (cdate) { rtp_timestamp_to_date(cdate, &rtpTimeStamp); } if (hdate) { rtp_timestamp_to_date(hdate, &rtpTimeStamp); } return (0); }
int rtp_get_date (RTP_DATE *date) { struct tm *linTime; time_t timer; time (&timer); linTime = localtime ((const time_t *)&timer); if (linTime == NULL) { RTP_DEBUG_OUTPUT_STR("rtp_get_system_time: error returned.\n"); return (-1); } (*date).year = linTime->tm_year + 1900; /* year, AD */ (*date).month = linTime->tm_mon + 1; /* 1 = January, 12 = December */ (*date).day = linTime->tm_mday; /* 1 = first of the month */ (*date).hour = linTime->tm_hour; /* 0 = midnight, 12 = noon */ (*date).minute = linTime->tm_min; /* minutes past the hour */ (*date).second = linTime->tm_sec; /* seconds in minute */ (*date).msec = 0; /* milliseconds in second */ /* These two fields help interpret */ /* the absolute time meaning of the */ /* above values. */ (*date).dlsTime = linTime->tm_isdst; /* boolean; daylight savings time is in effect - always 0 for gmtime */ (*date).tzOffset = 0; //timezone; /* signed int; difference in seconds imposed by timezone (from GMT) */ return (0); }
/*----------------------------------------------------------------------* rtp_file_get_size *----------------------------------------------------------------------*/ int rtp_file_get_size (void * dirobj, unsigned long * size) { #ifdef RTP_DEBUG /* ----------------------------------- */ /* Clear the error state by setting */ /* to 0. */ /* ----------------------------------- */ SetLastError (0); #endif if (!dirobj) { #ifdef RTP_DEBUG RTP_DEBUG_OUTPUT_ERRNO("rtp_file_get_size:"); #endif return (-1); } if (size) { *size = (unsigned long) (((FSOBJ *)dirobj)->fsObject.size); } #ifdef RTP_DEBUG else { RTP_DEBUG_OUTPUT_STR("rtp_file_get_size: error no storage location.\n"); } #endif return (0); }
/*---------------------------------------------------------------------- ----------------------------------------------------------------------*/ static int _rtp_windate_to_date (time_t * windate, RTP_DATE * rtpdate) { struct tm * ptime; #ifdef RTP_DEBUG /* ----------------------------------- */ /* Clear the error state by setting */ /* to 0. */ /* ----------------------------------- */ SetLastError (0); #endif ptime = localtime((const time_t *)windate); if (!ptime) { #ifdef RTP_DEBUG RTP_DEBUG_OUTPUT_STR("_rtp_windate_to_date: error returned.\n"); #endif return (-1); } (*rtpdate).year = ptime->tm_year + 1900; (*rtpdate).month = ptime->tm_mon + 1; (*rtpdate).day = ptime->tm_mday; (*rtpdate).hour = ptime->tm_hour; (*rtpdate).minute = ptime->tm_min; (*rtpdate).second = ptime->tm_sec; (*rtpdate).msec = 0; (*rtpdate).dlsTime = ptime->tm_isdst; /* always 0 for gmtime */ (*rtpdate).tzOffset = _timezone; return (0); }
/*----------------------------------------------------------------------* rtp_net_listen *----------------------------------------------------------------------*/ int rtp_net_listen (RTP_HANDLE sockHandle, int queueSize) { if (listen((int) sockHandle, queueSize) != 0) { int errVal = _rtp_get_last_socket_error(sockHandle); #ifdef RTP_DEBUG RTP_DEBUG_OUTPUT_STR("rtp_net_listen: error returned "); RTP_DEBUG_OUTPUT_INT(errVal); RTP_DEBUG_OUTPUT_STR(".\n"); #endif return (-1); } return (0); }
/*----------------------------------------------------------------------* rtp_net_setbroadcast *----------------------------------------------------------------------*/ int rtp_net_setbroadcast (RTP_HANDLE sockHandle, unsigned int onBool) { if (setsockopt((int) sockHandle, SOL_SOCKET, SO_BROADCAST, (char *) &onBool, sizeof (int)) == -1) { int errVal = _rtp_get_last_socket_error(sockHandle); #if (RTP_DEBUG) RTP_DEBUG_OUTPUT_STR("rtp_net_setbroadcast: error returned "); RTP_DEBUG_OUTPUT_INT(errVal); RTP_DEBUG_OUTPUT_STR(".\n"); #endif return (-1); } return (0); }
/*----------------------------------------------------------------------* rtp_wfile_chmode *----------------------------------------------------------------------*/ int rtp_wfile_chmode (unsigned short * name, unsigned char attributes) { #if (_WIN32_WINNT) >= 0x0400 int winmode; #ifdef RTP_DEBUG int result; /* ----------------------------------- */ /* Clear the error state by setting */ /* to 0. */ /* ----------------------------------- */ SetLastError (0); #endif winmode = 0; winmode |= (attributes & RTP_FILE_ATTRIB_RDONLY) ? FILE_ATTRIBUTE_READONLY : 0; winmode |= (attributes & RTP_FILE_ATTRIB_ARCHIVE) ? FILE_ATTRIBUTE_ARCHIVE : 0; winmode |= (attributes & RTP_FILE_ATTRIB_HIDDEN) ? FILE_ATTRIBUTE_HIDDEN : 0; winmode |= (attributes & RTP_FILE_ATTRIB_SYSTEM) ? FILE_ATTRIBUTE_SYSTEM : 0; /* ----------------------------------- */ /* If no attributes are specified, */ /* set to normal, which is 0x80, not */ /* 0x00 */ /* ----------------------------------- */ if (winmode == 0) { winmode = FILE_ATTRIBUTE_NORMAL; } name = _rtp_unicode_name_to_winname (name); if (SetFileAttributesW((const unsigned short *)name, winmode) < 0) { #ifdef RTP_DEBUG result = GetLastError(); RTP_DEBUG_OUTPUT_STR("rtp_wfile_chmode: error returned "); RTP_DEBUG_OUTPUT_INT(result); RTP_DEBUG_OUTPUT_STR(".\n"); #endif return (-1); } return (0); #endif return (-1); }
/*----------------------------------------------------------------------* rtp_file_lseek *----------------------------------------------------------------------*/ long rtp_file_lseek (RTP_HANDLE fd, long offset, int origin) { off_t result; int relative_to; #ifdef RTP_DEBUG /* ----------------------------------- */ /* Clear the error state by setting */ /* to 0. */ /* ----------------------------------- */ errno = 0; #endif switch (origin) { case 0: relative_to = SEEK_SET; break; case 1: relative_to = SEEK_CUR; break; case 2: relative_to = SEEK_END; break; default: #ifdef RTP_DEBUG errno = EINVAL; RTP_DEBUG_OUTPUT_STR("rtp_file_lseek: error returned "); RTP_DEBUG_OUTPUT_INT(errno); RTP_DEBUG_OUTPUT_STR(".\n"); #endif return (-1); break; } if ((result = lseek ((int) fd, (off_t) offset, relative_to)) == (off_t)-1) { #ifdef RTP_DEBUG RTP_DEBUG_OUTPUT_STR("rtp_file_lseek: error returned "); RTP_DEBUG_OUTPUT_INT(errno); RTP_DEBUG_OUTPUT_STR(".\n"); #endif return (-1); } return ((long) result); }
/*----------------------------------------------------------------------* rtp_file_open *----------------------------------------------------------------------*/ int rtp_file_open (RTP_HANDLE * fdPtr, const char * name, unsigned short flag, unsigned short mode) { int fileHandle; #ifdef RTP_DEBUG /* ----------------------------------- */ /* Clear the error state by setting */ /* to 0. */ /* ----------------------------------- */ errno = 0; #endif fileHandle = open (name, _rtp_flag_to_operation(flag), _rtp_mode_to_permission(mode)); if (fileHandle == (-1)) { /* ----------------------------------- */ /* If trying to open a directory or */ /* opening a read only file with */ /* write privilages. This can be */ /* non-fatal if doing an open to */ /* determine the existance of a */ /* directory. */ /* ----------------------------------- */ if (errno == EACCES) { #ifdef RTP_DEBUG RTP_DEBUG_OUTPUT_STR("rtp_file_open: non-fatal error returned "); RTP_DEBUG_OUTPUT_INT(errno); RTP_DEBUG_OUTPUT_STR(".\n"); #endif return (-2); } #ifdef RTP_DEBUG RTP_DEBUG_OUTPUT_STR("rtp_file_open: error returned "); RTP_DEBUG_OUTPUT_INT(errno); RTP_DEBUG_OUTPUT_STR(".\n"); #endif return (-1); } /* Ignore RTP_FILE_S_HIDDEN, RTP_FILE_S_SYSTEM, and RTP_FILE_S_ARCHIVE. */ *fdPtr = (RTP_HANDLE) fileHandle; return (0); }
/*----------------------------------------------------------------------* rtp_net_getpeername *----------------------------------------------------------------------*/ int rtp_net_getpeername (RTP_HANDLE sockHandle, unsigned char *ipAddr, int *port, int *type) { struct sockaddr_in peerAddr; int peerLen; peerLen = sizeof(peerAddr); memset(&peerAddr, 0, peerLen); #ifdef RTP_DEBUG /* ----------------------------------- */ /* Clear the error state by setting */ /* to 0. */ /* ----------------------------------- */ errno = 0; #endif if (getpeername((int) sockHandle, (struct sockaddr *) &peerAddr, &peerLen) != 0) { #ifdef RTP_DEBUG RTP_DEBUG_OUTPUT_STR("rtp_net_getpeername: error returned "); RTP_DEBUG_OUTPUT_INT(errno); RTP_DEBUG_OUTPUT_STR(".\n"); #endif return (-1); } if (ipAddr) { unsigned long d = peerAddr.sin_addr.s_addr; unsigned char *ptr = (unsigned char *) &d; *type = RTP_NET_TYPE_IPV4; ipAddr[0] = ptr[0]; ipAddr[1] = ptr[1]; ipAddr[2] = ptr[2]; ipAddr[3] = ptr[3]; } if (port) { *port = ntohs(peerAddr.sin_port); } return (0); }