{NULL, NULL, NULL, NULL, NULL, NULL, NULL}, NULL},
};
+const int VALIDATOR_BITS = 0x12345678;
+
typedef struct {
vine_data_path_method_e method;
vine_dp_plugin_fn *plugin_fn;
established_notifier established;
vine_data_path_h listen_dp; // only for client dp in the server side
+
+ int validator;
} vine_data_path_s;
+inline bool data_path_validate(vine_data_path_s *datapath, const char *func)
+{
+ RET_VAL_IF(datapath == NULL, false, "datapath is NULL");
+ RET_VAL_IF(datapath->plugin_handle == NULL, false, "plugin_handle is NULL");
+ RET_VAL_IF((((int)datapath->plugin_handle) ^ ((int)datapath->validator)) != VALIDATOR_BITS, false,
+ "validator fails. plugin_handle[%x] validator[%x]", datapath->plugin_handle, datapath->validator);
+
+ return true;
+}
+
typedef struct {
int result;
int port;
VINE_LOGD("user callback is invoked by event queue.");
- if (listen_dp && listen_dp->accepted_cb)
+ if (data_path_validate(listen_dp, __FUNCTION__) && listen_dp->accepted_cb)
listen_dp->accepted_cb(accepted_event->connected_dp, listen_dp->accepted_cb_data);
}
vine_data_path_s *listen_dp = (vine_data_path_s *)dp->listen_dp;
VINE_LOGD("listen_dp[%p]", listen_dp);
- if (listen_dp)
+ if (data_path_validate(listen_dp, __FUNCTION__))
vine_event_loop_add_event(listen_dp->event_queue, accepted_event,
__invoke_accepted_user_cb, __free_accepted_event, listen_dp);
}
VINE_LOGD("user callback is invoked by event queue");
- if (dp && dp->opened_cb)
+ if (data_path_validate(dp, __FUNCTION__) && dp->opened_cb)
dp->opened_cb(dp, opened_event->result, opened_event->port, dp->opened_cb_data);
}
static void __opened_cb(int result, int port, void *user_data)
{
+ VINE_LOGD("__opened_cb result[%d] port[%d] datapath[%p]", result, port, user_data);
RET_IF(user_data == NULL, "dp is NULL");
vine_data_path_s *dp = (vine_data_path_s *)user_data;
+ if (!data_path_validate(dp, __FUNCTION__))
+ return;
+
vine_dp_opened_event *opened_event =
(vine_dp_opened_event *)calloc(1, sizeof(vine_dp_opened_event));
opened_event->result = result;
RET_IF(user_data == NULL, "listen_dp is NULL");
vine_data_path_s *listen_dp = (vine_data_path_s *)user_data;
+ if (!data_path_validate(listen_dp, __FUNCTION__))
+ return;
VINE_LOGI("listen_dp[%p], security[%p]", listen_dp, listen_dp->security);
vine_data_path_s *connected_dp = _vine_data_path_create(listen_dp->method,
VINE_LOGD("user callback is invoked by event queue.");
- if (dp && dp->connected_cb)
+ if (data_path_validate(dp, __FUNCTION__) && dp->connected_cb)
dp->connected_cb(dp, connected_event->result, dp->connected_cb_data);
}
connected_event->result = result;
vine_data_path_s *dp = (vine_data_path_s *)datapath;
- vine_event_loop_add_event(dp->event_queue, connected_event,
- __invoke_connected_user_cb, free, datapath);
+ if (data_path_validate(dp, __FUNCTION__))
+ vine_event_loop_add_event(dp->event_queue, connected_event,
+ __invoke_connected_user_cb, free, datapath);
}
static void __connected_cb(int result, void *user_data)
RET_IF(user_data == NULL, "dp is NULL");
vine_data_path_s *dp = (vine_data_path_s *)user_data;
+ if (!data_path_validate(dp, __FUNCTION__))
+ return;
+
if (result < 0) {
VINE_LOGE("Fail to connect");
notify_connected(dp, result);
VINE_LOGD("user callback is invoked by event queue.");
- if (dp && dp->recv_cb) {
+ if (data_path_validate(dp, __FUNCTION__) && dp->recv_cb) {
// user can read the data in recv_cb().
dp->recv_cb(dp, received_event->bytes, dp->recv_cb_data);
}
VINE_LOGD("Create a received_event[%p] datapath[%p]", received_event, datapath);
vine_data_path_s *dp = (vine_data_path_s *)datapath;
- if (dp)
+ if (data_path_validate(dp, __FUNCTION__))
vine_event_loop_add_event(dp->event_queue, received_event,
- __invoke_received_user_cb, free, datapath);
+ __invoke_received_user_cb, free, datapath);
+ else
+ free(received_event);
}
static void __received_cb(size_t bytes, void *user_data)
RET_IF(user_data == NULL, "dp is NULL");
vine_data_path_s *dp = (vine_data_path_s *)user_data;
+ if (!data_path_validate(dp, __FUNCTION__))
+ return;
+
dp->state->received_cb(bytes);
}
{
VINE_LOGD("%d bytes are written through datapath[%p].", bytes, user_data);
vine_data_path_s *dp = (vine_data_path_s *)user_data;
+ if (!data_path_validate(dp, __FUNCTION__))
+ return;
+
dp->state->written_cb(bytes);
}
VINE_LOGD("user callback is invoked by event queue.");
+ if (!data_path_validate(dp, __FUNCTION__))
+ return;
+
start_default_state(dp, dp->plugin_handle, *dp->plugin_fn, dp->state);
if (dp->terminated_cb)
dp->terminated_cb(dp, dp->terminated_cb_data);
static void __terminated_cb(void *user_data)
{
vine_data_path_s *dp = (vine_data_path_s *)user_data;
- if (dp)
+ if (data_path_validate(dp, __FUNCTION__))
vine_event_loop_add_event(dp->event_queue, NULL,
__invoke_terminated_user_cb, NULL, user_data);
}
RET_VAL_IF(!dp->plugin_fn || !dp->plugin_fn->close,
VINE_ERROR_INVALID_PARAMETER, "plugin_fn is NULL");
+ //start_default_state(dp, dp->plugin_handle, *dp->plugin_fn, dp->state);
+
// Unset callbacks related with vine_dp_open() before closing to avoid timing issue.
dp->opened_cb = NULL;
+ dp->accepted_cb = NULL;
dp->connected_cb = NULL;
+ dp->recv_cb = NULL;
+ dp->terminated_cb = NULL;
dp->plugin_fn->close(dp->plugin_handle);
return VINE_ERROR_NONE;
}
dp->state = vine_get_default_state(dp, dp->plugin_handle, *dp->plugin_fn);
- VINE_LOGD("datapath[%p] is created. method[%d]", dp, method);
+ dp->validator = (((int)dp->plugin_handle) ^ VALIDATOR_BITS);
+ VINE_LOGD("datapath[%p] is created. method[%d] validator[%x] plugin_handle[%p]",
+ dp, method, dp->validator, dp->plugin_handle);
return dp;
}
RET_VAL_IF(datapath == NULL, VINE_ERROR_INVALID_PARAMETER, "datapath is NULL");
vine_data_path_s *dp = (vine_data_path_s *)datapath;
+ start_default_state(dp, dp->plugin_handle, *dp->plugin_fn, dp->state);
+
if (dp->plugin_fn && dp->plugin_fn->destroy)
dp->plugin_fn->destroy(dp->plugin_handle);
dp->connected_cb = NULL;
dp->recv_cb = NULL;
dp->terminated_cb = NULL;
+ dp->validator = 0;
VINE_LOGD("data_path[%p] is destroyed", datapath);
free(datapath);
RET_IF(datapath == NULL, "datapath is NULL");
vine_data_path_s *dp = (vine_data_path_s *)datapath;
+ if (!data_path_validate(dp, __FUNCTION__))
+ return;
+
dp->established(dp, result);
}