📄 isapimagick.c
字号:
string++; } } *target = '\0'; /* Terminate target string */ return (result);}/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %% %% %% C G I T o A r g v %% %% %% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Method CGIToArgv converts a text string passed as part of a CGI request% into command line arguments.%% The format of the CGIToArgv method is:%% char **CGIToArgv(const char *text,int *argc,char ***argv)%% A description of each parameter follows:%% o text: Specifies the string to segment into a list.%% o argc: This integer pointer returns the number of arguments in the% list.%% o argv: This array of pointers returns the string list unless an error% occurs, otherwise NULL.%*/#define IsCGIDelimiter(c) (((c) == '&') || ((c) == '=') || ((c) == '\0'))unsigned int CGIToArgv(const char *text,int *argc,char ***argv){ char **vector; const char *p, *q; register int i; int count; if (text == (char *) NULL) return(False); /* Determine the number of arguments by scanning for delimiters */ q=text; count=0; while (1) { int len; p=q; while (!IsCGIDelimiter(*q)) q++; len=q-p; if (len > 0) count++; if (*q == '\0') break; q++; } vector=(char **) AcquireMemory((count+2)*sizeof(char *)); if (vector == (char **) NULL) { MagickError(ResourceLimitError,"Unable to convert string to argv", "Memory allocation failed"); return(False); } /* Convert string to an ASCII list. */ vector[0]=AllocateString("isapimagick"); vector[count+1]=(char *) NULL; q=text; i=1; while (i <= count) { int len; p=q; while (!IsCGIDelimiter(*q)) q++; /* Skip an zero length tokens. This typically happens for the case of xxx=& on a CGI GET or POST were the name value pair has no value */ len=q-p; if (len > 0) { vector[i]=(char *) AcquireMemory(q-p+1); if (vector[i] == (char *) NULL) { MagickError(ResourceLimitError,"Unable to convert string to argv", "Memory allocation failed"); return(False); } (void) strncpy(vector[i],p,q-p); vector[i][q-p]='\0'; /* Convert any special HTML codes in place back to ASCII */ HttpUnescape(vector[i], (char *) NULL); i++; } q++; } *argc=count+1; *argv=vector; return(True);}/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %% %% %% G e t F i l e M i m e T y p e %% %% %% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Method GetFileMimeType given the file name, obtain MIME type for% "Content-type:" header field. We try to find MIME type string under% HCR\.xyz key, "Content Type" value. If that fails, we return default% "application/ocetet-stream".%% The format of the GetFileMimeType method is:%% void GetFileMimeType(LPCSTR pszPath, LPSTR pszType, DWORD cbMax)%% A description of each parameter follows:%% o pszPath: file path%% o pszType: points to the buffer that will receive MIME type string%% o cbMax: specifies the maximum number of characters to copy to the% buffer, including the NUL character. If the text exceeds% this limit, it will be truncated.%*/typedef struct _mime_spec{ char *extn, *type;} mime_spec;static mime_spec specs[] = { ".", "text/plain", ".htm", "text/html", ".html", "text/html", ".txt", "text/plain", ".gif", "image/gif", ".jpe", "image/jpeg", ".jpeg", "image/jpeg", ".jpg", "image/jpeg", ".pbm", "image/x-portable-bitmap", ".pgm", "image/x-portable-graymap", ".png", "image/png", ".pnm", "image/x-portable-anymap", ".ppm", "image/x-portable-pixmap", ".ras", "image/x-cmu-raster", ".rgb", "image/x-rgb", ".tif", "image/tiff", ".tiff", "image/tiff", ".xbm", "image/x-xbitmap", ".xpm", "image/x-xpixmap", ".xwd", "image/x-xwindowdump", ".avi", "video/msvideo", ".mov", "video/quicktime", ".mpe", "video/mpeg", ".mpeg", "video/mpeg", ".mpg", "video/mpeg", ".mp3", "audio/mpeg", ".wav", "audio/wav", ".bin", "application/octet-stream", ".eps", "application/postscript", ".exe", "application/octet-stream", ".gtar", "application/x-gtar", ".gz", "application/x-gzip", ".hdf", "application/x-hdf", ".jar", "application/java-archive", ".lzh", "application/x-lzh", ".pdf", "application/pdf", ".ps", "application/postscript", ".tar", "application/tar", ".tgz", "application/x-gzip", ".zip", "application/zip"};void GetFileMimeType(const char *pszPath, char *pszType, unsigned long cbMax){ char *pszExt; /* set MIME type to empty string */ *pszType = '\0'; /* try to locate file extension */ pszExt = strrchr( pszPath, '.'); if (pszExt != NULL) {#ifdef USE_REGISTRY HKEY hKey; unsigned long value_type; long result; /* for file extension .xyz, MIME Type can be found HKEY_CLASSES_ROOT\.xyz key in the registry */ result = RegOpenKeyEx(HKEY_CLASSES_ROOT,pszExt,0L,KEY_READ,&hKey); if (result == ERROR_SUCCESS) { /* we sucessfully opened the key. try getting the "Content Type" value */ result = RegQueryValueEx(hKey,"Content Type",NULL,&value_type, (BYTE *)pszType,&cbMax); /* if we failed to get the value or it is not string, clear content-type field */ if (result != ERROR_SUCCESS || value_type != REG_SZ) *pszType = '\0'; RegCloseKey( hKey ); }#else int i, tagcount = sizeof(specs) / sizeof(mime_spec); /* try to match this record to one of the ones in our named table */ for (i=0; i< tagcount; i++) { if (LocaleCompare(specs[i].extn,pszExt) == 0) strncpy(pszType, specs[i].type, cbMax); }#endif } /* if at this point we don't have MIME type, use default */ if (*pszType == '\0') strncpy(pszType, "application/octet_stream", cbMax);}/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %% %% %% H t t p E x t e n s i o n P r o c %% %% %% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% HttpExtensionProc - ISAPI / Win32 API method. This method is% required by IIS. It is called once per client request. This% is where the extension accomplishes its purpose in life. See% Microsofts ISAPI API documentation for all the gory details.%*/DWORD WINAPI HttpExtensionProc(EXTENSION_CONTROL_BLOCK *pECB){ char **argv, **argv_hw, *errmsg; int argc, argc_hw, i; unsigned int impersonating, status; CHAR
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -