- struct GNUNET_PSYCSTORE_OperationHandle *op;
- const struct OperationResult *opres;
- const struct CountersResult *cres;
- const struct FragmentResult *fres;
- const struct StateResult *sres;
- const char *str;
-
- if (NULL == msg)
- {
- reschedule_connect (h);
- return;
- }
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Received message of type %d from PSYCstore service.\n",
- ntohs (msg->type));
- uint16_t size = ntohs (msg->size);
- uint16_t type = ntohs (msg->type);
- switch (type)
- {
- case GNUNET_MESSAGE_TYPE_PSYCSTORE_RESULT_CODE:
- if (size < sizeof (struct OperationResult))
- {
- LOG (GNUNET_ERROR_TYPE_ERROR,
- "Received message of type %d with length %lu bytes. "
- "Expected >= %lu\n",
- type, size, sizeof (struct OperationResult));
- GNUNET_break (0);
- reschedule_connect (h);
- return;
- }
-
- opres = (const struct OperationResult *) msg;
- str = (const char *) &opres[1];
- if ( (size > sizeof (struct OperationResult)) &&
- ('\0' != str[size - sizeof (struct OperationResult) - 1]) )
- {
- GNUNET_break (0);
- reschedule_connect (h);
- return;
- }
- if (size == sizeof (struct OperationResult))
- str = NULL;
-
- op = find_op_by_id (h, ntohl (opres->op_id));
- if (NULL == op)
- {
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "No callback registered for operation with ID %ld.\n",
- type, ntohl (opres->op_id));
- }
- else
- {
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Received result message (type %d) with operation ID: %ld\n",
- type, op->op_id);
-
- GNUNET_CONTAINER_DLL_remove (h->op_head, h->op_tail, op);
- if (NULL != op->res_cb)
- {
- const struct StateModifyRequest *smreq;
- const struct StateSyncRequest *ssreq;
- switch (ntohs (op->msg->type))
- {
- case GNUNET_MESSAGE_TYPE_PSYCSTORE_STATE_MODIFY:
- smreq = (const struct StateModifyRequest *) op->msg;
- if (!(smreq->flags & STATE_OP_LAST
- || GNUNET_OK != ntohl (opres->result_code)))
- op->res_cb = NULL;
- break;
- case GNUNET_MESSAGE_TYPE_PSYCSTORE_STATE_SYNC:
- ssreq = (const struct StateSyncRequest *) op->msg;
- if (!(ssreq->flags & STATE_OP_LAST
- || GNUNET_OK != ntohl (opres->result_code)))
- op->res_cb = NULL;
- break;
- }
- }
- if (NULL != op->res_cb)
- op->res_cb (op->cls, ntohl (opres->result_code), str);
- GNUNET_free (op);
- }
- break;
-
- case GNUNET_MESSAGE_TYPE_PSYCSTORE_RESULT_COUNTERS:
- if (size != sizeof (struct CountersResult))
- {
- LOG (GNUNET_ERROR_TYPE_ERROR,
- "Received message of type %d with length %lu bytes. "
- "Expected %lu\n",
- type, size, sizeof (struct CountersResult));
- GNUNET_break (0);
- reschedule_connect (h);
- return;
- }
-
- cres = (const struct CountersResult *) msg;