static void prepopulate_fields(LinkDialog *ld, char *bufsel) { GtkClipboard *clipboard; char *clipsel, *url = NULL; clipboard = gtk_clipboard_get(GDK_SELECTION_CLIPBOARD); clipsel = gtk_clipboard_wait_for_text(clipboard); if (bufsel && has_url(bufsel)) { url = bufsel; } else if (clipsel && has_url(clipsel)) { url = clipsel; } if (bufsel) gtk_entry_set_text(GTK_ENTRY(ld->etext), bufsel); if (url) { char *niceurl; if (g_str_has_prefix(url, "http://") || g_str_has_prefix(url, "ftp://")) { niceurl = url; } else { niceurl = g_strdup_printf("http://%s", url); } gtk_entry_set_text(GTK_ENTRY(ld->eurl), niceurl); if (niceurl != url) g_free(niceurl); } g_free(clipsel); }
void * do_crawler(void *item) { char *url_ptr; int clientfd ; static int pages = 0; static int error = 0; char *buf = NULL; urlq_t *url_list_head = NULL, *p, *p_pre; char cur_dir[256]; hash_table *hash_in, *hash_out; /* int tid = pthread_self();*/ int j = 0; int i= 0; int pos_found = 0; char temp[256]; int status = 0; static int a = 0; static int b = 0; static int c = 0; static int d = 0; static int e = 0; static int f = 0; static int g = 0; while(1){ pthread_mutex_lock(&mutex); while (urlqueue.head_ptr->next == NULL){ pthread_cond_wait(&ready, &mutex); } pthread_mutex_lock(&((threadpool_item *)item)->waitlock); ((threadpool_item *)item)->idle = 0; pthread_mutex_unlock(&((threadpool_item *)item)->waitlock); url_ptr = queue_pop(&urlqueue); g++; pthread_mutex_unlock(&mutex); pthread_mutex_lock(&mutex); /*if not visited, set flag = 1*/ if(has_visited(hash, url_ptr) == 1){ pthread_mutex_unlock(&mutex); free(url_ptr); pthread_mutex_lock(&((threadpool_item *)item)->waitlock); ((threadpool_item *)item)->idle =1; pthread_mutex_unlock(&((threadpool_item *)item)->waitlock); d++; continue; } hash_out = has_url(hash, url_ptr); e++; pthread_mutex_unlock(&mutex); if (hash_out == NULL){ printf("error\n"); getchar(); } *temp = '\0'; cur_dir[0] = '\0'; strcpy(cur_dir, url_ptr); j = strlen(cur_dir); for (;cur_dir[j] != '/' && j != 0; j--) ; if(j == 0) cur_dir[j] = '\0'; else cur_dir[j+1] = '\0'; for (i = 0; i < 3; i++){ if((clientfd = open_tcp("127.0.0.1", 80)) < 0){ close_fd(clientfd); continue; } if( http_do_get(clientfd, rootdir, "127.0.0.1", url_ptr) < 0){ close_fd(clientfd); continue; } if(recv_line(clientfd, temp) <= 0){ close_fd(clientfd); continue; } if((status = http_response_status(temp)) == 4){ printf("%s error %d\n",url_ptr, error++); pthread_mutex_lock(&mutex); set_status(hash, url_ptr, 4); set_webg_status(webg, hash_out, 4); pthread_mutex_unlock(&mutex); pthread_mutex_lock(&((threadpool_item *)item)->waitlock); ((threadpool_item *)item)->idle =1; pthread_mutex_unlock(&((threadpool_item *)item)->waitlock); close_fd(clientfd); break; } buf = http_response_body(clientfd); close_fd(clientfd); break; } if (status == 4) continue; if(i == 3){ pthread_mutex_lock(&((threadpool_item *)item)->waitlock); ((threadpool_item *)item)->idle =1; pthread_mutex_unlock(&((threadpool_item *)item)->waitlock); close_fd(clientfd); continue; } if (buf == NULL){ pthread_mutex_lock(&((threadpool_item *)item)->waitlock); ((threadpool_item *)item)->idle =1; pthread_mutex_unlock(&((threadpool_item *)item)->waitlock); continue; } printf("%s pages %d\n", url_ptr,pages++); extract_link(buf, cur_dir, &url_list_head); free(buf); buf = NULL; p = url_list_head->next; p_pre = url_list_head; while (p != NULL){ if(strcmp(url_ptr, p->url_ptr) == 0){ p_pre->next = p->next; free(p->url_ptr); free(p); a++; p = p_pre->next; printf("a= %d, b= %d, c= %d, d= %d, e= %d, f= %d, g= %d\n", a,b,c,d,e,f,g); continue; } pthread_mutex_lock(&mutex); hash_in = has_url(hash, p->url_ptr); if (hash_in != NULL ){ insert_edge(webg, hash_in, hash_out); pthread_mutex_unlock(&mutex); p_pre->next = p->next; free(p->url_ptr); free(p); p = p_pre->next; b++; printf("a= %d, b= %d, c= %d, d= %d, e= %d, f= %d, g= %d\n", a,b,c,d,e,f,g); continue; } else{ pos_found = insert_vertex(webg, hash_out, p->url_ptr); insert_hash_item(hash, p->url_ptr, pos_found, 0); pthread_mutex_unlock(&mutex); c++; p_pre = p; p = p->next; printf("a= %d, b= %d, c= %d, d= %d, e= %d, f= %d, g= %d\n", a,b,c,d,e,f,g); } } if(p_pre != url_list_head){ pthread_mutex_lock(&mutex); queue_push(&urlqueue, url_list_head->next, p_pre); f++; pthread_mutex_unlock(&mutex); } free(url_list_head); p = p_pre = url_list_head = NULL; pthread_mutex_lock(&((threadpool_item *)item)->waitlock); ((threadpool_item *)item)->idle = 1; pthread_mutex_unlock(&((threadpool_item *)item)->waitlock); /*printf("next time!\n");*/ } /*printf("over!\n");*/ return NULL; }
int RceQueryRefuseReceiveWishItem::ByteSize() const { int total_size = 0; if (_has_bits_[0 / 32] & (0xffu << (0 % 32))) { // optional string type = 1; if (has_type()) { total_size += 1 + ::google::protobuf::internal::WireFormatLite::StringSize( this->type()); } // optional string name = 2; if (has_name()) { total_size += 1 + ::google::protobuf::internal::WireFormatLite::StringSize( this->name()); } // optional string playerId = 3; if (has_playerid()) { total_size += 1 + ::google::protobuf::internal::WireFormatLite::StringSize( this->playerid()); } // optional string id = 4; if (has_id()) { total_size += 1 + ::google::protobuf::internal::WireFormatLite::StringSize( this->id()); } // optional string guid = 5; if (has_guid()) { total_size += 1 + ::google::protobuf::internal::WireFormatLite::StringSize( this->guid()); } // optional string planetId = 6; if (has_planetid()) { total_size += 1 + ::google::protobuf::internal::WireFormatLite::StringSize( this->planetid()); } // optional string time = 7; if (has_time()) { total_size += 1 + ::google::protobuf::internal::WireFormatLite::StringSize( this->time()); } // optional string msg = 8; if (has_msg()) { total_size += 1 + ::google::protobuf::internal::WireFormatLite::StringSize( this->msg()); } } if (_has_bits_[8 / 32] & (0xffu << (8 % 32))) { // optional string url = 9; if (has_url()) { total_size += 1 + ::google::protobuf::internal::WireFormatLite::StringSize( this->url()); } } if (!unknown_fields().empty()) { total_size += ::google::protobuf::internal::WireFormat::ComputeUnknownFieldsSize( unknown_fields()); } _cached_size_ = total_size; return total_size; }
int MsgNeighbor::ByteSize() const { int total_size = 0; if (_has_bits_[0 / 32] & (0xffu << (0 % 32))) { // optional string platform = 1; if (has_platform()) { total_size += 1 + ::google::protobuf::internal::WireFormatLite::StringSize( this->platform()); } // optional int64 accountId = 2; if (has_accountid()) { total_size += 1 + ::google::protobuf::internal::WireFormatLite::Int64Size( this->accountid()); } // optional int32 score = 3; if (has_score()) { total_size += 1 + ::google::protobuf::internal::WireFormatLite::Int32Size( this->score()); } // optional int32 xp = 4; if (has_xp()) { total_size += 1 + ::google::protobuf::internal::WireFormatLite::Int32Size( this->xp()); } // optional string extId = 5; if (has_extid()) { total_size += 1 + ::google::protobuf::internal::WireFormatLite::StringSize( this->extid()); } // optional string url = 6; if (has_url()) { total_size += 1 + ::google::protobuf::internal::WireFormatLite::StringSize( this->url()); } // optional string name = 7; if (has_name()) { total_size += 1 + ::google::protobuf::internal::WireFormatLite::StringSize( this->name()); } // optional int32 isNeighbor = 8; if (has_isneighbor()) { total_size += 1 + ::google::protobuf::internal::WireFormatLite::Int32Size( this->isneighbor()); } } if (_has_bits_[8 / 32] & (0xffu << (8 % 32))) { // optional int32 levelBasedOnScore = 9; if (has_levelbasedonscore()) { total_size += 1 + ::google::protobuf::internal::WireFormatLite::Int32Size( this->levelbasedonscore()); } // optional string wishlist = 10; if (has_wishlist()) { total_size += 1 + ::google::protobuf::internal::WireFormatLite::StringSize( this->wishlist()); } // optional int64 damageProtectionTimeLeft = 11; if (has_damageprotectiontimeleft()) { total_size += 1 + ::google::protobuf::internal::WireFormatLite::Int64Size( this->damageprotectiontimeleft()); } // optional int32 tutorialCompleted = 12; if (has_tutorialcompleted()) { total_size += 1 + ::google::protobuf::internal::WireFormatLite::Int32Size( this->tutorialcompleted()); } } // repeated .MsgPlanet neighbor = 13; total_size += 1 * this->neighbor_size(); for (int i = 0; i < this->neighbor_size(); i++) { total_size += ::google::protobuf::internal::WireFormatLite::MessageSizeNoVirtual( this->neighbor(i)); } if (!unknown_fields().empty()) { total_size += ::google::protobuf::internal::WireFormat::ComputeUnknownFieldsSize( unknown_fields()); } _cached_size_ = total_size; return total_size; }