Diff

Differences From Artifact [9641a2fef0]:

To Artifact [75e6704a49]:


     8      8   #include <ppapi/cpp/module.h>
     9      9   #include <ppapi/cpp/core.h>
    10     10   #include <ppapi/cpp/var.h>
    11     11   #include <ppapi/cpp/var_dictionary.h>
    12     12   #include <ppapi/cpp/var_array.h>
    13     13   #include <ppapi/cpp/var_array_buffer.h>
    14     14   
    15         -#include <stdio.h>
    16         -
    17     15   #include "pcsc-nacl.h"
    18     16   #include "cackey-chrome.h"
    19     17   
    20     18   class CACKeyInstance : public pp::Instance {
    21     19   	private:
    22     20   		void pcscNaClInitWrapper(pp::Core *core) {
    23         -			fprintf(stderr, "Calling pcscNaClInit(%p, %p)\n", this, core);
    24         -
    25     21   			pcscNaClInit(this, core);
    26         -
    27         -			fprintf(stderr, "pcscNaClInit terminated\n");
    28     22   		}
    29     23   	public:
    30     24   		explicit CACKeyInstance(PP_Instance instance, pp::Core *core) : pp::Instance(instance) {
    31     25   			std::thread(&CACKeyInstance::pcscNaClInitWrapper, this, core).detach();
    32     26   		}
    33     27   
    34     28   		virtual ~CACKeyInstance() {}
................................................................................
    35     29   
    36     30   		virtual void HandleMessageThread(pp::VarDictionary *message) {
    37     31   			int numCertificates, i;
    38     32   			struct cackey_certificate *certificates;
    39     33   			pp::VarDictionary *reply;
    40     34   			pp::VarArray certificatesPPArray;
    41     35   			pp::VarArrayBuffer *certificateContents;
    42         -			pp::Var command;
           36  +			pp::Var command, incomingCertificateContents;
    43     37   
    44     38   			/*
    45     39   			 * Extract the command
    46     40   			 */
    47     41   			command = message->Get("command");
    48     42   
    49     43   			/*
    50     44   			 * Do the thing we are being asked to do
    51     45   			 */
           46  +			reply = new pp::VarDictionary();
           47  +
    52     48   			if (command.AsString() == "listcertificates") {
    53     49   				numCertificates = cackey_chrome_listCertificates(&certificates);
    54     50   
    55         -				reply = new pp::VarDictionary();
    56         -
    57     51   				certificatesPPArray.SetLength(numCertificates);
    58     52   
    59     53   				for (i = 0; i < numCertificates; i++) {
    60     54   					certificateContents = new pp::VarArrayBuffer(certificates[i].certificate_len);
    61     55   
    62     56   					memcpy(certificateContents->Map(), certificates[i].certificate, certificates[i].certificate_len);
    63     57   
    64     58   					certificateContents->Unmap();
    65     59   
    66     60   					certificatesPPArray.Set(i, *certificateContents);
           61  +
           62  +					delete certificateContents;
    67     63   				}
           64  +
           65  +				cackey_chrome_freeCertificates(certificates, numCertificates);
    68     66   
    69     67   				reply->Set("status", "success");
    70     68   				reply->Set("certificates", certificatesPPArray);
    71     69   			} else if (command.AsString() == "sign") {
    72         -				reply = new pp::VarDictionary();
           70  +				if (!message->HasKey("certificate")) {
           71  +					reply->Set("status", "error");
           72  +					reply->Set("error", "Certificate not supplied");
           73  +				} else {
           74  +					incomingCertificateContents = message->Get("certificate");
    73     75   
    74         -				reply->Set("status", "success");
           76  +					reply->Set("status", "error");
           77  +					reply->Set("error", "This function is not yet implemented");
           78  +				}
    75     79   			} else {
    76         -				reply = new pp::VarDictionary();
    77         -
    78     80   				reply->Set("status", "error");
    79     81   				reply->Set("error", "Invalid command");
    80     82   			}
    81     83   
    82     84   			/*
    83     85   			 * If a message ID was sent in the request, include it in the reply
    84     86   			 */
................................................................................
    86     88   				reply->Set("id", message->Get("id"));
    87     89   			}
    88     90   
    89     91   			/*
    90     92   			 * Send the reply back to the requestor, hopefully they are waiting for this message
    91     93   			 */
    92     94   			PostMessage(*reply);
           95  +
           96  +			delete reply;
    93     97   
    94     98   			delete message;
    95     99   
    96    100   			return;
    97    101   		}
    98    102   
    99    103   		virtual void HandleMessage(const pp::Var& messagePlain) {