473,414 Members | 1,946 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,414 software developers and data experts.

Dynamically introducing code into the application

Hi,

This is what i am finding out if it is possible. I am not sure but
would like to know..

I have a Client application that sends me a condition like this

(1 == 'A' && 2 == 'B') || (3 == 10) && (4 >= 200 && 4 <= 500)

I do not want to parse anything out of this condition but my server
which is already running when it gets this request just will prepend
an "if" word and i want this if condition to get executed.

if ((1 == 'A' && 2 == 'B') || (3 == 10) && (4 >= 200 && 4 <= 500))

In short, i want to introduce "if" conditions dynamically into the
executable and send the result set back to the client.

Is this possible in any programming language (C, C++ or JAVA)? The
server application will be multithreaded, so it should support that as
well.

Thanks,
Bala
Sep 1 '08 #1
7 1236
Bala <R.***********@gmail.comwrites:
I cant recompile the code because the server application is running.
Something like i want to hook the code in.... As far as i
understand, compiler based programming languages need precompiled
code, but this piece of if block is going to come in runtime.. How
would i handle this situation?
Have a look at:
- interpreter pattern,
- GNU lightning,
- http://vvm.lip6.fr/projects_realizations/ccg/

--
__Pascal Bourguignon__
Sep 1 '08 #2
On Sep 1, 5:06*pm, p...@informatimago.com (Pascal J. Bourguignon)
wrote:
Bala <R.Balaji.I...@gmail.comwrites:
I cant recompile the code because the server application is running.
Something like i want to hook the code in.... * *As far as i
understand, compiler based programming languages need precompiled
code, but this piece of if block is going to come in runtime.. *How
would i handle this situation?

Have a look at:
- interpreter pattern,
- GNU lightning,
-http://vvm.lip6.fr/projects_realizations/ccg/
and LLVM, or even invoking the compiler and running/dlopen-ing the
generated binary.

But probably an ad-hoc interpreter is the simplest and safer solution
in this case.

--
gpd
Sep 1 '08 #3
On 2008-09-01 16:48, Bala wrote:
On Sep 1, 7:15 pm, "Alf P. Steinbach" <al...@start.nowrote:
>* Bala:
Hi. I have a homework assignment I'd like you to provide me complete codes.
1. Suppose you have a Client application that sends your Server a condition like
(1 == 'A' && 2 == 'B') || (3 == 10) && (4 >= 200 && 4 <= 500)
You want to introduce this "if" condition dynamically into the
Server and send the result set back to the Client.
Is this possible in any programming language (C, C++ or JAVA)?

Yes to all.

You just have to compile the code.

And what you have then is a system wide open to attack.
2. Assume that the server application will be multithreaded.

Oh.

By the way, what's the C++ question, again?
Please do not quote signatures.
I cant recompile the code because the server application is running.
Something like i want to hook the code in.... As far as i
understand, compiler based programming languages need precompiled
code, but this piece of if block is going to come in runtime.. How
would i handle this situation?
You compile it to a shared library/DLL and then load that from you
application. Or you use lisp (or a few other dynamic languages) which
can modify themselves.

--
Erik Wikström
Sep 1 '08 #4
On Sep 1, 9:35*pm, Erik Wikström <Erik-wikst...@telia.comwrote:
On 2008-09-01 16:48, Bala wrote:
On Sep 1, 7:15 pm, "Alf P. Steinbach" <al...@start.nowrote:
* Bala:
Hi. I have a homework assignment I'd like you to provide me completecodes.
1. Suppose you have a Client application that sends your Server a condition like
(1 == 'A' && 2 == 'B') || (3 == 10) && (4 >= 200 && 4 <= 500)
You want to introduce this "if" condition dynamically into the
Server and send the result set back to the Client.
Is this possible in any programming language (C, C++ or JAVA)?
Yes to all.
You just have to compile the code.
And what you have then is a system wide open to attack.
2. Assume that the server application will be multithreaded.
Oh.
By the way, what's the C++ question, again?

Please do not quote signatures.
I cant recompile the code because the server application is running.
Something like i want to hook the code in.... * *As far as i
understand, compiler based programming languages need precompiled
code, but this piece of if block is going to come in runtime.. *How
would i handle this situation?

You compile it to a shared library/DLL and then load that from you
application. Or you use lisp (or a few other dynamic languages) which
can modify themselves.

--
Erik Wikström
Hi Erik,
I did think about the following approach.
1. If there is no Dynamic linking then i might generate a new source
file, compile it, run and get the results into the parent process
through IPC.

2. If there is Dynamic Linking, then create a new library/dll, load
and execute it and get the results in the parent application.

But the issue to be addressed here are
1. How costly would this be in terms of performance since the
application will be getting such different requests continously.
2. If 2 different Front Ends send me the same query, then i should be
able to recognize them and use the existing shared library instead of
recompiling it.

The other approach i was thinking of is to be able to use a third
party high performance regular expression parser and evaluater if at
all that is available to execute the query.
Sep 2 '08 #5
On Sep 2, 8:45 am, Bala <R.Balaji.I...@gmail.comwrote:
On Sep 1, 9:35 pm, Erik Wikström <Erik-wikst...@telia.comwrote:
[...]
I did think about the following approach.
1. If there is no Dynamic linking then i might generate a new source
file, compile it, run and get the results into the parent process
through IPC.
2. If there is Dynamic Linking, then create a new library/dll, load
and execute it and get the results in the parent application.
But the issue to be addressed here are
1. How costly would this be in terms of performance since the
application will be getting such different requests continously.
How much time does it take to compile and link a new dynamic
object? On the systems I use, I'd count on something around a
second or two, but it obviously depends.
2. If 2 different Front Ends send me the same query, then i
should be able to recognize them and use the existing shared
library instead of recompiling it.
For what definition of "same query". If textual identity is
sufficient, then you can maintain a hash table with the compiled
queries.
The other approach i was thinking of is to be able to use a
third party high performance regular expression parser and
evaluater if at all that is available to execute the query.
If all you need to handle is regular expressions, that's
definitely the way to go. More generally, I'd probably prefer
some sort of embedded interpreter: many script languages (perl,
python, etc.) can easily be embedded, for example. About the
only time I'd use the compile/link/dlopen solution is if there
was a strict requirement that the dynamic code support all of
C++.

--
James Kanze (GABI Software) email:ja*********@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
Sep 2 '08 #6
Bala wrote:
[Dynamically introducing code into the application]
I did think about the following approach.
1. If there is no Dynamic linking then i might generate a new source
file, compile it, run and get the results into the parent process
through IPC.

2. If there is Dynamic Linking, then create a new library/dll, load
and execute it and get the results in the parent application.

But the issue to be addressed here are
1. How costly would this be in terms of performance since the
application will be getting such different requests continously.
2. If 2 different Front Ends send me the same query, then i should be
able to recognize them and use the existing shared library instead of
recompiling it.

The other approach i was thinking of is to be able to use a third
party high performance regular expression parser and evaluater if at
all that is available to execute the query.
If all you need is a regular expression parser, then use that. There is
one in TR1, which is available as update for some compiler systems.

If you need a type of database entry filtering, think about using a true
database system (with SQL language). The querying is very optimized in
database systems.

If you want to execute some expressions with variables and function
defined by your application, you need a parser and an interpreter.
There's Lua ( http://www.lua.org/ ), which is a very light-weight
embeddable scripting language which is used in many computer games.
The API for Lua is in C, but AFAIK there are also some C++ bindings.

--
Thomas
Sep 2 '08 #7
On 2008-09-02 08:45, Bala wrote:
On Sep 1, 9:35 pm, Erik Wikström <Erik-wikst...@telia.comwrote:
>On 2008-09-01 16:48, Bala wrote:
On Sep 1, 7:15 pm, "Alf P. Steinbach" <al...@start.nowrote:
* Bala:
1. Suppose you have a Client application that sends your Server a condition like

(1 == 'A' && 2 == 'B') || (3 == 10) && (4 >= 200 && 4 <= 500)

You want to introduce this "if" condition dynamically into the
Server and send the result set back to the Client.
Is this possible in any programming language (C, C++ or JAVA)?
>Yes to all.
>You just have to compile the code.
I cant recompile the code because the server application is running.
Something like i want to hook the code in.... As far as i
understand, compiler based programming languages need precompiled
code, but this piece of if block is going to come in runtime.. How
would i handle this situation?

You compile it to a shared library/DLL and then load that from you
application. Or you use lisp (or a few other dynamic languages) which
can modify themselves.
Please do not quota signatures.
Hi Erik,
I did think about the following approach.
1. If there is no Dynamic linking then i might generate a new source
file, compile it, run and get the results into the parent process
through IPC.

2. If there is Dynamic Linking, then create a new library/dll, load
and execute it and get the results in the parent application.

But the issue to be addressed here are
1. How costly would this be in terms of performance since the
application will be getting such different requests continously.
2. If 2 different Front Ends send me the same query, then i should be
able to recognize them and use the existing shared library instead of
recompiling it.
To be honest I was not really serious when I wrote that reply, either of
those solutions are bad in more ways than one.
The other approach i was thinking of is to be able to use a third
party high performance regular expression parser and evaluater if at
all that is available to execute the query.
If the expressions the user can enter is limited to a reasonable number
I would spend some time to write a parser/evaluator in C++ and use it to
evaluate the expressions. In "The C++ Programming Language" you can see
an example of a quite advanced calculator. If you understand that you
should be able to expand it to solve your expressions too.

If the expressions are of a more complex nature you should go the route
of using some external/embedded evaluator. An embedded language such as
lua or python might be a good idea, just remember to add some check so
you do not allow the users to run whatever they want.

--
Erik Wikström
Sep 2 '08 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: David Elliott | last post by:
I can create this: ?xml version="1.0" standalone="yes" ?> <ConfigOpt> <record> <Field_1>Text # 1</Field_1> <Field_2>Text # 2</Field_2> </record> </ConfigOpt>
9
by: netasp | last post by:
hi all, how can I populate one aspx form when page is loading based on page ID? for example: loading page A (to search for VB code) would display labels and texboxes, dropdown lists all related...
36
by: Martin Larsen | last post by:
Hi, When a PHP program links to a library using include or require (or their _once variations), is the library then linked dynamically or statically? While it might seem irrelevant from a...
2
by: Smithers | last post by:
I have a Windows Forms application that implements a plug-in architecture whereby required assemblies are identified and loaded dynamically. Here are the relevant classes: A = application =...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.