Call VPP ping from a custom plugin - c

I am developing a plugin for VPP, that at some point will have to do pings. The only way I found now, that saves from rewriting all ping functions, is to reuse the existing ping plugin. Instead of calling the entire ping plugin, I tried to include its .c file, and reuse the existing functions, but this gives the following issue:
/home/ubuntu/vpp-base/vpp/src/plugins/nipsla/nipsla.c:372:1: error: redefinition of 'vlib_plugin_registration'
VLIB_PLUGIN_REGISTER () =
Which is quite normal, as include the .c file would mean that we're trying to register two plugins with VLIB_PLUGIN_REGISTER called in my file as well as the one in .c ping file.
Is there another way to call the functions of ping plugin in mine ? or call the plugin itself.

Related

How to get generated content in Apache module and save it to file

I have been playing around with Apache module development and got the module working. However, I ran into the issue of where to hook properly to get all the data I need.
I am making a simple caching module that needs to hook at the beginning of the request and check if the file for this URL exists on disk and if it does then serve that file and stop content generation of Apache.
Currently, the module still continues to go into content generation mode. Let's say I have a long-running PHP script that takes 5s to generate. I would to omit calling the script altogether and just serve the static file from disk.
Furthermore, if the local file does not exist, I would like Apache to execute content generation (actually executes the PHP script) and before sending that data to the client I would like to have a proper hook that somehow gets this data and saves it to a local file.
I have tried ap_hook_fixups, ap_hook_handler and APR_HOOK_LAST, APR_HOOK_LAST and all the variations but no luck.
It always executes at the start of the request.
I also do not want to use any existing Apache modules. I want this to be a self-contained module.
Is there a way to do this kind of thing?
Based on the information you have provided, it sounds like you want your module to execute First and not last.
From what I understand of your issue, you want to make sure the file that would potentially be generated is already on disk or not, and if it is, serve that file, instead of allowing your php script to serve it.
In this case, you'll want to use APR_HOOK_FIRST or APR_HOOK_REALLY_FIRST
Then, assuming your file is on disk, you serve your file, and at the end of your module's work do a return OK;
If the file does not exist, do a return DECLINED
The DECLINED tells Apache that your module should not be the handler for this request and will continue down the list of modules till it finds something that will.
The goal here is to get your module to run before the php module does, to prevent your generation code from running, and fall back onto the php module if the requested file was not found.
Note:
The APR_HOOK_? priorities are just numbers -10 to 30
You should be able to fine tune this if you find your module executing a little too soon, like before mod_ssl for example.
Also, I am terrible at following documents, but the official Apache module development docs are amazingly assembled. Please try to use them, if you have,
I have spent the last 6 months messing around with Apache module development, working on a telegram bot.
I have had to do this song and dace a few times now.

Add .pm file to CakePHP

I have a .pm file with a 30+ subs. The functionality in those subs needs to be called from my CakePHP pages. What is the Cake way to include the .pm file in a CakePHP project so I can call the subs from a View or Controller?
Where should I put the .pm file? How should I include the file into the CakePHP project? How do I call the subs in the .pm file?
I can't find anything in the CakePHP documentation. The place that it seems it should be is in the App, but I can't find anything to do what I want to do.
CakePHP is a PHP framework. According to Wikipedia, a .pm file contains Perl source code basically composed of function definitions. From the PHP point of view, that's as reusable as the blueprints of a Toyota. I suppose it's technically possible to write a PHP extension that's able to compile the Perl code and expose its methods to PHP functions but it'd be a daunting task.
The obvious workaround is to write a Perl executable that loads the module, does whatever you need and prints the output in a format that PHP can use. Afterwards, program execution functions are your friends.
Depending on how your perl scripts work(I have no idea what the difference between .pm and .pl is ), you could create a model or component and access the data using PHP's exec function like so:
exec("path_to_perl /path/to/script.pl arguments to be passed",$output);
Wrap the perl output in your model/components methods. Than in your controller just call the model/component method passing in the relevant arguments.
NOTE: just make sure when running this command you have properly secured the input/output data from the scripts

header file for the function poll

I am trying to create a chat application with a non-blocking socket. for this I am supposed to use the poll() function. I understand that I've to include the "poll.h" header file but my compiler says "No such file or directory found",On the other hand If I don't include this file my code accepts the structure pollfd,it compiles fine but at run time gives me the error that the variable "P is used without being initialised"(I defined "P" to be a pollfd variable)
could some one tell me what should I do in this situation...
Is it possible to download header files?
I am working on visual studio 2008.
According to this forum post, you can try using select() instead of poll(), which Windows does not support. You could try to download the libraries and header files that you need, but those may in turn rely on platform-dependent libraries, bringing you back to square one.
You'll want to use the Windows implementation of select(), of course. Here's the link. The header is file is Winsock2.h.

Compiling an ExtJS MVC app that uses Direct

I have the following case. In my not-compiled project I have included ( in html file) :
extjs-all.js
my api.js ( that generates the remote calls)
app.js
When i compile my app i get one single file that contains extjs library and also my app files. I can't get it to work because i have no place to include my api.js. I can't included before all-classes.js because Ext.ns will not work. If i include after my all-classes.js than my stores will do not have instantieted the direct functions.
Have any idea? Do i have to keep separated the extjs library minified and the app files compilation?
I do something similar;
first comes the ExtJS libs
second the API
third my custom classes/extension (none of them uses the API)
fourth comes the Models, Stores
fifth the rest of your application
If this don't work you should do necessary refactorings to make it work cause you may end up with problems otherwise.

Perl Script not locating File via its set path

I am working on a reporting tool called MARS (Multi Access Reporting Service). This is a tool which reads reports via a SQL server. We have a local machine test environment setup which has everything running fine but when we upload onto the Windows Server 2008 it seems to not want to locate a "required" file. We are running Perl(v5.14.2) on the server and an older version on the desktop/local.
the error i am receieving is:
*HTTP Error 502.2 - Bad Gateway
The specified CGI application misbehaved by not returning a complete set of HTTP headers. The headers it did return are "Can't locate jsdb.pl in #INC (#INC contains: /Inetpub/Scripts /Inetpub/Scripts/Security c:/Perl/site/lib c:/Perl/lib .) at \gl-0185-nas07p\MCL_Dev_MPN_GL\Green_App\MARS\Scripts\Security\security.pl line 7. ".*
Here is the header on the Security.pl file which clearly has the set path and file in it:
use CGI qw/:standard *table start_ul/;
use Date::Calc;
use Win32::ODBC;
use POSIX qw(floor);
###
use lib "/Inetpub/Scripts/Security";
require "jsdb.pl";
###
require "javascript.pl";
require "SecurityUtils.pl";
use lib "/Inetpub/Scripts";
require "webpageutils.pl";
Within the JSDB file is the code for the "Profiles" tab which is used to setup and modify users of the system.
Any help is really appreciated as we cannot seem to get our heads around it.
You seem to be insensitive to case sensitivity, i.e. in the file it is listed as jsdb.pl and in your question you identify it as JSDB. Also, the error message identifies the offending file as security.pl, but your question calls it Security.pl. Perl is case sensitive. Is it possible this could be a factor, e.g. the jsdb.pl file is actually named JSDB.pl?
Where is jsdb.pl? From your source file I would guess it's in /Inetpub/Scripts/Security which doesn't look like a Windows path to me.
At a guess, only C:/Perl/site/lib and C:/Perl/lib exist on your Windows Server machine, and the other paths are either different on that machine or you simply have no access to jsdb.pl from there
Also, you don't seem to be using use strict and use warnings at the top of your code, and your method of using libraries by require 'library.pl' could be very much better

Resources