Thursday, June 27, 2013

Hello World

Syntax Highliter in Use

// understanding call-by-value vs call-by-reference

#include 

int f1 (int, int, int);
int f2 (int&, int&, int&);
int f3 (int, int&, int);

void main () {
  int i, j, k;

  i=1;
  j=2;
  k=3;

  cout << endl;
  cout << "Initial values of i, j, and k are: " 
    << i << ", " << j << ", and " << k << endl << endl;
  cout << "f1(i,j,k) = " << f1(i,j,k) << endl;
  cout << "Values of i, j, and k after the call to f1 are: " 
    << i << ", " << j << ", and " << k << endl << endl;
  cout << "f2(i,j,k) = " << f2(i,j,k) << endl;
  cout << "Values of i, j, and k after the call to f2 are: " 
    << i << ", " << j << ", and " << k << endl << endl;
  cout << "f3(i,j,k) = " << f3(i,j,k) << endl;
  cout << "Values of i, j, and k after the call to f3 are: " 
    << i << ", " << j << ", and " << k << endl;
}

int f1 (int x, int y, int z) {
  x=x+5;
  y=y+5;
  z=z+5;
  return(x+y+z);
}

int f2 (int& x, int& y, int& z) {
  x=x+5;
  y=y+5;
  z=z+5;
  return(x+y+z);
}

int f3 (int x, int& y, int z) {
  x=x+5;
  y=y+5;
  z=z+5;
  return(x+y+z);
}

[Article Link] Publish Source code in Blogger

http://oneqonea.blogspot.in/2012/04/how-do-i-add-syntax-highlighting-to-my.html

Friday, June 21, 2013

Refactoring n configuring

We have a set of scripts in one of the products in my current company. I have been maintaining them for last six months. They are simple scripts which perform some routine maintenance task like logging etc.
So I have been steadily improving them and adding more options and hardening them. But I wasn't able to spend some considerable time and finish them off with some real world unit testing and accompanying documentation with guidelines for use in various scenarios.
I finished this big task this week. I have made considerable changes to make them very configurable so that they can be used in one of 7-8 possible use cases with minimal amount of changes. I also added logging capability and fine tuned it. That was a feature we were jn sore need of having. The logging capability will let us perform statistical analysis based on the logs. Overall this was the one great task of the week.
On the documentation front I have created a standard document which depicts all the scenarios in which the scripts will be used and I have provided samples for the use cases too. I think this is going to help our implementation team a lot. 

And I thought Qt's documentation was average

Till I encountered OpenSSL!!!

Thursday, June 13, 2013

Upload files to a FTP site via batch script

http://www.howtogeek.com/50359/upload-files-to-an-ftp-site-via-a-batch-script/


Original Script: 

 
 @ECHO OFF
ECHO Upload to FTP
ECHO Written by: Jason Faulkner
ECHO SysadminGeek.com
ECHO.
ECHO.

REM Usage:
REM UploadToFTP [/L] FileToUpload
REM
REM Required Parameters:
REM    FileToUpload
REM        The file or file containing the list of files to be uploaded.
REM
REM Optional Parameters:
REM    /L    When supplied, the FileToUpload is read as a list of files to be uploaded.
REM        A list of files should be a plain text file which has a single file on each line.
REM        Files listed in this file must specify the full path and be quoted where appropropriate.

SETLOCAL EnableExtensions

REM Connection information:
SET Server=
SET UserName=
SET Password=


REM ---- Do not modify anything below this line ----

SET Commands="%TEMP%\SendToFTP_commands.txt"

REM FTP user name and password. No spaces after either.
ECHO %UserName%> %Commands%
ECHO %Password%>> %Commands%

REM FTP transfer settings.
ECHO binary >> %Commands%

IF /I {%1}=={/L} (
    REM Add file(s) to the list to be FTP'ed.
    FOR /F "usebackq tokens=*" %%I IN ("%~dpnx2") DO ECHO put %%I >> %Commands%
) ELSE (
    ECHO put "%~dpnx1" >> %Commands%
)

REM Close the FTP connection.
ECHO close  >> %Commands%
ECHO bye    >> %Commands%

REM Perform the FTP.
FTP -d -i -s:%Commands% %Server%

ECHO.
ECHO.

REM Clean up.
IF EXIST %Commands% DEL %Commands%

ENDLOCAL


/*********************   Modified script *************************/
/* Modified to provide fixed username/password and variable server IP 
to be passed on command line as first parameter and after that the file/ 
fileList to be ftp'd */

@ECHO OFF
ECHO FTP Upload Script

ECHO Written by: Jason Faulkner
ECHO SysadminGeek.com
ECHO.
ECHO.


REM Usage:
REM FTPScript serverIP [/L] FileToUpload
REM
REM Required Parameters:
REM serverIP
REM     The IP of FTP site; Username/password is hardcoded
REM
REM    FileToUpload
REM        The file or file containing the list of files to be uploaded.
REM
REM Optional Parameters:
REM    /L    When supplied, the FileToUpload is read as a list of files to be uploaded.
REM        A list of files should be a plain text file which has a single file on each line.
REM        Files listed in this file must specify the full path and be quoted where appropropriate.

SETLOCAL EnableExtensions

REM Connection information:
SET Server=%1
SET UserName=ftpuser
SET Password=ftppassword

SET Commands="%TEMP%\SendToFTP_commands.txt"
CD "D:\LIU_BACKUP\master"
REM FTP user name and password. No spaces after either.
ECHO %UserName%> %Commands%
ECHO %Password%>> %Commands%

REM FTP transfer settings.
ECHO binary >> %Commands%

IF /I {%2}=={/L} (
    REM Add file(s) to the list to be FTP'ed.
    FOR /F "usebackq tokens=*" %%I IN ("%~dpnx3") DO ECHO put %%I >> %Commands%
) ELSE (
    ECHO put "%~dpnx2" >> %Commands%
)

REM Close the FTP connection.
ECHO close  >> %Commands%
ECHO bye    >> %Commands%

REM Perform the FTP.
FTP -d -i -s:%Commands% %Server%

ECHO.
ECHO.

REM Clean up.
IF EXIST %Commands% DEL %Commands%

ENDLOCAL

Wednesday, June 5, 2013

OpenSSL vs the Me

I have been working on openSSL integration for some time. And its been quite some experience. I knew openSSL by name only. I was aware of SSL certificates - you know how sometimes things fail when you get some invalid certificate error.
So I have learned a lot about both OpenSSL and authentication. I have also learned about public key encryption. But this has not been easy. I got stuck at almost every step.
The problem was OpenSSL looks easy to use and as long as you are generating some certificates and using them with your web hosts. Look towards integration with existing software and then you need to take some easy chill pill.
Basically I didn't even wanted to touch openSSL. I wanted to use Qt's inbuilt openSSL support and be done with it. But the requirements changed midway and Qt just couldn't extend far enough. I tried everything till inheriting QSslCertificate but it just wasn't designed to serve our requirement.
So after going through some OpenSSL research I decided to bite the bullet and went for it. That meant I needed to build openssl with my setup. Thankfully I got hold of a good tutorial which asked me to install perl and then after a few steps my openssl was ready. Next I created a sample certificate and went about reading it. Here I hit a wall. Since openssl integration is a rare thing, there are so few pointers out on the net. But after struggling around for a few days I finally picked up a few pieces here n there and made them work together to read my sample certificate.
After getting there I integrated my existing authentication code to it and made that work together.
You must be thinking, wow! He has done it. But that's just the first half. Since I wanted almost no human interaction I had to create a program to generate the certificate as well. There I hit few more snags. But after some time I even got that to work. But by then the requirement has changed again and so that invalidated my code.
So now I am stuck where I have the certificate creator and authenticator working properly but the reader isn't able to read the generated certificate. I know few more hours of headbang is going to solve this too. But just so you know, openssl sucks! C n C++ suck even more. But I'm happy fighting!