src/dkim/verifier/verifier.c in iragsdale-rubydkim-0.2 vs src/dkim/verifier/verifier.c in iragsdale-rubydkim-0.3
- old
+ new
@@ -1,29 +1,32 @@
#include "ruby.h"
-#include "rubyio.h"
#include "pdkim1.h"
+#ifndef GetWriteFile
+ #include "ruby/io.h"
+ #define GetWriteFile(fp) rb_io_stdio_file(fp)
+ #define OpenFile rb_io_t
+#else
+ #include "rubyio.h"
+#endif
static VALUE mDKIM, cDKIMVerifier, cDKIMResolver, cDKIMSignature, cTime;
// feed data to the dkim context
VALUE verifier_feed(VALUE obj, VALUE text)
{
- // create a pointer for the length of the string
- int length;
-
// get the dkim context
pdkim_ctx *ctx;
Data_Get_Struct(obj, pdkim_ctx, ctx);
// get the text data
char * data = StringValuePtr(text);
// pass the string data to pdkim_feed while setting the length
- int i = 0;
if ( pdkim_feed(ctx, data, strlen(data)) != PDKIM_OK) {
printf("pdkim_feed() error\n");
}
+ return Qnil;
}
// create a signature object from a pdkim_signature
VALUE new_signature(pdkim_signature *sig)
{
@@ -65,11 +68,13 @@
pdkim_ctx *ctx;
Data_Get_Struct(obj, pdkim_ctx, ctx);
// finish up the call
pdkim_signature *signatures;
- if ( pdkim_feed_finish(ctx,&signatures) == PDKIM_OK ) {
+
+ int result = pdkim_feed_finish(ctx,&signatures);
+ if ( result == PDKIM_OK ) {
// create an array to hold the new signatures
VALUE rsigs = rb_ary_new();
// step through the list of signatues
@@ -82,12 +87,11 @@
signatures = signatures->next;
}
return rsigs;
}
else {
- printf("pdkim_feed_finish error");
- return rb_str_new2("");
+ rb_raise(rb_eRuntimeError, "error finishing signature: %d", result);
}
}
// looks up the DNS record given
int query_dns_txt(char *name, char *answer) {
@@ -145,9 +149,10 @@
}
// otherwise, raise an exception
else {
rb_raise(rb_eTypeError, "debug requires a file handle");
}
+ return Qnil;
}
// defines the new ruby class and hooks up the proper methods
void Init_verifier() {
mDKIM = rb_define_module("DKIM");