LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 08-03-2010, 08:26 AM   #1
smuro
LQ Newbie
 
Registered: Jun 2009
Posts: 9

Rep: Reputation: 0
Multiple runs with the same login, C++


I am trying to implement a corba program (client) to retrieve customer
information from the server. Since the server allow to login once and
perform your operations until the lifetime experies, i want the client to use already login connection to perform the retrieve function without
login in to the server for every request.

Suppose retrieve has three functions, logon(), perform() and logoff()
Pseudo code;
Quote:
1. User runs a client application
./retrieve <URI> <customerID>
2. if the client program has already login, donot login, go to 4
3. Client program login to the server program
4. client program invoke perform(customerID,secKey, BaseList) to retrieve customer information, server will return customer status
5. Client program submit customer information to the calling program, in
this case, stdio
6. Unless specified, do not logoff
7. exit
8. go to 1
Here is the code snippets;

Code:
static void login(Base::Customer_ptr e) {

  CORBA::String_var username = (const char*) "mimi";
  CORBA::String_var password = (const char*) "ahh!!";
  CORBA::String_var seckey= (const char*) "";
  Base::BaseList  BaseLists;

  BaseList.length(2);
  BaseList[0].bName =  CORBA::string_dup("CATEGORY");
  BaseList[0].bValue = CORBA::string_dup("VIP");

  BaseList[1].bName =  CORBA::string_dup("GENDER");
  BaseList[1].bValue = CORBA::string_dup("F");

//I JUST WANT TO PERFORM THIS FUNCTION IFF IT HASNT BEEN INVOKED BEFORE,
ELSE SKIP THIS METHOD
  e->Login(username,password,seckey); //NEW seckey WILL BE RETURNED

  Base::BaseResult result;
  result=  e-> Perform(customerID, secKey, BaseList);

  cerr  << "***********************************" <<endl
        << "****         TASK RESULT      *****" <<endl
        << "****     \t"<< taskresult << "  *****" <<endl
        << "***********************************" <<endl;

  //PERFORM THIS FUCTION ONLY IF NECESSARY, MAY CHECK argc[] for specified
option
 e-> logoff();

}
Since the first login will return a seckey which can be used for subsequent runs, i was thinking of storing the key to the file (with md5checksum), and see if the key file exist before continue. The question is how can i do that.

Thanks in advance
 
Old 08-03-2010, 10:52 AM   #2
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 454Reputation: 454Reputation: 454Reputation: 454Reputation: 454
Quote:
Originally Posted by smuro View Post
... see if the key file exist before continue. The question is how can i do that.
...
To do what ? Check file existence ?
 
Old 08-03-2010, 01:09 PM   #3
smuro
LQ Newbie
 
Registered: Jun 2009
Posts: 9

Original Poster
Rep: Reputation: 0
Partly yes. 1st check if the file exists, fetch the userid and security key then continue with the rest of the program. If file doesnt exist, initiate a login, create the security_file, save userid and security key for future use, then continue with the rest of the program.

Java code similarity would be like;

Want to figure out if someone can lead me to C++ code

Code:
private void checkFile(String userid)
*** *** *** throws RecoverableConnectionException {
*** *** // Connecting to the peer 
*** *** // Check if the sec file exist and it hasn't been changed by the external program.
*** *** if (!new File(SEC_FILE).exists()) {
*** *** *** if (cat.isDebugEnabled()) {
*** *** *** *** cat.debug("Security File exists: "
*** *** *** *** *** *** + new File(SEC_FILE).exists()
*** *** *** *** *** *** + " - logging in");
*** *** *** }
*** *** *** cat.debug("Starting login process for: " + userid);
*** *** *** logon();
*** *** *** cat.debug("Logon complete for: " + userid);
*** *** } else {
*** *** *** if (cat.isDebugEnabled()) {
*** *** *** *** cat.debug("Security File exists: "
*** *** *** *** *** *** + new File(SEC_FILE).exists()
*** *** *** *** *** *** + " - connecting to server");
*** *** *** }

*** *** *** // check checksum
*** *** *** md5sumCheck();

*** *** *** cat.debug("Starting connection for: " + userid);
*** *** *** connect();
*** *** *** cat.debug("Connection complete for: " + userid);
*** *** }
*** }
and the snippets for writing a sec file could be
Code:
*** *** *** // Set userid
*** *** *** userid = userID.value;

*** *** *** // Set securitykey
*** *** *** securitykey = secKey.value;

*** *** *** // Store securitykey
*** *** *** printWriter = new java.io.PrintWriter(new java.io.FileWriter(
*** *** *** *** *** SEC_KEY, false), true);
*** *** *** printWriter.println(userid);
*** *** *** printWriter.println(securitykey);
I am looking for similar solution for C++. Kindly post one

/S
 
Old 08-03-2010, 09:38 PM   #4
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 454Reputation: 454Reputation: 454Reputation: 454Reputation: 454
Quote:
Originally Posted by smuro View Post
Partly yes. 1st check if the file exists ...
man 2 stat
man 2 access
.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
postgresql runs in multiple pid dinakumar12 Linux - Server 3 07-19-2010 03:02 PM
LXer: Terminator runs multiple GNOME terminals in the same window LXer Syndicated Linux News 0 05-14-2008 11:01 PM
What's the name of the file that runs programs at x-login? Jim48307 Linux - Newbie 2 11-09-2004 09:21 PM
login as root just runs YaST mortensent Linux - Newbie 4 08-18-2004 02:28 PM
Mandrake 9.2 runs multiple copies of services. Help QtCoder Mandriva 0 03-10-2004 05:23 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:38 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration