Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // MR6zad4.cpp : Defines the entry point for the console application.
- //
- #include "stdafx.h"
- #include "MR6zad4.h"
- #include <io.h>
- #include <stdlib.h>
- #include <string.h>
- #include <fcntl.h>
- #include <afx.h>
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- /////////////////////////////////////////////////////////////////////////////
- // The one and only application object
- CWinApp theApp;
- using namespace std;
- void SendFile(CString file)
- {
- CFile f;
- CFile tmp;
- CString tmps("tmp.log");
- tmp.Open(tmps, CFile::modeCreate | CFile::modeWrite);
- tmp.Write(file, file.GetLength());
- if (!f.Open(file, CFile::modeRead))
- {
- printf("HTTP/1.1 404 Not Found\nContent-Length: 26\nContent-Type: text/plain\n\n404 Error: File not found.");
- exit(-1);
- }
- DWORD len = f.GetLength();
- printf("Content-Type: image/jpeg\r\n");
- printf("Content-Length: %d\r\n\r\n", len);
- int result;
- result = _setmode(_fileno(stdout), _O_BINARY);
- if (result == -1)
- {
- exit(-1);
- }
- else
- {
- for (long i = 0; i < len; i++)
- {
- BYTE buf;
- f.Read(&buf, 1);
- printf("%c", buf);
- }
- fflush(stdout);
- _setmode(_fileno(stdout), _O_TEXT);
- f.Close();
- }
- }
- void parse(char* query)
- {
- CString cquery(query), file;
- int p=cquery.Find(_T("slika="))+6;
- for (int i = p; i < cquery.GetLength(); i++)
- file=file+cquery[i];
- file="slika1.jpeg";
- SendFile(file);
- }
- int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
- {
- int nRetCode = 0;
- // initialize MFC and print and error on failure
- if (!AfxWinInit(::GetModuleHandle(NULL), NULL, ::GetCommandLine(), 0))
- {
- // TODO: change error code to suit your needs
- cerr << _T("Fatal Error: MFC initialization failed") << endl;
- nRetCode = 1;
- }
- else
- {
- // TODO: code your application's behavior here.
- char *reqMethod = getenv("REQUEST_METHOD");
- char *queryString = getenv("QUERY_STRING");
- char *POST_INPUT;
- CString s_post("POST");
- if (s_post.CompareNoCase(CString(reqMethod)) == 0)
- {
- if(queryString != NULL)
- parse(queryString);
- int br_byte = atoi(getenv("CONTENT_LENGTH"));
- if (br_byte > 0)
- {
- char* postInput = new char[br_byte];
- scanf("%s", postInput);
- parse(postInput);
- }
- }
- }
- return nRetCode;
- }
Add Comment
Please, Sign In to add comment