git-svn-id: https://svn.code.sf.net/p/nsis/code/NSIS/trunk@1879 212acab6-be3b-0410-9dea-997c60f758d6
This commit is contained in:
kichik 2002-12-04 20:05:35 +00:00
parent 25459dcb70
commit 53d954e00b
7 changed files with 160 additions and 259 deletions

View file

@ -33,7 +33,6 @@ JNL_AsyncDNS::~JNL_AsyncDNS()
unsigned long WINAPI JNL_AsyncDNS::_threadfunc(LPVOID _d) unsigned long WINAPI JNL_AsyncDNS::_threadfunc(LPVOID _d)
{ {
JNL_AsyncDNS *_this=(JNL_AsyncDNS*)_d; JNL_AsyncDNS *_this=(JNL_AsyncDNS*)_d;
int nowinsock=JNL::open_socketlib();
struct hostent *hostentry; struct hostent *hostentry;
hostentry=::gethostbyname(_this->m_hostname); hostentry=::gethostbyname(_this->m_hostname);
if (hostentry) if (hostentry)
@ -42,7 +41,6 @@ unsigned long WINAPI JNL_AsyncDNS::_threadfunc(LPVOID _d)
} }
else else
_this->m_addr=INADDR_NONE; _this->m_addr=INADDR_NONE;
if (!nowinsock) JNL::close_socketlib();
_this->m_thread_kill=1; _this->m_thread_kill=1;
return 0; return 0;
} }

View file

@ -29,8 +29,6 @@ JNL_Connection::JNL_Connection(JNL_AsyncDNS *dns, int sendbufsize, int recvbufsi
m_recv_buffer=(char*)malloc(m_recv_buffer_len); m_recv_buffer=(char*)malloc(m_recv_buffer_len);
m_send_buffer=(char*)malloc(m_send_buffer_len); m_send_buffer=(char*)malloc(m_send_buffer_len);
m_socket=-1; m_socket=-1;
memset(m_recv_buffer,0,recvbufsize);
memset(m_send_buffer,0,sendbufsize);
m_remote_port=0; m_remote_port=0;
m_state=STATE_NOCONNECTION; m_state=STATE_NOCONNECTION;
m_recv_len=m_recv_pos=0; m_recv_len=m_recv_pos=0;

View file

@ -9,53 +9,24 @@
#ifndef _NETINC_H_ #ifndef _NETINC_H_
#define _NETINC_H_ #define _NETINC_H_
#ifdef _WIN32
#include <windows.h> #include <windows.h>
#include <stdio.h> #include "util.h"
#include <time.h>
#define strcasecmp(x,y) stricmp(x,y) #define strcasecmp(x,y) stricmp(x,y)
#define ERRNO (WSAGetLastError()) #define ERRNO (WSAGetLastError())
#define SET_SOCK_BLOCK(s,block) { unsigned long __i=block?0:1; ioctlsocket(s,FIONBIO,&__i); } #define SET_SOCK_BLOCK(s,block) { unsigned long __i=block?0:1; ioctlsocket(s,FIONBIO,&__i); }
#define EWOULDBLOCK WSAEWOULDBLOCK #define EWOULDBLOCK WSAEWOULDBLOCK
#define EINPROGRESS WSAEWOULDBLOCK #define EINPROGRESS WSAEWOULDBLOCK
#define memset mini_memset
#define memcpy mini_memcpy
#define strcpy lstrcpy
#define strncpy lstrcpyn
#define strcat lstrcat
#define strlen lstrlen
#define malloc(x) (new char[x])
#define free(x) {delete x;}
typedef int socklen_t; typedef int socklen_t;
#else
#ifndef THREAD_SAFE
#define THREAD_SAFE
#endif
#ifndef _REENTRANT
#define _REENTRANT
#endif
#include <pthread.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <sys/time.h>
#include <arpa/inet.h>
#include <netdb.h>
#include <stdarg.h>
#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>
#include <signal.h>
#include <stdlib.h>
#include <errno.h>
#include <string.h>
#define ERRNO errno
#define closesocket(s) close(s)
#define SET_SOCK_BLOCK(s,block) { int __flags; if ((__flags = fcntl(s, F_GETFL, 0)) != -1) { if (!block) __flags |= O_NONBLOCK; else __flags &= ~O_NONBLOCK; fcntl(s, F_SETFL, __flags); } }
#define stricmp(x,y) strcasecmp(x,y)
#define strnicmp(x,y,z) strncasecmp(x,y,z)
#define wsprintf sprintf
#endif // !_WIN32
#ifndef INADDR_NONE #ifndef INADDR_NONE
#define INADDR_NONE 0xffffffff #define INADDR_NONE 0xffffffff
#endif #endif
@ -68,15 +39,4 @@ typedef int socklen_t;
#define SHUT_RDWR 2 #define SHUT_RDWR 2
#endif #endif
extern void mini_memset(void *,char,int);
extern void mini_memcpy(void *,void*,int);
#define memset mini_memset
#define memcpy mini_memcpy
#define strcpy lstrcpy
#define strncpy lstrcpyn
#define strcat lstrcat
#define strlen lstrlen
#define malloc(x) GlobalAlloc(GPTR,(x))
#define free(x) { if (x) GlobalFree(x); }
#endif //_NETINC_H_ #endif //_NETINC_H_

View file

@ -48,6 +48,7 @@ HANDLE hModule;
HWND g_parent; HWND g_parent;
HWND g_dialog; HWND g_dialog;
HWND g_childwnd; HWND g_childwnd;
HWND g_hwndProgressBar;
static int g_cancelled; static int g_cancelled;
BOOL CALLBACK DownloadDialogProc(HWND hwndDlg, BOOL CALLBACK DownloadDialogProc(HWND hwndDlg,
@ -71,28 +72,12 @@ static LRESULT CALLBACK ParentWndProc(HWND hwnd, UINT message, WPARAM wParam, LP
return CallWindowProc((long (__stdcall *)(struct HWND__ *,unsigned int,unsigned int,long))lpWndProcOld,hwnd,message,wParam,lParam); return CallWindowProc((long (__stdcall *)(struct HWND__ *,unsigned int,unsigned int,long))lpWndProcOld,hwnd,message,wParam,lParam);
} }
BOOL APIENTRY DllMain( HANDLE _hModule, BOOL APIENTRY DllMain( HANDLE _hModule,
DWORD ul_reason_for_call, DWORD ul_reason_for_call,
LPVOID lpReserved LPVOID lpReserved
) )
{ {
switch (ul_reason_for_call)
{
case DLL_PROCESS_ATTACH:
case DLL_THREAD_ATTACH:
hModule = _hModule; hModule = _hModule;
JNL::open_socketlib ();
break;
case DLL_THREAD_DETACH:
case DLL_PROCESS_DETACH:
JNL::close_socketlib ();
break;
}
return TRUE; return TRUE;
} }
@ -103,38 +88,11 @@ static void progress_callback(char *msg, int read_bytes)
{ {
if (g_dialog) if (g_dialog)
{ {
HWND hwndProgressBar = GetDlgItem (g_dialog, IDC_PROGRESS1);
SetDlgItemText (g_dialog, IDC_STATIC2, msg); SetDlgItemText (g_dialog, IDC_STATIC2, msg);
if (g_file_size) SendMessage(hwndProgressBar, PBM_SETPOS, (WPARAM)MulDiv(read_bytes,30000,g_file_size), 0); if (g_file_size) SendMessage(g_hwndProgressBar, PBM_SETPOS, (WPARAM)MulDiv(read_bytes,30000,g_file_size), 0);
} }
} }
static int getProxyInfo(char *out)
{
DWORD v=0;
HKEY hKey;
if (RegOpenKeyEx(HKEY_CURRENT_USER,"Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings",0,KEY_READ,&hKey) == ERROR_SUCCESS)
{
DWORD l = 4;
DWORD t;
if (RegQueryValueEx(hKey,"ProxyEnable",NULL,&t,(unsigned char *)&v,&l) == ERROR_SUCCESS && t == REG_DWORD)
{
l=8192;
if (RegQueryValueEx(hKey,"ProxyServer",NULL,&t,(unsigned char *)out,&l ) != ERROR_SUCCESS || t != REG_SZ)
{
v=0;
*out=0;
}
}
else v=0;
out[8192-1]=0;
RegCloseKey(hKey);
}
return v;
}
extern char *_strstr(char *i, char *s); extern char *_strstr(char *i, char *s);
#define strstr _strstr #define strstr _strstr
@ -143,9 +101,22 @@ void downloadFile(char *url,
HANDLE hFile, HANDLE hFile,
char **error) char **error)
{ {
static char buf[8192]; WSADATA wsaData;
WSAStartup(MAKEWORD(1, 1), &wsaData);
static char buf[8192]="";
char *p=NULL; char *p=NULL;
if (getProxyInfo(buf))
HKEY hKey;
if (RegOpenKeyEx(HKEY_CURRENT_USER,"Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings",0,KEY_READ,&hKey) == ERROR_SUCCESS)
{
DWORD l = 4;
DWORD t;
DWORD v;
if (RegQueryValueEx(hKey,"ProxyEnable",NULL,&t,(unsigned char *)&v,&l) == ERROR_SUCCESS && t == REG_DWORD && v)
{
l=8192;
if (RegQueryValueEx(hKey,"ProxyServer",NULL,&t,(unsigned char *)buf,&l ) == ERROR_SUCCESS && t == REG_SZ)
{ {
p=strstr(buf,"http="); p=strstr(buf,"http=");
if (!p) p=buf; if (!p) p=buf;
@ -157,6 +128,11 @@ void downloadFile(char *url,
char *p2=strstr(p,"="); char *p2=strstr(p,"=");
if (p2) p=0; // we found the wrong proxy if (p2) p=0; // we found the wrong proxy
} }
}
buf[8192-1]=0;
RegCloseKey(hKey);
}
DWORD start_time=GetTickCount(); DWORD start_time=GetTickCount();
JNL_HTTPGet *get=new JNL_HTTPGet(JNL_CONNECTION_AUTODNS,16384,(p&&p[0])?p:NULL); JNL_HTTPGet *get=new JNL_HTTPGet(JNL_CONNECTION_AUTODNS,16384,(p&&p[0])?p:NULL);
int st; int st;
@ -225,8 +201,7 @@ void downloadFile(char *url,
*error = "Server did not specify content length."; *error = "Server did not specify content length.";
break; break;
} else if (g_dialog) { } else if (g_dialog) {
HWND hwndProgressBar = GetDlgItem (g_dialog, IDC_PROGRESS1); SendMessage(g_hwndProgressBar, PBM_SETRANGE, 0, MAKELPARAM(0,30000));
SendMessage(hwndProgressBar, PBM_SETRANGE, 0, MAKELPARAM(0,30000));
g_file_size=cl; g_file_size=cl;
} }
} }
@ -291,10 +266,12 @@ void downloadFile(char *url,
if (*error) if (*error)
{ {
char *t=*error; char *t=*error;
*error = (char *)GlobalAlloc(GPTR,strlen(t)+1); *error = new char[lstrlen(t)+1];
lstrcpy(*error,t); lstrcpy(*error,t);
} }
delete get; delete get;
WSACleanup();
} }
RECT r, cr; RECT r, cr;
@ -379,6 +356,7 @@ __declspec(dllexport) void download (HWND parent,
} }
} }
g_hwndProgressBar = GetDlgItem (g_dialog, IDC_PROGRESS1);
char *error=NULL; char *error=NULL;
@ -398,8 +376,6 @@ __declspec(dllexport) void download (HWND parent,
if (wasen) EnableWindow(GetDlgItem(g_parent,IDCANCEL),0); if (wasen) EnableWindow(GetDlgItem(g_parent,IDCANCEL),0);
} }
if (g_cancelled) { if (g_cancelled) {
setuservariable(INST_0, "cancel"); setuservariable(INST_0, "cancel");
DeleteFile(filename); DeleteFile(filename);
@ -419,8 +395,9 @@ __declspec(dllexport) void download_quiet(HWND parent,
char *variables, char *variables,
stack_t **stacktop) stack_t **stacktop)
{ {
g_hwndProgressBar=0;
download(NULL,stringsize,variables,stacktop); download(NULL,stringsize,variables,stacktop);
} }
} } //extern "C"

View file

@ -10,31 +10,6 @@
#include "util.h" #include "util.h"
int JNL::open_socketlib()
{
#ifdef _WIN32
WSADATA wsaData;
if (WSAStartup(MAKEWORD(1, 1), &wsaData)) return 1;
#endif
return 0;
}
void JNL::close_socketlib()
{
#ifdef _WIN32
WSACleanup();
#endif
}
unsigned long JNL::ipstr_to_addr(const char *cp)
{
return ::inet_addr(cp);
}
void JNL::addr_to_ipstr(unsigned long addr, char *host, int maxhostlen)
{
struct in_addr a; a.s_addr=addr;
char *p=::inet_ntoa(a); strncpy(host,p?p:"",maxhostlen);
}
int my_atoi(char *s) int my_atoi(char *s)
{ {
int sign=0; int sign=0;

View file

@ -27,15 +27,8 @@
#ifndef _UTIL_H_ #ifndef _UTIL_H_
#define _UTIL_H_ #define _UTIL_H_
class JNL
{
public:
static int open_socketlib();
static void close_socketlib();
static unsigned long ipstr_to_addr(const char *cp);
static void addr_to_ipstr(unsigned long addr, char *host, int maxhostlen);
};
int my_atoi(char *p); int my_atoi(char *p);
void mini_memset(void *,char,int);
void mini_memcpy(void *,void*,int);
#endif //_UTIL_H_ #endif //_UTIL_H_

Binary file not shown.