static void clusterRPC_init() { int ret; /*********************************************************************** * Create plugin mutex ***********************************************************************/ node_status_mutex = INKMutexCreate(); if (!node_status_mutex) { INKDebug(PLUGIN_DEBUG_ERR_TAG, "INKMutexCreate for node_status failed\n"); return; } if (!INKMutexTryLock(node_status_mutex)) { /* Should never fail */ INKDebug(PLUGIN_DEBUG_ERR_TAG, "INKMutexTryLock failed\n"); } /*********************************************************************** * Register our RPC handler. ***********************************************************************/ ret = INKAddClusterRPCFunction(RPC_API_WIRELESS_F10, rpc_wireless_f10_func, &rpc_wireless_f10_handle); if (ret) { INKDebug(PLUGIN_DEBUG_ERR_TAG, "INKAddClusterRPCFunction failed\n"); return; } /*********************************************************************** * Subscribe to cluster node status callouts. ***********************************************************************/ ret = INKAddClusterStatusFunction(status_callout, node_status_mutex, &status_callout_handle); if (ret) { INKDebug(PLUGIN_DEBUG_ERR_TAG, "INKAddClusterStatusFunction failed\n"); return; } /*********************************************************************** * Perform node status initializations. ***********************************************************************/ INKGetMyNodeHandle(&my_node_handle); /*********************************************************************** * Enable cluster node status callouts. ***********************************************************************/ INKEnableClusterStatusCallout(&status_callout_handle); /*********************************************************************** * Establish the periodic event. ***********************************************************************/ periodic_event_cont = INKContCreate(periodic_event, node_status_mutex); if (!periodic_event_cont) { INKDebug(PLUGIN_DEBUG_ERR_TAG, "INKContCreate for periodic_event failed\n"); return; } periodic_event_action = INKContSchedule(periodic_event_cont, (1 * 1000) /* 1 sec */ ); INKMutexUnlock(node_status_mutex); }
/******************************************************************** * When the client sends the same request the second time, get the * header field MY_HDR from the caches response header, print it out * and save it in a text file. ********************************************************************/ static int handle_cache_hdr(INKHttpTxn txnp) { LOG_SET_FUNCTION_NAME("handle_cache_hdr"); INKMBuffer cache_bufp; INKMLoc cache_loc = NULL, field_loc = NULL; const char *my_hdr; int value_count, i, length; char output_file[1024], output_str[1024]; INKFile file; output_str[0] = '\0'; /* get the cached response header */ if (!INKHttpTxnCachedRespGet(txnp, &cache_bufp, &cache_loc)) LOG_ERROR_AND_RETURN("INKHttpTxnCachedRespGet"); /* get the MY_HDR field in the header */ if ((field_loc = INKMimeHdrFieldFind(cache_bufp, cache_loc, MY_HDR, strlen(MY_HDR))) == INK_ERROR_PTR || field_loc == NULL) LOG_ERROR_AND_CLEANUP("INKMimeHdrFieldFind"); if ((value_count = INKMimeHdrFieldValuesCount(cache_bufp, cache_loc, field_loc)) == INK_ERROR) LOG_ERROR_AND_CLEANUP("INKMimeHdrFieldValuesCount"); for (i = 0; i <= value_count - 1; i++) { if (INKMimeHdrFieldValueStringGet(cache_bufp, cache_loc, field_loc, i, &my_hdr, &length) == INK_ERROR) LOG_ERROR_AND_CLEANUP("INKMimeHdrFieldValueStringGet"); /* concatenate the field to output_str */ if (my_hdr) { snprintf(output_str, 1024, "%s MY_HDR(%d): %.*s \n", output_str, i, length, my_hdr); INKHandleStringRelease(cache_bufp, field_loc, my_hdr); } } snprintf(output_file, 1024, "%s/write_server_ip.txt", plugin_dir); INKDebug(DEBUG_TAG, "Writing record\n%s\nto file %s", output_str, output_file); /* append to the text file */ if (INKMutexLock(file_mutex) == INK_ERROR) LOG_ERROR_AND_CLEANUP("INKMutexLock"); if ((file = INKfopen(output_file, "w")) == NULL) LOG_ERROR_AND_CLEANUP("INKfopen"); INKfwrite(file, output_str, strlen(output_str)); INKfflush(file); INKfclose(file); if (INKMutexUnlock(file_mutex) == INK_ERROR) LOG_ERROR_AND_CLEANUP("INKMutexUnlock"); /* cleanup */ Lcleanup: /* release mlocs */ if (VALID_POINTER(field_loc)) INKHandleMLocRelease(cache_bufp, cache_loc, field_loc); if (VALID_POINTER(cache_loc)) INKHandleMLocRelease(cache_bufp, INK_NULL_MLOC, cache_loc); return 0; }