// ismsSend.cpp : Defines the entry point for the console application.
//

//Version: $Revision: 1.2 $

#include "stdafx.h"
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>

using namespace std;


/******************************************************************************/
void Tokenize(const string& str,
                      vector<string>& tokens,
                      const string& delimiters = " ")
{
    // Skip delimiters at beginning.
    string::size_type lastPos = str.find_first_not_of(delimiters, 0);
    // Find first "non-delimiter".
    string::size_type pos     = str.find_first_of(delimiters, lastPos);

    while (string::npos != pos || string::npos != lastPos)
    {
        // Found a token, add it to the vector.
        tokens.push_back(str.substr(lastPos, pos - lastPos));
        // Skip delimiters.  Note the "not_of"
        lastPos = str.find_first_not_of(delimiters, pos);
        // Find next "non-delimiter"
        pos = str.find_first_of(delimiters, lastPos);
    }
}
/*******************************************************************************/

int _tmain(int argc, _TCHAR* argv[])
{
   char *pValue;
   size_t len;
   string url = "http://172.17.29.233:81/sendmsg?user=admin&passwd=admin&cat=1";
   

   //Get query string from the send.html
   errno_t err = _dupenv_s( &pValue, &len, "QUERY_STRING" );
   if ( err ) return -1;
   
   string delimiter ="&";
   vector<string> tokens;

   //Call Tokenize function and pass the tokens vector to it.
   //Note - Pass the vector by reference.
    Tokenize(pValue, tokens,delimiter);

	url.append("&");
	url.append(tokens[0]);
	url.append("&");
	url.append(tokens[1]);

	//Forward it to the SMSFinder
	cout << "Location: " << url << endl << endl;

	free( pValue );
	return 0;
}

