aws version 4 signature in C - c

I am trying to use SQS on aws (on a linux box) using generic C. Not using any sdk (not that there is one for C). I can not find an example I can relate to. Sorry, I don't relate to these newfangled languages. I am proficient in Cobol, fortran, pascal and C. Not python, c++, c# or java. There are "steps" on amazon site, but honestly they expect proficiency on aws and an object oriented language. I just want to create my own https get command for accessing SQS/SNS, can anyone provide a 'C' snipet that creates a complete url with the version 4 signature? Or point me in the correct direction?

Have a look at https://docs.aws.amazon.com/general/latest/gr/sigv4-signed-request-examples.html
If you're proficient with any programming language, you should be able to understand all of that code. It's just string operations and some hashing for which you'll have to use another library. There's also lots of comments to help you with the details.

You can use libcurl for the call:
Use CURLOPT_AWS_SIGV4 argument for the signature https://curl.se/libcurl/c/CURLOPT_AWS_SIGV4.html
You can take a look at CURLOPT_WRITEFUNCTION if you want to store the result into a variable: https://curl.se/libcurl/c/CURLOPT_WRITEFUNCTION.html
And for debugging purpose CURLOPT_VERBOSE can be useful too: https://curl.se/libcurl/c/CURLOPT_VERBOSE.html
Note that you need a version of libcurl superior to 7.75.

Related

PICK/BASIC, FlashBASIC, and C Interoperability

I stumbled across some interesting documentation regarding PICK programming:
http://www.d3ref.com/?token=flash.basic
It says FlashBASIC is a compiled, instead of interpreted, version of PICK programs that are interoperable with PICK. This is great. I am curious about how it describes Object code:
converts Pick/BASIC source code into a list of binary instructions
called object code.
Is this object code interoperable with other languages? Or is it limited to the PICK & Universe operating environment? In other words could a C program call a FlashBASIC program?
This is helpful in defining the C version, but cannot find any clear definition of the FlashBasic version:
What's an object file in C?
You're asking a few different questions which I'll try to answer.
Here is an article I wrote that might help your understanding of FlashBASIC. In short, where traditional MV BASIC is compiled and then run by assembler, the Flash compiler is C and generates an object module that sits below the standard BASIC object in frame space. At runtime that code is then interpreted by a C runtime. For our purposes here, there is no C interface, this is just an internal mechanism for getting code to run faster.
Note from the above that this is Not related to the "What's an object file in C?" topic because object modules in D3 are stored in D3 frames, completely unrelated to common OS-level object modules.
Now about C calling Pick - in your case D3: You can use the CP library - the docs are in the same area as the link you cited. Rather than binding with the database itself, you can also use your code in a client/server mode with the MVSP library if you're using Managed C (.NET). Or you can use any common web service client mechanism in C and setup D3 as a web service server with a number of technologies including MVST, mv.NET, Java, or C/C++.
I know that response is rather vague but you're asking a question which has been discussed at-length in forums over a period of years. If you ask a more specific question you'll get a specific answer. Feel free to refine your query in a comment and we can focus the answer.
Also note that you tagged this question as "u2". If you are really using the U2 variant of MV/Pick (Universe or Unidata) then the reference to the D3 docs was misleading and none of the above applies, as they do this differently in U2 and there is no FlashBASIC there. I know, you're confused. Let's work it out...
Yep, Flash BASIC just translates to C, is compiled, and resulting object files are dynamically loaded and linked, then run from the Pick OS. The feature of C programs running and interacting with BASIC was certainly possible, but we did not implement that feature.

Is Google Test OK for testing C code?

So I've come to like and enjoy using Google Test for a C++ project I'm involved in. I'm just bringing up a new project that will be straight C (a library) and so far can't see any reason why not to continuing using Google Test, even though its a C++ framework. Having a C++ compiler available will not be an issue.
Are there are specific reasons why I shouldn't use Google Test for testing straight C code?
Thanks.
It is pretty common to test C code using a C++ testing frameworks, even the leading book on the subject follows this approach. I have used googletest extensively in the past to unit test C code and can recommend it.
I have written a blog post about it that might be useful:
http://meekrosoft.wordpress.com/2009/11/09/unit-testing-c-code-with-the-googletest-framework/
As all Google's C++ code, Google Test does not use exceptions, so exception safety flow won't be an issue. As long as your headers are C++-compatible (not using C++ keywords, export symbols with correct linkage), it should be fine.
I just thought I'd add another point: since gtest is C++, you'll be parsing your C headers under test as C++. This means the tests don't guarantee that the headers are consumable from C. I recently ran into this with a C library I'm building.
Jason,
be aware of that!!! :D
As Meekrosoft said, yes, it is possible. I also used his website when I tried to do that. It works, but there is one big problem:
GTest is objected oriented tool and C language isn't!
In example, in GTest you have a lot of functions (80% of whole API) that request object as parameter, for example:
EXPECT_CALL(turtle, PenDown()) // turtle is object(class) and PenDown() is method of that object
.Times(AtLeast(1));
from GTest website gmock_for_dummies.md
so you will use only macros like expect_equal, expect_bigger_than and so on...
I would like to suggest you tool CMocka (or some other C unit testing tools). It is also from google (modified by group of non-google developers) and it is created directly for C language. I use this one when I want to test C-type source code.
I hope this helps.. :-) Have a nice day.. :-)
I could not name one. I guess there will be some things which you don't have in "normal" C. E.g I think the TestCase are derived from a certain class. But within the test you can test whatever you like and so why not C?

Does a C language client library for Cassandra exist?

I wish I could use Cassandra for a project where only C language is used.
I tried to find a mature C client library for Cassandra, with no luck.
Shall I try a C++ one instead, like http://github.com/posulliv/libcassandra, or does one exist?
At least in Thrift trunk, there is C glib support, which means it's possible to make a C client for Cassandra. It's probably not well tested yet.
posulliv/libcassandra was never completed and only supports Cassandra 0.6. It lacks several features like super column support, for example.
I also started a C++ client that supports Cassandra 0.7, but it's still half-baked at the moment. Most of the Cassandra API is supported. At the very least, it can be a good example of working with the Thrift API. Of course, if you're capable of contributing to the project or starting a C client, I think many people would appreciate that.
I've created a very basic proof-of-concept C client for Cassandra and put it up on github. It relies on the barely-documented C language support in Thrift (as mentioned in previous answers). This client is not mature by any means, but demonstrates how to use the C files generated by Thrift, and offers some basic functionality; it might be a useful stepping stone towards a more serious C client.
I managed generating C code from the Cassandra trunk Thrift file.
I obtained the following files :
cassandra.c
cassandra.h
cassandra_types.c
cassandra_types.h
No main() function there, I guess these should be linked and used as a library, but I found no API documentation or whatsoever.
The samples in thrift/lib/c_glib/test do not show any client test source...
Will look into this more deeply !
I came across this and hopefully this helps -
http://datastax.github.io/cpp-driver/
There is already a C++ cassandra API called libQtCassandra
http://snapwebsites.org/project/libqtcassandra#Download

What language should we use to let people extend our terminal/sniffer program?

We have a very versatile terminal/sniffer application which can do all sorts of things with TCP, UDP and serial connections.
We are looking to make it extensible -- i.e, allow people to write their own protocol parsers, highlighters, etc.
We created a C-like language for extending the product, and then discovered that for some coders, this presents a steep learning curve.
We are now pondering the question: Should we stick to C or go with something like Ruby or Lua?
C is beautiful for low-level stuff (like parsing binary data), because it supports pointers. But for exactly that reason, it can be tough to learn.
Ruby (etc) are easy to learn, but don't have pointers, so anything that has to do with parsing binary data gets ugly very fast.
What do you think? For extending a product that parses binary data -- Ruby/Lua or C/C++?
Would be great if you could give some background when you respond -- especially if you've done something similar.
Wireshark, the "world's foremost network protocol analyzer", is also a packet sniffer/analyzer, formerly also called Ethereal. It uses Lua to enable writing custom dissectors and taps, see the manual.
However, note that I have not used it, so I cannot tell how nice/effective/easy to learn the API is.
Like TCL, Lua was designed to be tightly integrated with an application. Personally, I find Lua's syntax and idioms to be much easier to deal with than TCL.
Lua is easy to integrate with an existing system, and easy to extend. It is also fairly easy to create safe sandboxes in which user-supplied code can run without full access to the innards of your product.
If you have an API written does it make a difference? The person using the C-like API would only have to understand the difference between passing by value or reference.
Your core does one thing very good, so fine. Let it be that way. I think you should create an API based on std in/out, just like the way of good unix design. Then anyone can extend it in any language of choice.
Tcl was designed with the goal to allow scripting for C programs, so it would be much easier to implement.
http://en.wikipedia.org/wiki/Tcl#Interfacing_with_other_languages
I second Johan's idea. Although in past when I had to do something like this I stuck to
C language APIs and people were restricted to use C language only. But now I look at it,
I realize that it would have been more efficient if we would have done the way Johan describes
PS: And by coincidence it was a protocol testing app using packet sniffer
perl, sed, awk, lex, antler, ... These are languages I'm somewhat familiar with that I'd like to write something like this in. It depends on the data flow, though.
It's really hard to say what the correct thing to use is. Something that I don't think anyone else has mentioned is to keep in mind that the scripts will have bugs. It's very easy to design something like this in such a way that bugs in the scripts (especially run time errors) either just show up a "error in script" or kill the whole system.
You should keep that the scripts should be unit testable and that failures should be reproducible.
I don't think it matters what you do as long as you do one thing, drop the in-house language. It sounds like you choose to make C into a scripting language. One issue I see with this is it will look familiar to C programmers, but not be the same. I can't imagine you have mimicked the semantics of C that would make existing C programmers comfortable. And as you have mentioned, others will find it hard to learn.
The company I am working at have developed their own language. It uses XML for structure so parsing is easy. The language grows "as needed." Meaning if a feature is missing then it will be added. I'm pretty sure it went from an XML database to something that needed control flow. But my point is that if you aren't thinking about building it as a language, then you'll be limiting what users can do with it unintentionally.
Personally I've been looking at how I can get the company to start taking advantage of Lua. And specifically Lua for several reasons. Lua was developed as an extension language that was general purpose. It easily interfaces with the language, including Python and Ruby. It is small and simple for use by non-programmers (not really needed in your case). It is simple enough to replace XML, INI... for configuration settings and powerful enough to replace the need for another programming language.
http://www.lua.org/spe.html

What programs use GSS-API? Any decent sample programs?

I thought I wanted to use GSS-API, but now am not so sure, since I'm having a hard time finding good sample code for a trivial client/server pair. Sun has documentation including sample code, but it's written specifically for their GSS API implementation, using a few proprietary functions not in e.g. the GNU GSS-API (and for which it's not immediately clear to me how to re-implement them against the GNU implementation). Plus, it's written in pre-ANSI C, with K&R function declarations and so on (I had no problem converting the declarations, but it did make me think the Sun example code may be so old as to be irrelevant).
Have you used the GSS-API in an application in, say, the last decade? Do you know of some self-contained tutorial with example programs that's worth reading?
Alternatively, maybe I'm on the wrong track and should try SASL instead. The GNU GSS-API author himself suggests as much.
For what it's worth, I'm using GCC on Linux, and have Kerberos set up already for other purposes.
Yes, you should absolutely be using SASL instead of GSSAPI. It is a much better supported protocol, and the libraries are pretty good. At the very least, you can think of it as a sanity-improving wrapper over GSSAPI, since that is one of the typical plugins implemented for SASL. The only reason you should consider using GSSAPI directly is to implement a SASL library. But don't do that. :)
SASL also has wide use. It is specified as part of IMAP and XMPP.
Are you implementing some custom protocol over TCP?
Sun uses the GSSAPI in their Java code. You can find a bit more information about it here:
Equivalent of 'gss_import_name' and 'gss_init_sec_context' methods in java?
Also you may want to look at the code implementation done by the folks at OpenJDK:
http://www.docjar.org/docs/api/sun/security/jgss/GSSContextImpl.html
They have published a full working example of GSSAPI written in Java.
Grant

Resources