Ejemplo n.º 1
0
int truncate_intervals(TTBIN_FILE *ttbin)
{
    TTBIN_RECORD *record, *end;
    /* if we have no intervals, we can't truncate the file */
    if (!ttbin->interval_finish_records.count)
        return 0;

    /* find the position record AFTER the final interval finish record */
    end = ttbin->interval_finish_records.records[ttbin->interval_finish_records.count - 1];
    while (end->next)
    {
        end = end->next;
        if ((end->tag == TAG_GPS) || (end->tag == TAG_SWIM) || (end->tag = TAG_TREADMILL))
            break;
    }

    /* delete everything after this point */
    record = ttbin->last;
    while (record != end)
    {
        TTBIN_RECORD *r = record->prev;
        delete_record(ttbin, record);
        record = r;
    }

    update_summary_information(ttbin);

    return 1;
}
Ejemplo n.º 2
0
void domailclean(struct fileheader* fhdrp)
{
    static int newcnt, savecnt, deleted, idc;
    char    buf[STRLEN];
    if (fhdrp == NULL)
    {
        fprintf(cleanlog, "new = %d, saved = %d, deleted = %d\n",
                newcnt, savecnt, deleted);
        newcnt = savecnt = deleted = idc = 0;
        if (delcnt)
        {
            sprintf(buf, "mail/%c/%s/%s", toupper(curruser[0]), curruser, DOT_DIR);
            while (delcnt--)
                delete_record(buf, sizeof(struct fileheader), delmsgs[delcnt]);
        }
        delcnt = 0;
        return;
    }
    idc++;
    if (!(fhdrp->accessed[0] & FILE_READ))
        newcnt++;
    else if (fhdrp->accessed[0] & FILE_MARKED)
        savecnt++;
    else
    {
        deleted++;
        sprintf(buf, "mail/%c/%s/%s", toupper(curruser[0]), curruser, fhdrp->filename);
        unlink(buf);
        delmsgs[delcnt++] = idc;
    }
}
Ejemplo n.º 3
0
Archivo: q2.c Proyecto: eokeeffe/C-code
void options()//give some options for the DB
{
	clear_screen();
	char dummy;
	int answer;
	
	printf("Welcome to Employee database V1.0\r\n");
	printf("Please enter a number\r\n");
	printf("1.read database by a sorted pattern\r\n");
	printf("2.search for a person in the database\r\n");
	printf("3.change a persons information in the database\r\n");
	printf("4.add a person to the database\r\n");
	printf("5.delete name from the database\r\n");
	printf("6.quit the program\r\n");
	scanf("%d",&answer);
	dummy=getchar();
	switch(answer)
	{
		case 1:{sort_file_ini();break;}
		case 2:{search_file_ini();break;}
		case 3:{change_record();break;}
		case 4:{add_to_record();break;}
		case 5:{delete_record();break;}
		case 6:{end_all();break;}
		case 7:{info();break;}
		default:{options();break;}
	}
	
}
Ejemplo n.º 4
0
void entry_menu()
{
  int ch,num;
  clrscr();
  cout<<"\n\n\n\t\tENTRY MENU";
  cout<<"\n\n\t1.CREATE STUDENT RECORD";
  cout<<"\n\n\t2.DISPLAY ALL STUDENTS RECORD";
  cout<<"\n\n\t3.SEARCH STUDENT RECORD";
  cout<<"\n\n\t4.MODIFY STUDENT RECORD ";
  cout<<"\n\n\t5.DELETE STUDENT RECORD ";
  cout<<"\n\n\t6.RETURN TO MAIN MENU";
  cout<<"\n\nPlease Enter Your Choice(1-6).......";
  cin>>ch;
  clrscr();
  switch(ch)
  {
	  case 1:write_record();break;
	  case 2:read_record();break;
	  case 3:cout<<"\n\n\tPlease enter the roll no. of student ";
		 cin>>num;
		 display(num);
		 break;
	  case 4:cout<<"\n\n\tPlease enter the roll no. of student ";
		 cin>>num;
		 modify_record(num);
		 break;
	  case 5:cout<<"\n\n\tPlease enter the roll no. of student ";
		 cin>>num;
	    delete_record(num);
		 break;
     case 6:break;
     default : cout<<"\a";entry_menu();
  }
}
Ejemplo n.º 5
0
/******************************************************
 Search/Insert/Delete
 based on input flag determines whether to go to the search insert or delete function
 */
void searchOrInsert(FILE *fp, int insertflag, FILE **fpInput)
{
    
    char line[100];
    long address;
    char *lastname;
    char *firstname;
    int id;
    char * idstring;
    double amount=0.0;
    char *amtstring;
    char *end;
    
    if (insertflag==2)
        printf("\nDELETE\n");
    else if (insertflag==1)
        printf("\nINSERT\n");
    else
        printf("\nSEARCH\n");

    while(printf("Enter student id, last name, first name, and amount or quit to stop: "), fgets(line, sizeof(line), stdin), strcmp(line, "quit\n") != 0)
    {
        idstring = strtok(line, "\040\t");
        id=atoi(idstring);
        lastname=strtok(NULL, "\040\t");
        firstname=strtok(NULL, "\040\t");
        amtstring=strtok(NULL, "\n");
        if (amtstring)
        {
            amount=strtod(amtstring, &end);
            if (*end == '\0')
                printf("\n");
            else
                printf("Not a number: it contains %c!\n", *end);
        }
        
        isValid(lastname, firstname, id, amount);
        printf("%d %s %s %.2f\n", id, lastname, firstname, amount);
        
        address = hash(idstring, 100);
        if (insertflag==2)
        {
            delete_record(lastname, firstname, id, amount, address, fp);
        }
        else if (insertflag==1)
        {
            insert_record(lastname, firstname, id, amount, address, fp);
        }
        else
        {
            search_record(lastname, firstname, id, amount, address, fp);
        }
    }
    return;
}
Ejemplo n.º 6
0
void food :: delete_item(void)
{
	clrscr() ;
	char t_code[5], ch ;
	int t, tcode ;
	gotoxy(3,25) ;
	cout <<"Press <ENTER> to see the list" ;
	gotoxy(5,3) ;
	cout <<"Enter Item Code of the item to be deleted : " ;
	gets(t_code) ;
	t = atoi(t_code) ;
	tcode = t ;
	if (t_code[0] == '0')
		return ;
	if (tcode == 0)
	{
		list_of_item() ;
		gotoxy(1,25) ; clreol() ;
		gotoxy(3,25) ;
		cout <<"Press <ENTER> to Exit" ;
		gotoxy(5,24) ;
		cout <<"Enter Item Code of the item to be deleted : " ;
		gets(t_code) ;
		t = atoi(t_code) ;
		tcode = t ;
		if (tcode == 0)
			return ;
	}
	clrscr() ;
	if (!item_found(tcode))
	{
		gotoxy(5,5) ;
		cout <<"\7Record not found" ;
		getch() ;
		return ;
	}
	display_record(tcode) ;
	do
	{
		gotoxy(1,8) ; clreol() ;
		gotoxy(5,8) ;
		cout <<"Do you want to delete this record (y/n) : " ;
		ch = getche() ;
		ch = toupper(ch) ;
	} while (ch != 'N' && ch != 'Y') ;
	if (ch == 'N')
		return ;
	delete_record(tcode) ;
	gotoxy(5,15) ;
	cout <<"\7Record Deleted" ;
	getch() ;
}
Ejemplo n.º 7
0
Archivo: db.c Proyecto: SanketDG/db_c
int main(int argc, char *argv[])
{

    int fd;
    person_record rec;

    /* fd = open_record("data1"); */

    if(argc > 1)
    {
        // insert data

        if(argc > 5 && !strcmp(argv[1], "insert"))
        {
            fd = update_record("data1", 1);
            rec.key = atoi(argv[2]);
            strcpy(rec.fname, argv[3]);
            strcpy(rec.lname, argv[4]);
            rec.age = atoi(argv[5]);

            insert_record(fd, &rec);
        }

        /* delete data */

        if(argc > 2 && !strcmp(argv[1], "delete"))
        {
            fd = update_record("data1", 0);
            delete_record(fd, atoi(argv[2]));
        }

        /* print data */

        if(argc > 2 && !strcmp(argv[1], "print"))
        {
            fd = update_record("data1", 1);

            get_record(fd, &rec, atoi(argv[2]));

            printf("key = %d\n", rec.key);
            printf("First = %s\n", rec.fname);
            printf("Last = %s\n", rec.lname);
            printf("Age = %d\n", rec.age);
        }
    }

    close_record(fd);
    return 0;
}
Ejemplo n.º 8
0
void replace_lap_list(TTBIN_FILE *ttbin, float *distances, unsigned count)
{
    float end_of_lap = 0;
    float last_distance = 0;
    uint32_t i;
    unsigned d = 0;

    /* remove the current lap records */
    if (ttbin->lap_records.count)
    {
        for (i = 0; i < ttbin->lap_records.count; ++i)
            delete_record(ttbin, ttbin->lap_records.records[i]);
        free(ttbin->lap_records.records);
        ttbin->lap_records.records = 0;
        ttbin->lap_records.count   = 0;
    }

    /* do the check here, so that we can just remove all the laps if we want to */
    if (!distances || (count == 0))
        return;

    end_of_lap = distances[d];
    for (i = 0; i < ttbin->gps_records.count; ++i)
    {
        TTBIN_RECORD *lap_record;
        /* skip records until we reach the desired lap distance */
        if (ttbin->gps_records.records[i]->gps.cum_distance < end_of_lap)
            continue;

        /* right, so we need to add a lap marker here */
        lap_record = insert_before(ttbin, ttbin->gps_records.records[i]);
        lap_record->tag = TAG_LAP;
        lap_record->length = 10;
        lap_record->lap.total_time = i;
        lap_record->lap.total_distance = ttbin->gps_records.records[i]->gps.cum_distance;
        lap_record->lap.total_calories = ttbin->gps_records.records[i]->gps.calories;
        append_array(&ttbin->lap_records, lap_record);

        /* get the next lap distance */
        if (++d >= count)
        {
            d = 0;
            last_distance = end_of_lap;
        }

        end_of_lap = last_distance + distances[d];
    }
}
Ejemplo n.º 9
0
int main(int argc, char ** argv)
{
    if ( argc != 2 ) {
        fprintf(stderr, "Usage: pricelist FILENAME\n");
        return EXIT_FAILURE;
    }

    const int dbfd = x_open(argv[1], O_RDWR | O_CREAT, 0644);

    bool should_quit = false;

    while ( !should_quit ) {
        print_summary(dbfd, argv[1]);
        int choice = get_menu_choice();

        struct record record;

        switch ( choice ) {
            case MENU_LIST:
                list_records(dbfd);
                break;

            case MENU_ADD:
                get_new_record(&record);
                write_record(dbfd, &record, -1);
                break;

            case MENU_DELETE:
                printf("Enter record number to delete: ");
                fflush(stdout);
                delete_record(dbfd, get_integer());
                break;

            case MENU_QUIT:
                printf("Goodbye!\n");
                should_quit = true;
                break;

            default:
                printf("Invalid menu choice. Try again.\n\n");
                break;
        }
    }

    x_close(dbfd);

    return 0;
}
Ejemplo n.º 10
0
int clear_table(ALLOC * a, table_t * t)
{
    handle_t h;
    record_t *r;
    int ret;

    for (h = t->head; h != 0;) {
        if ((r = read_record(a, t, h)) == NULL)
            return -1;
        h = r->next;
        ret = delete_record(a, t, r->self);
        preserve_errno(_free_record(r));
        if (ret < 0)
            return -1;
    }
    return 0;
}
Ejemplo n.º 11
0
int main (void)
{
	int i, j;
	int t = clock();
	int array[20000];
	hash_s *hash = DEFAULT_HASH();
	for (i = 0, j = 0; i < 20000; i++, j++)
	{
		array[j] = i;
		add_record (hash, (key_u)array[j]);
	}	
	for (i = 0; i < 1993; i++)
		if (delete_record (hash, (key_u)array[i]) < 0)
			printf("hello son\n");	
	print_hash (hash);
	printf("Last:%d\n",array[19999]);
	printf("%d,%d\n",hash->size, hash->collisions);
	dealloc_hash (hash);
	printf("total time: %d\n",(int)clock()-t);
}
Ejemplo n.º 12
0
int truncate_goal(TTBIN_FILE *ttbin)
{
    TTBIN_RECORD *record, *end;
    int i;
    /* if we have no race, we can't truncate the file */
    if (!ttbin->goal_progress_records.count)
        return 0;

    /* don't truncate anything if we didn't reach the goal */
    i = ttbin->goal_progress_records.count - 1;
    end = ttbin->goal_progress_records.records[i];
    if (end->goal_progress.percent < 100)
        return 0;

    /* find the 100% record (there may be others after it) */
    while (ttbin->goal_progress_records.records[i]->goal_progress.percent > 100)
        i--;
    end = ttbin->goal_progress_records.records[i];

    /* find the position record AFTER the 100% goal record */
    while (end->next)
    {
        end = end->next;
        if ((end->tag == TAG_GPS) || (end->tag == TAG_SWIM) || (end->tag = TAG_TREADMILL))
            break;
    }

    /* delete everything after this point */
    record = ttbin->last;
    while (record != end)
    {
        TTBIN_RECORD *r = record->prev;
        delete_record(ttbin, record);
        record = r;
    }

    update_summary_information(ttbin);

    return 1;
}
Ejemplo n.º 13
0
Archivo: chat.c Proyecto: wyat/kbs
void call_listen(chatcontext * pthis, const char *arg)
{                               /* added by Luzi 1997.11.28 */
    char path[40];
    char uident[IDLEN + 1];
    char ignoreuser[IDLEN + 1];
    int nIdx;

    if (!*arg) {
        printchatline(pthis, "*** 请输入用户的ID ***");
    } else if (!strcasecmp(arg, getCurrentUser()->userid))
        printchatline(pthis, "*** 这是你自己的ID ***");
    else {
        strncpy(uident, arg, IDLEN + 1);
        uident[IDLEN] = 0;
        if (!searchuser(uident))
            /* change getuser -> searchuser, by dong, 1999.10.26 */
            printchatline(pthis, "*** 没有这个ID ***");
        else {
            sethomefile(path, getCurrentUser()->userid, "/ignores");
            nIdx =
                search_record(path, ignoreuser, IDLEN + 1,
                              (RECORD_FUNC_ARG) cmpinames, uident);
            if (nIdx <= 0)
                printchatline(pthis,
                              "*** 该用户的聊天讯息没有被忽略啊 ***");
            else if (delete_record(path, IDLEN + 1, nIdx, NULL, NULL) == 0) {
                bbslog("user", "listen %s", uident);
                printchatline(pthis,
                              "*** 已恢复对该用户聊天讯息的接收 ***");
                sprintf(uident, "/listen %s\n", uident);
                chat_send(pthis, uident);
            } else {
                bbslog("3error", "listen %s failed", uident);
                printchatline(pthis, "*** system error ***");
            }
        }
    }
}
Ejemplo n.º 14
0
/**
 * @brief Recovery system based on log file
 */
void WriteBehindFrontendLogger::DoRecovery() {
  // Set log file size
  log_file_size = GetLogFileSize(log_file_fd);

  // Go over the log size if needed
  if (log_file_size > 0) {
    bool reached_end_of_file = false;

    // check whether first item is LOGRECORD_TYPE_TRANSACTION_COMMIT
    // if not, no need to do recovery.
    // if yes, need to replay all log records before we hit
    // LOGRECORD_TYPE_TRANSACTION_DONE
    bool need_recovery = NeedRecovery();
    if (need_recovery == true) {
      TransactionRecord dummy_transaction_record(LOGRECORD_TYPE_INVALID);
      cid_t current_commit_id = INVALID_CID;

      // Go over each log record in the log file
      while (reached_end_of_file == false) {
        // Read the first byte to identify log record type
        // If that is not possible, then wrap up recovery
        LogRecordType log_type = GetNextLogRecordType(log_file, log_file_size);

        switch (log_type) {
          case LOGRECORD_TYPE_TRANSACTION_DONE:
          case LOGRECORD_TYPE_TRANSACTION_COMMIT: {
            // read but do nothing
            ReadTransactionRecordHeader(dummy_transaction_record, log_file,
                                        log_file_size);
          } break;

          case LOGRECORD_TYPE_WBL_TUPLE_INSERT: {
            TupleRecord insert_record(LOGRECORD_TYPE_WBL_TUPLE_INSERT);
            ReadTupleRecordHeader(insert_record, log_file, log_file_size);

            auto insert_location = insert_record.GetInsertLocation();
            auto info = SetInsertCommitMark(insert_location);
            current_commit_id = info.first;
          } break;

          case LOGRECORD_TYPE_WBL_TUPLE_DELETE: {
            TupleRecord delete_record(LOGRECORD_TYPE_WBL_TUPLE_DELETE);
            ReadTupleRecordHeader(delete_record, log_file, log_file_size);

            auto delete_location = delete_record.GetDeleteLocation();
            auto info = SetDeleteCommitMark(delete_location);
            current_commit_id = info.first;
          } break;

          case LOGRECORD_TYPE_WBL_TUPLE_UPDATE: {
            TupleRecord update_record(LOGRECORD_TYPE_WBL_TUPLE_UPDATE);
            ReadTupleRecordHeader(update_record, log_file, log_file_size);

            auto delete_location = update_record.GetDeleteLocation();
            SetDeleteCommitMark(delete_location);

            auto insert_location = update_record.GetInsertLocation();
            auto info = SetInsertCommitMark(insert_location);
            current_commit_id = info.first;
          } break;

          default:
            reached_end_of_file = true;
            break;
        }
      }

      // Update latest commit id
      if (latest_commit_id < current_commit_id) {
        latest_commit_id = current_commit_id;
      }

      // write out a trasaction done log record to file
      // to avoid redo next time during recovery
      WriteTransactionLogRecord(
          TransactionRecord(LOGRECORD_TYPE_TRANSACTION_DONE));
    }

    // After finishing recovery, set the next oid with maximum oid
    // observed during the recovery
    auto &manager = catalog::Manager::GetInstance();
    manager.SetNextOid(max_oid);
  }
}
Ejemplo n.º 15
0
int main( void )
{
    int i;
    
    /* holds both command characters */
    char command[ 2 ];
    
    /* set up the three libraries */
    struct Ordered_container* lib_title = OC_create_container( comp_Record_by_title );
    struct Ordered_container* lib_ID    = OC_create_container( comp_Record_by_ID );
    struct Ordered_container* catalog   = OC_create_container( comp_Collection_by_name );
    
    for ( ; ; )
    {
        printf( "\nEnter command: " );
        
        /* load the command chars */
        for ( i = 0 ; i < 2; ++i)
        {
            command[ i ] = get_command_char();
        }
        
        switch ( command[ 0 ] )
        {
            case 'f' :/* find (records only)*/
                switch ( command[ 1 ] )
                {
                    case 'r' :
                        find_record_print( lib_title );
                        break;
                    default:
                        print_error_clear( "Unrecognized command!\n");
                        break;
                }
                break;
            case 'p' : /* print */
                switch ( command[ 1 ] )
                {
                    case 'r' :
                        print_record( lib_ID );
                        break;
                    case 'L':
                        print_containter( lib_title, "Library", "records", (void (*)(void*))print_Record );
                        break;
                    case 'C':
                        /* print_catalog( catalog ); */
                        print_containter( catalog, "Catalog", "collections", (void (*)(void*))print_Collection );
                        break;
                    case 'a': /* allocation */
                        print_allocation( lib_title, lib_ID, catalog );
                        break;
                    case 'c':
                        print_collection_main( catalog );
                        break;
                    default:
                        print_error_clear( "Unrecognized command!\n");
                        break;
                }
                break;
            case 'm': /* modify (rating only) */
                switch ( command[ 1 ] )
                {
                    case 'r':
                        modify_rating( lib_ID );
                        break;
                    default:
                        print_error_clear( "Unrecognized command!\n");
                        break;
                }
                break;
            case 'a' : /* add */
                switch ( command[ 1 ] )
                {
                    case 'r' :
                        add_record( lib_title, lib_ID );
                        break;
                    case 'c':
                        add_coll( catalog );
                        break;
                    case 'm':
                        add_member( lib_ID , catalog );
                        break;
                    case 'a': /* allocation */
                        /* throw error */
                        print_error_clear( "Unrecognized command!\n");
                        break;
                    default:
                        break;
                }
                break;
            case 'd': /* delete */
                switch ( command[ 1 ] )
                {
                    case 'r' :
                        delete_record( lib_title, lib_ID, catalog );
                        break;
                    case 'c':
                        delete_collection( catalog );
                        break;
                    case 'm':
                         remove_member( lib_ID , catalog );
                        break;
                    case 'a': /* allocation */
                        /* throw error */
                        break;
                    default:
                        print_error_clear( "Unrecognized command!\n");
                        break;
                }
                break;
            case 'c': /* clear */
                switch ( command[ 1 ] )
                {
                    case 'L':
                        clear_library( lib_title, lib_ID, catalog, "All records deleted\n" );
                        break;
                    case 'C':
                        clear_container( catalog, ( void(*)(void*) )destroy_Collection, "All collections deleted\n" );
                        break;
                    case 'A':
                        clear_all(lib_title, lib_ID, catalog, "All data deleted\n" );
                        break;
                    default:
                        print_error_clear( "Unrecognized command!\n");
                        break;
                }
                break;
            case 's': /* save */
                switch ( command[ 1 ] ) {
                    case 'A':
                        save_all_to_file( lib_title, catalog );
                        break;
                    default:
                        print_error_clear( "Unrecognized command!\n");
                        break;
                }
                break;
            case 'r': /* restore */
                switch ( command[ 1 ] ) {
                    case 'A':
                        load_from_file( lib_title, lib_ID, catalog );
                        break;
                    default:
                        print_error_clear( "Unrecognized command!\n");
                        break;
                }
                break;
            case 'q':
                switch ( command[ 1 ] )
                {
                    case 'q':
                        /* clean up memory */
                        quit( lib_title, lib_ID, catalog );
                        break;
                    default:
                        print_error_clear( "Unrecognized command!\n");
                        break;
                }
            default:
                /* throw error for bad input */
                print_error_clear( "Unrecognized command!\n");
                break;
        }
    }
	return 0;
}
Ejemplo n.º 16
0
Archivo: chat.c Proyecto: wyat/kbs
void call_alias(chatcontext * pthis, const char *arg)
{                               /* added by Luzi 1998.01.25 */
    char buf[128], buf2[200];
    FILE *fp;
    char path[40];
    char emoteid[40];
    int nIdx;

    nextword(&arg, emoteid, sizeof(emoteid));
    sethomefile(path, getCurrentUser()->userid, "/emotes");
    if (!emoteid[0]) {
        if ((fp = fopen(path, "r")) == NULL) {
            printchatline(pthis, "*** 还没有自定义的emote ***");
            return;
        }
        nIdx = 0;
        printchatline(pthis, "〖用户自定义emote列表〗");
        while (fread(buf, 128, 1, fp) > 0) {
            printchatline(pthis, buf);
        }
        fclose(fp);
    } else {
        nIdx = 0;
        if ((fp = fopen(path, "r")) != NULL) {
            while (1) {
                const char *tmpbuf;
                char tmpemote[40];

                if (fread(buf, 128, 1, fp) == 0) {
                    nIdx = 0;
                    break;
                }
                tmpbuf = buf;
                nextword(&tmpbuf, tmpemote, sizeof(tmpemote));
                nIdx++;
                if (strcasecmp(emoteid, tmpemote) == 0)
                    break;
            }
            fclose(fp);
        }
        if (nIdx > 0) {
            if (*arg) {
                printchatline(pthis, "*** 该emote已经被定义过了 ***");
                return;
            }
            if (delete_record(path, 128, nIdx, NULL, NULL) == 0) {
                printchatline(pthis, "*** 该自定义emote已经被删除了 ***");
                sprintf(buf, "/alias_del %s", emoteid);
                chat_send(pthis, buf);
            } else {
                bbslog("3error", "delete alias %s fail", emoteid);
                printchatline(pthis, "*** system error ***");
            }
        } else if (!*arg)
            printchatline(pthis, "*** 请指定emote对应的字串 ***");
        else {
            fp = fopen(path, "r");
            if (fp != NULL) {
                fseek(fp, 0, SEEK_END);
                if (ftell(fp) >= 128 * MAX_EMOTES) {
                    fclose(fp);
                    printchatline(pthis,
                                  "*** 用户自定义emote的列表已满 ***");
                    return;
                }
                fclose(fp);
            }
            sprintf(buf, "%s %s", emoteid, arg);
            if (append_record(path, buf, 128) == 0) {
                printchatline(pthis, "*** 自定义emote已经设定 ***");
                sprintf(buf2, "/alias_add %s", buf);
                chat_send(pthis, buf2);
            } else {
                bbslog("3error", "add alias %s fail", emoteid);
                printchatline(pthis, "*** 系统错误 ***");
            }
        }
    }
}
Ejemplo n.º 17
0
struct response_struct delete_command(char* token_vector[], int token_count){

  char* part            = NULL;
  char key[KEY_LEN]     = "";
  int length            = 0;
  int i = 0;
  int retval;
  struct keydb_column *tuple = NULL;
  struct keydb_column *head = NULL;
  struct keydb_column *tmp;
  int responselen = 0;
  struct response_struct response;

  response.status = 0;

  if ((response.msg = malloc(sizeof(char) * MSG_SIZE)) == NULL) {
    perror(NULL);
    cleanup_and_exit();
  }

  if (token_count < 2) {
    response.status = 1;
    sprintf(response.msg, "Not enough arguments");
    return response;
  }

  for (i = 1; (part = token_vector[i]) && (i < MAX_ARGS); i++) {
    length += strlen(part);
    if (length > KEY_LEN - 1) {
      response.status = 1;
      sprintf(response.msg, "Key too large");
      return response;
    }

    // Save away the list of key composites
    if ((tmp = malloc(sizeof(struct keydb_column))) == NULL) {
      perror(NULL);
      cleanup_and_exit();
    }
    strncpy(tmp->column, part, KEY_LEN);
    tmp->next = NULL;
    if (tuple == NULL) {
      tuple = tmp;
      head = tmp;
    } else {
      tuple->next = tmp;
      tuple = tuple->next;
      tuple->next = NULL;
    }
    strcat(key, part);
  } 

  if (length == 0) {
    response.status = 1;
    sprintf(response.msg, "Failed to extract key.");
    return response;
  }

  retval = delete_record(key);

  if (retval == 0) {
    if (composite_delete(KEYDB_FD, head) == -1) {
      fprintf(stderr, "Composite key delete failed.");
      response.status = 1;
      sprintf(response.msg, "Internal Error.");
    } else {
      sprintf(response.msg, "Delete OK.");
    }
  } else if (retval == -2) {
    response.status = 1;
    sprintf(response.msg, "Not found.");
  } else {
    response.status = 1;
    sprintf(response.msg, "Could not delete record.");
  } 

  while (head) { // free our list of key composites.
    tmp = head->next;
    free(head);
    head = tmp;
  };
  return response;
}
Ejemplo n.º 18
0
struct response_struct create_command(char* token_vector[], int token_count) {

  int length            = 0;
  int i = 0;
  char* part            = NULL;
  char* previous_part   = NULL;
  int retval            = 0;
  char key[KEY_LEN]     = "";
  struct keydb_column *tuple = NULL;
  struct keydb_column *head = NULL;
  struct keydb_column *tmp;
  struct response_struct response;

  response.status = 0;

  if ((response.msg = malloc(sizeof(char) * MSG_SIZE)) == NULL) {
    perror(NULL);
    cleanup_and_exit();
  }
  bzero(response.msg, MSG_SIZE);

  if (token_count < 3) {
    response.status = 1;
    sprintf(response.msg, "Not enough arguments.");
    return response;
  }

  for (i = 1; (part = token_vector[i]) && (i < MAX_ARGS); i++) {

    if (previous_part != NULL) {
      length += strlen(previous_part);
      if (length > KEY_LEN - 1) {
        response.status = 1;
        sprintf(response.msg, "Key too large.");
        return response;
      }

      // Save away the list of key composites
      if ((tmp = malloc(sizeof(struct keydb_column))) == NULL) {
        perror(NULL);
        cleanup_and_exit;
      }
      strncpy(tmp->column, previous_part, KEY_LEN);
      tmp->next = NULL;
      if (tuple == NULL) {
        tuple = tmp;
        head = tmp;
      } else {
        tuple->next = tmp;
        tuple = tuple->next;
        tuple->next = NULL;
      }
      strcat(key, previous_part);

    }
    previous_part = part;
  } 

  if (key[0] == '\0') {
    response.status = 1;
    sprintf(response.msg, "Failed to get value.");
    return response;
  }

  retval = write_record(key, previous_part);
  if (retval == 0) {
    if (composite_insert(KEYDB_FD, head) == -1) {
      delete_record(key); // undo what we did.
      fprintf(stderr, "Composite key insertion failed.");
      response.status = 1;
      sprintf(response.msg, "Internal error.");
    } else {
      sprintf(response.msg, "Write OK.");
    }
  } else if (retval == -2) { // key already exists.
    response.status = 1;
    sprintf(response.msg, "Write failed. Key exists in the index.");
  } else {
    response.status = 1;
    sprintf(response.msg, "Internal error.");
  }

  while (head) { // free our list of key composites.
    tmp = head->next;
    free(head);
    head = tmp;
  };
  return response;
}
Ejemplo n.º 19
0
 void BerkeleyQ::delete_job_record(const string& uid)
 {
     string key = build_job_key(uid);
     delete_record(key, 0);
 }
Ejemplo n.º 20
0
int main(int argc, char *argv[])
{
	dnsa_comm_line_s *cm;
	dnsa_config_s *dc;
	char *domain = NULL;
	int retval;

	cm = cmdb_malloc(sizeof(dnsa_comm_line_s), "cm in main");
	dnsa_init_comm_line_struct(cm);
	if ((retval = parse_dnsa_command_line(argc, argv, cm)) != 0) {
		cmdb_free(cm, sizeof(dnsa_comm_line_s));
		display_command_line_error(retval, argv[0]);
	}
	dc = cmdb_malloc(sizeof(dnsa_config_s), "dc in main");
	dnsa_init_config_values(dc);
	if ((retval = parse_dnsa_config_file(dc, cm->config)) != 0) {
		parse_dnsa_config_error(retval);
		goto cleanup;
	}
	domain = cmdb_malloc(CONF_S, "domain in main");
	if (!(strncpy(domain, cm->domain, CONF_S - 1)))
		goto cleanup;
	if (cm->type == FORWARD_ZONE) {
		if (cm->action == LIST_ZONES) {
			list_zones(dc);
			retval = 0;
		} else if (cm->action == DISPLAY_ZONE) {
			display_zone(domain, dc);
			retval = 0;
		} else if (cm->action == COMMIT_ZONES) {
			retval = commit_fwd_zones(dc, domain);
		} else if (cm->action == ADD_HOST) {
			retval = add_host(dc, cm);
		} else if (cm->action == ADD_ZONE) {
			retval = add_fwd_zone(dc, cm);
		} else if (cm->action == DELETE_RECORD) {
			retval = delete_record(dc, cm);
		} else if (cm->action == DELETE_ZONE) {
			retval = delete_fwd_zone(dc, cm);
		} else if (cm->action == ADD_CNAME_ON_ROOT) {
			retval = add_cname_to_root_domain(dc, cm);
		} else {
			printf("Action code %d not implemented\n", cm->action);
		}
	} else if (cm->type == REVERSE_ZONE) {
		if (cm->action == LIST_ZONES) {
			list_rev_zones(dc);
			retval = 0;
		} else if (cm->action == DISPLAY_ZONE) {
			display_rev_zone(domain, dc);
			retval = 0;
		} else if (cm->action == COMMIT_ZONES) {
			retval = commit_rev_zones(dc, domain);
		} else if (cm->action == ADD_ZONE) {
			retval = add_rev_zone(dc, cm);
		} else if (cm->action == MULTIPLE_A) {
			retval = display_multi_a_records(dc, cm);
		} else if (cm->action == ADD_PREFER_A) {
			retval = mark_preferred_a_record(dc, cm);
		} else if (cm->action == BUILD_REV) {
			retval = build_reverse_zone(dc, cm);
		} else if (cm->action == DELETE_PREFERRED) {
			retval = delete_preferred_a(dc, cm);
		} else if (cm->action == DELETE_ZONE) {
			retval = delete_reverse_zone(dc, cm);
		} else {
			printf("Action code %d not implemented\n", cm->action);
		}
	} else if (cm->type == GLUE_ZONE) {
		if (cm->action == ADD_ZONE)
			retval = add_glue_zone(dc, cm);
		else if (cm->action == LIST_ZONES)
			list_glue_zones(dc);
		else if (cm->action == DELETE_ZONE)
			delete_glue_zone(dc, cm);
		else
			printf("Action code %d not implemented\n", cm->action);
	}

	cleanup:
		if (domain)
			cmdb_free(domain, CONF_S);
		cmdb_free(cm, sizeof(dnsa_comm_line_s));
		cmdb_free(dc, sizeof(dnsa_config_s));
		exit(retval);
}
Ejemplo n.º 21
0
// [SLOT] - slot when delete button is pressed
void creatordialog::on_pushButton_delete_clicked()
{
    delete_record(creator_model);
}