static void differenceVectorDelete(ClDifferenceBlockT *block) { hashDel(&block->hash); if(block->data) clHeapFree(block->data); clDifferenceVectorKeyFree(&block->key); if(block->md5List) clHeapFree(block->md5List); clHeapFree(block); }
static ClRcT delNotifyMap(ClInt32T watchFd, ClInt32T port) { ClTransportNotifyMapT *notify; if( (notify = findNotifyMap(watchFd, port) ) ) { hashDel(¬ify->hash); clHeapFree(notify); return CL_OK; } return CL_ERR_NOT_EXIST; }
ClRcT clAmsMgmtOIDelete(ClCorInstanceIdT instance, ClAmsEntityT *entity) { ClAmsMgmtOICacheT *entry = NULL; if(!entity || entity->type > CL_AMS_ENTITY_TYPE_MAX) return CL_AMS_RC(CL_ERR_INVALID_PARAMETER); clOsalMutexLock(&gClAmsMgmtOICacheMutex); if(!(entry = clAmsMgmtOICacheFind(gClAmsMgmtOICacheTable[entity->type], instance, entity))) { clOsalMutexUnlock(&gClAmsMgmtOICacheMutex); return CL_AMS_RC(CL_ERR_NOT_EXIST); } hashDel(&entry->hash); clOsalMutexUnlock(&gClAmsMgmtOICacheMutex); clHeapFree(entry); return CL_OK; }
ClRcT clAmsMgmtOIExtendedDelete(ClAmsMgmtOIExtendedClassTypeT type, ClCorInstanceIdT instance) { ClAmsMgmtOIExtendedCacheT *entry = NULL; if(type >= CL_AMS_MGMT_OI_EXTENDED_CLASS_MAX) return CL_AMS_RC(CL_ERR_INVALID_PARAMETER); clOsalMutexLock(&gClAmsMgmtOICacheMutex); if(!(entry = clAmsMgmtOIExtendedCacheFind(gClAmsMgmtOIExtendedCacheTable[type], instance))) { clOsalMutexUnlock(&gClAmsMgmtOICacheMutex); return CL_AMS_RC(CL_ERR_NOT_EXIST); } hashDel(&entry->hash); clOsalMutexUnlock(&gClAmsMgmtOICacheMutex); if(entry->pConfig) clHeapFree(entry->pConfig); clHeapFree(entry); return CL_OK; }
void handleQuery(char *commandName, unsigned int key, unsigned int value, unsigned long responseAddress, unsigned int responsePort) { //, struct hashnode *table if(isSetQuery(commandName)) { // -- process set cmd if(hashSet(table, key, value) == -1){ strcpy(commandName, "err"); // key = value = 0; }else{ strcpy(commandName, "ok!"); } } else if(isGetQuery(commandName)) { // -- process get cmd int val = hashGet(table, key); if(val == -1){ strcpy(commandName, "nof"); // key = value = 0; }else{ strcpy(commandName, "val"); value = val; } } else if(isDelQuery(commandName)) { // -- process del cmd if(hashDel(table, key) == -1){ strcpy(commandName, "nof"); // key = value = 0; }else{ strcpy(commandName, "ok!"); } } else { strcpy(commandName, "err"); // key = value = 0; } printf("Table modification complete.\n"); forwardQuery(commandName, key, value, responseAddress, responsePort); return; }
/** * A client has requested the given url using the given method * (#MHD_HTTP_METHOD_GET, #MHD_HTTP_METHOD_PUT, * #MHD_HTTP_METHOD_DELETE, #MHD_HTTP_METHOD_POST, etc). The callback * must call MHD callbacks to provide content to give back to the * client and return an HTTP status code (i.e. #MHD_HTTP_OK, * #MHD_HTTP_NOT_FOUND, etc.). * * @param cls argument given together with the function * pointer when the handler was registered with MHD * @param url the requested url * @param method the HTTP method used (#MHD_HTTP_METHOD_GET, * #MHD_HTTP_METHOD_PUT, etc.) * @param version the HTTP version string (i.e. * #MHD_HTTP_VERSION_1_1) * @param upload_data the data being uploaded (excluding HEADERS, * for a POST that fits into memory and that is encoded * with a supported encoding, the POST data will NOT be * given in upload_data and is instead available as * part of #MHD_get_connection_values; very large POST * data *will* be made available incrementally in * @a upload_data) * @param upload_data_size set initially to the size of the * @a upload_data provided; the method must update this * value to the number of bytes NOT processed; * @param con_cls pointer that the callback can set to some * address and that will be preserved by MHD for future * calls for this request; since the access handler may * be called many times (i.e., for a PUT/POST operation * with plenty of upload data) this allows the application * to easily associate some request-specific state. * If necessary, this state can be cleaned up in the * global #MHD_RequestCompletedCallback (which * can be set with the #MHD_OPTION_NOTIFY_COMPLETED). * Initially, `*con_cls` will be NULL. * @return #MHD_YES if the connection was handled successfully, * #MHD_NO if the socket must be closed due to a serios * error while handling the request */ static int answer_to_connection(void *cls, struct MHD_Connection *connection, const char *url, const char *method, const char *version, const char *upload_data, size_t * upload_data_size, void **con_cls) { if (*con_cls == NULL) { printf("CON_CLS is NULL. Request-type: %s\n", method); struct connection_info_struct *con_info; con_info = malloc(sizeof(struct connection_info_struct)); if (con_info == NULL) { return MHD_NO; } con_info->answerstring = NULL; if (strcmp(method, "POST") == 0) { con_info->postprocessor = MHD_create_post_processor(connection, POSTBUFFERSIZE, iterate_post, (void *) con_info); if (con_info->postprocessor == NULL) { free(con_info); return MHD_NO; } con_info->connectiontype = POST; } else if (strcmp(method, "DELETE") == 0) { con_info->connectiontype = DELETE; } else { con_info->connectiontype = GET; } *con_cls = (void *) con_info; return MHD_YES; } printf("CON_CLS is NOT NULL.\n"); if (0 == strcmp(method, "GET")) { char modifiableUrl [strlen(url) + 1]; strncpy(modifiableUrl, url, sizeof modifiableUrl); modifiableUrl[strlen(url)] = '\0'; char * argument = strtok(modifiableUrl, "/"); // remove api name argument = strtok(NULL, "/"); int parsedArgument = atoi(argument); int responseValue = hashGet(parsedArgument); if (responseValue >= 0) { char buffer[100]; // totally arbitrary but pretty big sprintf(buffer, "200 - OK\nValue: %d\n", responseValue); return send_page(connection, MHD_HTTP_OK, buffer); } else if (responseValue == NOT_FOUND) { return send_page(connection, 404, "404 - Not found\nThere are no entries matching your key.\n"); } else { return send_page(connection, 500, "500 - Internal server error\n"); } } if (0 == strcmp(method, "DELETE")) { printf("DELETE REQUEST to %s >>>\n", url); char modifiableUrl [strlen(url) + 1]; strncpy(modifiableUrl, url, sizeof modifiableUrl); modifiableUrl[strlen(url)] = '\0'; char * argument = strtok(modifiableUrl, "/"); // remove api name argument = strtok(NULL, "/"); int parsedArgument = atoi(argument); printf("Parsed as %d from %s\n", parsedArgument, argument); int responseValue = hashDel(parsedArgument); printf("Result: %d\n", responseValue); if (responseValue >= 0) { return send_page(connection, 200, "200 - OK\n"); } else if (responseValue == NOT_FOUND) { return send_page(connection, 404, "404 - Not found\nThere are no entries matching your key.\n"); } else { return send_page(connection, 500, "500 - Internal server error\n"); } } if (0 == strcmp(method, "POST")) { struct connection_info_struct *con_info = *con_cls; if (*upload_data_size != 0) { MHD_post_process(con_info->postprocessor, upload_data, *upload_data_size); *upload_data_size = 0; return MHD_YES; } else if (keySet && valueSet) { keySet = 0; valueSet = 0; printf("Set %d:%d!\n", key, value); if (hashSet(key, value)) { const char *responseText = "201 - Created\n"; struct MHD_Response *response = MHD_create_response_from_buffer(strlen(responseText), (void*) responseText, MHD_RESPMEM_PERSISTENT); char buffer[100]; // totally arbitrary but pretty big sprintf(buffer, "http://localhost:%d%s/%d", port, url, key); MHD_add_response_header (response, "Location", buffer); int ret = MHD_queue_response (connection, 201, response); MHD_destroy_response(response); return MHD_YES; } else { return send_page(connection, 500, "500 - Internal server error\n"); } } else { return send_page(connection, MHD_HTTP_BAD_REQUEST, "400 - Malformed request\n"); } } return send_page(connection, MHD_HTTP_NOT_FOUND, "404 - Not found\n"); }
void filereader(FILE* in, int bflag, char* sym, int n){ FILE* iq = fopen("iq.txt", "w"); FILE* ob = fopen("ob.txt", "w"); int count = 0; if(!bflag){ char ch; int id; while(!feof(in)){ fscanf(in,"%c",&ch); if(ch == 'A'){ char side; char* symbol = (char*)malloc(sizeof(char*)); int quantity; double price; fscanf(in,"%d %c %s %d %lf\n",&id, &side, symbol, &quantity, &price); if(!strcmp(sym,symbol)){ hashAdd(id, side, symbol, quantity, price); //printf("%ld %c %s %d %lf\n", id, side, symbol, quantity, price); //count++; } }else if(ch == 'X'){ char* symbol = (char*)malloc(sizeof(char*)); fscanf(in,"%d %s\n",&id, symbol); hashDel(id); }else if(ch == 'T'){ int id; char* symbol = (char*)malloc(sizeof(char*)); int quantity; fscanf(in, "%d %s %d\n", &id, symbol, & quantity); if(!strcmp(sym,symbol)){ changeNode(id, quantity); } }else if(ch == 'R'){ int id; char* symbol = (char*)malloc(sizeof(char*)); int quantity; double price; fscanf(in, "%d %s %d %lf\n", &id, symbol, &quantity, &price); changePnode(id, quantity, price); }else if(ch == 'C'){ int id; char* symbol = (char*)malloc(sizeof(char*)); int quantity; fscanf(in, "%d %s %d\n", &id, symbol, & quantity); if(!strcmp(sym,symbol)){ changeNode(id, quantity); } } count++; //printf("count %d\n", count); //printf("n in file %d\n", n); if(count == n){ count = 0; double sellPrice = 0.0; double buyPrice = 0.0; if(sell != NULL) sellPrice = sell->price; if(buy != NULL) buyPrice = buy->price; fprintf(iq, "%lf %lf\n", sellPrice, buyPrice); } } }else{ char c; while(!feof(in)){ fread(&c, sizeof(char), 1,in); if(c == 'A'){ int id; char side; char *symbol = (char *) malloc(sizeof(char *)); int quantity; double price; fread(&id,sizeof(int),1,in); fread(&side,sizeof(char),1,in); fread(symbol,sizeof(char),4,in); symbol[strlen(symbol)] = '\0'; fread(&quantity,sizeof(int),1,in); fread(&price,sizeof(double),1,in); if(!strcmp(sym,symbol)){ hashAdd(id, side, symbol, quantity, price); //printf("%ld %c %s %d %lf\n", id, side, symbol, quantity, price); } } if(c == 'X'){ int id; char *symbol = (char *) malloc(sizeof(char *)); fread(&id,sizeof(int),1,in); fread(symbol,sizeof(char),4,in); symbol[strlen(symbol)] = '\0'; hashDel(id); } if(c == 'T'){ int id; char *symbol = (char *) malloc(sizeof(char *)); int quantity; fread(&id,sizeof(int),1,in); fread(symbol,sizeof(char),4,in); symbol[strlen(symbol)] = '\0'; fread(&quantity,sizeof(int),1,in); changeNode(id, quantity); } if(c == 'C'){ int id; char *symbol = (char *) malloc(sizeof(char *)); int quantity; fread(&id,sizeof(int),1,in); fread(symbol,sizeof(char),4,in); symbol[strlen(symbol)] = '\0'; fread(&quantity,sizeof(int),1,in); changeNode(id,quantity); } if(c == 'R'){ int id; char *symbol = (char *) malloc(sizeof(char *)); int quantity; double price; fread(&id,sizeof(int),1,in); fread(symbol,sizeof(char),4,in); symbol[strlen(symbol)] = '\0'; fread(&quantity,sizeof(int),1,in); fread(&price,sizeof(double),1,in); changePnode(id, quantity, price); } } } printhash(ob); }