Ejemplo n.º 1
0
func accept(w http.ResponseWriter, r *http.Request) {
	c := appengine.NewContext(r)
	id := r.FormValue("id")
	intID, err := strconv.ParseInt(id, 10, 64)
	if err != nil {
		http.Error(w, err.Error(), http.StatusInternalServerError)
		return
	}
	pkg := &Package{}
	key := datastore.NewKey(c, "Package", "", intID, nil)
	err = datastore.Get(c, key, pkg)
	if err != nil {
		http.Error(w, err.Error(), http.StatusInternalServerError)
		return
	}
	// check if the package is already present
	acceptQuery := datastore.NewQuery("Package").
		Filter("Accepted =", true).
		Filter("Repo =", pkg.Repo)

	var packages []*Package
	keys, err := acceptQuery.GetAll(c, &packages)
	if err != nil {
		http.Error(w, err.Error(), http.StatusInternalServerError)
		return
	}
	if len(packages) > 1 {
		// just print an error to let admin know
		c.Errorf("More tha one package for repo: %v", pkg.Repo)
	}

	if len(packages) > 0 {
		// update the package and delete
		oldKey := keys[0]
		oldPkg := packages[0]
		oldPkg.Name = pkg.Name
		oldPkg.Description = pkg.Description
		oldPkg.IsLibrary = pkg.IsLibrary
		oldPkg.Category = pkg.Category
		oldPkg.Updated = time.Now()
		if _, err = datastore.Put(c, oldKey, oldPkg); err != nil {
			http.Error(w, err.Error(), http.StatusInternalServerError)
			return
		}
		if err = datastore.Delete(c, key); err != nil {
			http.Error(w, err.Error(), http.StatusInternalServerError)
			return
		}
	} else {
		// accept the new package
		pkg.Accepted = true
		if _, err = datastore.Put(c, key, pkg); err != nil {
			http.Error(w, err.Error(), http.StatusInternalServerError)
			return
		}
	}
	memcache.Delete(c, pkg.Repo)
	memcache.Delete(c, CAT)
	memcache.Delete(c, ALL_QUERY)
}
Ejemplo n.º 2
0
func delete(w http.ResponseWriter, r *http.Request) {
	key := extractKey(r)
	parts := strings.Split(key, "/")
	if len(parts) == 3 {
		result := make(map[string]bool, 1)
		context := appengine.NewContext(r)
		err := memcache.Delete(context, key)
		if err == nil {
			result[key] = true
			contentType, _ := url.QueryUnescape(parts[0])
			if imageTypes.MatchString(contentType) {
				thumbnailKey := key + thumbSuffix + filepath.Ext(parts[2])
				err := memcache.Delete(context, thumbnailKey)
				if err == nil {
					result[thumbnailKey] = true
				}
			}
		}
		w.Header().Set("Content-Type", "application/json")
		b, err := json.Marshal(result)
		check(err)
		fmt.Fprintln(w, string(b))
	} else {
		http.Error(w, "405 Method not allowed", http.StatusMethodNotAllowed)
	}
}
Ejemplo n.º 3
0
// clear the pairing cache for the specified dish/pair that is changed
func clearPairingCache(c *context, dishKey *datastore.Key, pairingKey *datastore.Key) {
	url := c.lid.Encode() + "/dish/" + dishKey.Encode() + "/pairing/"
	memcache.Delete(c.c, url)
	if pairingKey != nil {
		url += pairingKey.Encode()
		memcache.Delete(c.c, url)
	}
}
Ejemplo n.º 4
0
// Unsubscribe removes a feed from the user's feed list.
func unsubscribe(c appengine.Context, feedKey *datastore.Key) error {
	var f FeedInfo
	err := datastore.RunInTransaction(c, func(c appengine.Context) error {
		u, err := getUser(c)
		if err != nil {
			return err
		}

		i := 0
		var k *datastore.Key
		for i, k = range u.Feeds {
			if feedKey.Equal(k) {
				break
			}
		}
		if i >= len(u.Feeds) {
			return nil
		}

		err = fixMissingFieldError(datastore.Get(c, feedKey, &f))
		if err != nil {
			return err
		}

		f.Refs--
		if f.Refs <= 0 {
			if err := f.rmArticles(c); err != nil {
				return err
			}
			if err := datastore.Delete(c, feedKey); err != nil {
				return err
			}

			memcache.Delete(c, articlesMcacheKey(feedKey))

		} else if _, err := datastore.Put(c, feedKey, &f); err != nil {
			return err
		}

		u.Feeds = append(u.Feeds[:i], u.Feeds[i+1:]...)
		return putUser(c, &u)
	}, &datastore.TransactionOptions{XG: true})
	if err != nil {
		return err
	}

	flushUserPageCache(c)

	if f.Refs <= 0 {
		memcache.Delete(c, mcacheFeedsKey)
		memcache.Delete(c, feedKey.StringID())
		return nil
	}

	return memcache.Gob.Set(c, &memcache.Item{Key: feedKey.StringID(), Object: f})
}
Ejemplo n.º 5
0
Archivo: ds1.go Proyecto: sankark/kyp
func DeleteUser(ctx appengine.Context, user *event.User) {
	key := datastore.NewKey(ctx, "ProxyUser", user.Email, 0, nil)
	datastore.delete(ctx, key)
	key1 := USER_CACHE_KEY_PREFIX + User.Email
	key2 := USER_CACHE_KEY_PREFIX + User.AuthToken
	UserTable[key1] = nil, false
	UserTable[key2] = nil, false
	memcache.Delete(key1)
	memcache.Delete(key2)
}
Ejemplo n.º 6
0
// default data handler for "DELETE" to remove one itme
func (self *dataHandler) delete(key *datastore.Key) {
	// delete the item
	err := datastore.Delete(self.c, key)
	check(err)
	// remove this item from the cache
	cacheKey := self.lid.Encode() + self.r.URL.Path
	memcache.Delete(self.c, cacheKey)
	// remove the parent from the cache too
	// strip off the key from the URL
	parentURL := cacheKey[:len(cacheKey)-len(key.Encode())]
	memcache.Delete(self.c, parentURL)
	// also without the /
	memcache.Delete(self.c, parentURL[:len(parentURL)-1])
}
Ejemplo n.º 7
0
func HandleSign(r *http.Request) (err error) {

	c := appengine.NewContext(r)

	if user.Current(c) == nil {
		panic("Not logged in .. can only post with authenticated users")
	}

	if err := r.ParseForm(); err != nil {
		return err
	}
	g := &Buriggie{
		Content: r.FormValue("bericht"),
		Date:    time.Now(),
	}
	if u := user.Current(c); u != nil {
		g.Author = u.String()
	}
	if _, err := datastore.Put(c, datastore.NewIncompleteKey(c, "Greeting", nil), g); err != nil {
		return err
	}

	// nice and clean
	memcache.Delete(c, "buriggies.list.100")

	return nil
}
Ejemplo n.º 8
0
Archivo: ds1.go Proyecto: sankark/kyp
func DeleteGroup(ctx appengine.Context, group *event.Group) {
	key := datastore.NewKey(ctx, "ProxyGroup", group.Name, 0, nil)
	datastore.delete(ctx, key)
	key1 := GROUP_CACHE_KEY_PREFIX + group.Name
	GroupTable[key1] = nil, false
	memcache.Delete(key1)
}
Ejemplo n.º 9
0
func C1Logout(c appengine.Context) os.Error {
	u := user.Current(c).Email

	itm, err := memcache.Get(c, u+"__c1Sess")
	if err != nil && err != memcache.ErrCacheMiss {
		return err
	}
	if err == memcache.ErrCacheMiss {
		return nil
	}
	skey := string(itm.Value)
	session := c1SessionCookie(skey)

	r, err := http.NewRequest("GET", "https://www.cadetone.aafc.org.au/logout.php", nil)
	if err != nil {
		return err
	}
	injectSession(r, session)
	client := GetClient(c)
	_, err = client.Do(r)
	if err != nil {
		return err
	}

	memcache.Delete(c, u+"__c1Sess")

	return nil
}
Ejemplo n.º 10
0
func (cache *Cache) ClearStories(typeKey string) {
	delete(storyListCache, typeKey)

	if err := memcache.Delete(cache.context, typeKey); err != nil && err != memcache.ErrCacheMiss {
		cache.context.Warningf("Error clearing stories from memcache: %v", typeKey, err)
	}
}
Ejemplo n.º 11
0
Archivo: app.go Proyecto: 0x7cc/rsc
func cachePathTime(c appengine.Context, path string) (t int64, err error) {
	t, err = cacheTime(c)
	if err != nil {
		return 0, err
	}

	key := fmt.Sprintf("%d,mtime,%s", t, path)
	item, err := memcache.Get(c, key)
	if err == nil {
		v, err := strconv.ParseInt(string(item.Value), 10, 64)
		if err == nil {
			if chatty {
				c.Infof("cachePathTime %q = %v", key, v)
			}
			return v, nil
		}
		c.Criticalf("memcache.Get %q = %q (%v) - deleting", key, item.Value, err)
		memcache.Delete(c, key)
	}

	var seq int64
	if fi, err := stat(c, path); err == nil {
		seq = fi.Seq
	}

	c.Infof("cachePathTime save %q = %v", key, seq)
	item = &memcache.Item{Key: key, Value: []byte(strconv.FormatInt(seq, 10))}
	if err := memcache.Set(c, item); err != nil {
		c.Criticalf("memcache.Set %q %q: %v", key, item.Value, err)
	}
	return seq, nil
}
Ejemplo n.º 12
0
func (c *memcacheDriver) Delete(key string) error {
	err := memcache.Delete(c.c, key)
	if err != nil && err != memcache.ErrCacheMiss {
		return err
	}
	return nil
}
Ejemplo n.º 13
0
func updateHandler(w http.ResponseWriter, r *http.Request) {
	c := gae.NewContext(r)
	g := goon.FromContext(c)
	if r.Header.Get("X-AppEngine-Cron") != "true" {
		http.NotFound(w, r)
		return
	}
	var ups []UpdateSchedule
	if cache, err := memcache.Get(c, "UpdateSchedule"); err == memcache.ErrCacheMiss {
		q := datastore.NewQuery("UpdateSchedule")
		if _, err := g.GetAll(q, &ups); err != nil {
			http.Error(w, err.Error(), http.StatusInternalServerError)
			return
		}
		if val, err := serialize(&ups); err == nil {
			item := memcache.Item{Key: "UpdateSchedule", Value: val, Expiration: time.Hour * 12}
			memcache.Add(c, &item)
		}
	} else if err != nil {
		http.Error(w, err.Error(), http.StatusInternalServerError)
		return
	} else {
		deserialize(cache.Value, &ups)
	}
	now := time.Now()
	for _, us := range ups {
		if us.IsUpdateTime(now) {
			if err := updateVillage(us, g); err != nil {
				c.Debugf("%v", err)
			}
			memcache.Delete(c, "UpdateSchedule")
		}
	}
	return
}
Ejemplo n.º 14
0
// serveTwitterCallback handles callbacks from the Twitter OAuth server.
func serveTwitterCallback(c *context) error {
	token := c.r.FormValue("oauth_token")
	var ci connectInfo
	_, err := memcache.Gob.Get(c.c, token, &ci)
	if err != nil {
		return err
	}
	memcache.Delete(c.c, token)
	tempCred := &oauth.Credentials{
		Token:  token,
		Secret: ci.Secret,
	}

	httpClient := urlfetch.Client(c.c)
	tokenCred, _, err := oauthClient.RequestToken(httpClient, tempCred, c.r.FormValue("oauth_verifier"))
	if err != nil {
		return err
	}

	if err := c.updateUserInfo(func(u *userInfo) { u.TwitterCred = *tokenCred }); err != nil {
		return err
	}
	http.Redirect(c.w, c.r, ci.Redirect, 302)
	return nil
}
Ejemplo n.º 15
0
// ClearDeviceForRandID clears the cached Device for the specified RandID.
func ClearDeviceForRandID(c appengine.Context, RandID string) {
	mk := prefixDevForRandID + RandID

	if err := memcache.Delete(c, mk); err != nil {
		c.Warningf("Failed to delete %s from memcache: %v", mk, err)
	}
}
Ejemplo n.º 16
0
func AddClient(c appengine.Context, id string) (string, os.Error) {

	q := datastore.NewQuery("Client")
	var gg []*Client
	var check = 0

	if _, err := q.GetAll(c, &gg); err != nil {
		return "", err
	}

	for _, client := range gg {
		if client.ClientID == id {
			check = check + 1
		}
	}

	if check == 0 {
		key := datastore.NewIncompleteKey("Client")
		client := Client{ClientID: id}

		_, err := datastore.Put(c, key, &client)
		if err != nil {
			return "", err
		}
	}

	memcache.Delete(c, "sut")

	return channel.Create(c, id)

}
Ejemplo n.º 17
0
Archivo: unico.go Proyecto: licio/unico
func deleteAccountHandler(w http.ResponseWriter, r *http.Request) {

	id := ""
	session, err := sessions.Session(r, "", "datastore")
	c1 := appengine.NewContext(r)
	c1.Debugf("deleteAccount: id=%v, session=%v, err=%v\n", session["userID"], session, err)
	if err == nil {
		if session["userID"] != nil {
			id = session["userID"].(string)
		}
	}
	if id != "" {
		user := loadUser(r, id)
		if user.Id != "" {
			c := appengine.NewContext(r)
			key := datastore.NewKey(c, "User", user.Id, 0, nil)
			datastore.Delete(c, key)
			session["userID"] = ""
			sessions.Save(r, w)
			memUserDelete(c, user.Id)
			memcache.Delete(c, "user"+user.Id)
			http.SetCookie(w, &http.Cookie{Name: "userId", Value: "", Domain: appConfig.AppDomain, Path: "/", MaxAge: -1})
		}
	}
	http.Redirect(w, r, "/", http.StatusFound)
}
Ejemplo n.º 18
0
func channelDisconnected(w http.ResponseWriter, r *http.Request) {
	c := appengine.NewContext(r)
	from, err := strconv.ParseInt(r.FormValue("from"), 10, 0)
	if err != nil {
		c.Errorf("Error ParseInt: %v", err)
		return
	}
	if err := datastore.Delete(c, datastore.NewKey(c, "Endpoint", "", from, nil)); err != nil {
		c.Errorf("Error datastore.Delete: %v", err)
		return
	}

	token, err := getToken(c, from)
	if err != nil {
		c.Errorf("Error getToken(): %v", err)
		return
	}
	//c.Infof("Token: %s", token)

	act, err := memcache.Get(c, token)
	if err != nil && err != memcache.ErrCacheMiss {
		c.Errorf("Error memcache.Get: %v", err)
		return
	}

	var actions []inbox.ActionItem
	if err == nil {
		//c.Infof("mcache: %s", act.Value)
		err = json.Unmarshal(act.Value, &actions)
		if err != nil {
			c.Errorf("Error datastore.Get: %v", err)
			return
		}
		for _, a := range actions {
			var mailItem = new(inmail.Message)
			mkey := datastore.NewKey(c, "Message", "", a.MessageKey, nil)
			if err = datastore.Get(c, mkey, mailItem); err != nil {
				c.Errorf("Error datastore.Get: %v", err)
				continue
			}
			//c.Infof("Cmd: %s",a.Cmd)
			switch a.Cmd {
			case "UNREAD":
				mailItem.DeleteUnreadCount++
			case "DELETE":
				mailItem.DeleteUnreadCount--
			}
			//c.Infof("DeleteUnreadCount: %d",mailItem.DeleteUnreadCount)
			if _, err = datastore.Put(c, mkey, mailItem); err != nil {
				c.Errorf("Error datastore.Get: %v", err)
			}
		}
		if err = memcache.Delete(c, token); err != nil {
			c.Errorf("Error memcache.Delete: %v", err)
		}
	}

	return
}
Ejemplo n.º 19
0
func UpdateActiveAct(c appengine.Context) os.Error {
	err := memcache.Delete(c, "activeAct")
	if err != nil {
		return err
	}
	_, err = GetActiveAct(c)
	return err
}
Ejemplo n.º 20
0
func (cache *Cache) ClearStory(storyId int) {
	delete(storyCache, storyId)

	key := cacheKeyStoryPrefix + strconv.Itoa(storyId)
	if err := memcache.Delete(cache.context, key); err != nil && err != memcache.ErrCacheMiss {
		cache.context.Warningf("Error clearing storiy from memcache: %v", key, err)
	}
}
Ejemplo n.º 21
0
// DELETE http://localhost:8080/users/1
//
func (u *UserService) removeUser(request *restful.Request, response *restful.Response) {
	c := appengine.NewContext(request.Request)
	id := request.PathParameter("user-id")
	err := memcache.Delete(c, id)
	if err != nil {
		response.WriteError(http.StatusInternalServerError, err)
	}
}
Ejemplo n.º 22
0
func packageReloadHandler(w http.ResponseWriter, r *http.Request) error {
	c := appengine.NewContext(r)
	importPath := r.FormValue("importPath")
	cacheKey := docKeyPrefix + importPath
	err := memcache.Delete(c, cacheKey)
	c.Infof("memcache.Delete(%s) -> %v", cacheKey, err)
	removeDoc(c, importPath)
	http.Redirect(w, r, "/"+importPath, 302)
	return nil
}
Ejemplo n.º 23
0
func Logout(r *http.Request) (err bool) {
	c := appengine.NewContext(r)

	if e := memcache.Delete(c, "user"); e == memcache.ErrCacheMiss {
		return false
	} else if e != nil {
		return false
	}
	return true
}
Ejemplo n.º 24
0
func handleDelayedNotify(w http.ResponseWriter, r *http.Request) {
	log.Printf("Task started")
	c := appengine.NewContext(r)
	// Read the form data
	perma_blobref := r.FormValue("perma")
	// Allow for further notification tasks to be enqueued
	memcache.Delete(c, "notify-"+perma_blobref)
	// Find out about the users of this permanode
	s := newStore(c)
	data, err := s.GetPermaNode(perma_blobref)
	if err != nil {
		http.Error(w, "Err: Failed reading permanode", http.StatusInternalServerError)
		return
	}
	perma := grapher.NewPermaNode(nil)
	perma.FromMap(perma_blobref, data)
	message := fmt.Sprintf(`{"type":"notification", "perma":"%v", "lastseq":%v}`, perma_blobref, perma.SequenceNumber()-1)
	// For all users find all channels on which they are listening
	for _, user := range perma.Users() {
		// Do we know this user?
		userid, err := isLocalUser(c, user)
		if err != nil {
			// TODO: In the case of federation this is not really an error?
			log.Printf("Err: Unknown user %v", user)
			continue
		}
		// Mark that there is an unread file
		err = addUnread(c, userid, perma_blobref)
		if err != nil {
			log.Printf("Err writing unread: %v", err)
		}
		// Notify browser instances where this user is logged in
		var channels []channelStruct
		query := datastore.NewQuery("channel").Filter("UserEmail =", user)
		for it := query.Run(c); ; {
			var data channelStruct
			_, e := it.Next(&data)
			if e == datastore.Done {
				break
			}
			if e != nil {
				log.Printf("Err: in query: %v", e)
				break
			}
			channels = append(channels, data)
		}
		for _, ch := range channels {
			log.Printf("Sending to %v", ch.UserID+"/"+ch.SessionID)
			err := channel.Send(c, ch.UserID+"/"+ch.SessionID, message)
			if err != nil {
				log.Printf("Failed sending to channel %v", ch.UserID+"/"+ch.SessionID)
			}
		}
	}
}
Ejemplo n.º 25
0
func delete(w http.ResponseWriter, r *http.Request) {
	parts := strings.Split(r.URL.Path, "/")
	if len(parts) != 3 {
		return
	}
	if key := parts[1]; key != "" {
		c := appengine.NewContext(r)
		blobstore.Delete(c, appengine.BlobKey(key))
		memcache.Delete(c, key)
	}
}
Ejemplo n.º 26
0
func acceptremoval(w http.ResponseWriter, r *http.Request) {
	c := appengine.NewContext(r)
	repo := r.FormValue("repo")

	c.Errorf("REPO: %v", repo)

	removeQuery := datastore.NewQuery("Package").
		Filter("Accepted =", true).
		Filter("Repo = ", repo).
		KeysOnly()

	keys, err := removeQuery.GetAll(c, nil)
	if err != nil {
		http.Error(w, err.Error(), http.StatusInternalServerError)
		return
	}
	c.Errorf("FOUND: %v", keys)
	for _, key := range keys {
		c.Errorf("DELETING: %v", key)
		if err := datastore.Delete(c, key); err != nil {
			http.Error(w, err.Error(), http.StatusInternalServerError)
			return
		}
	}

	// delete removal request
	id := r.FormValue("id")
	intID, err := strconv.ParseInt(id, 10, 64)
	if err != nil {
		http.Error(w, err.Error(), http.StatusInternalServerError)
		return
	}
	key := datastore.NewKey(c, "RemoveRequest", "", intID, nil)
	if err := datastore.Delete(c, key); err != nil {
		http.Error(w, err.Error(), http.StatusInternalServerError)
		return
	}
	memcache.Delete(c, repo)
	memcache.Delete(c, CAT)
	memcache.Delete(c, ALL_QUERY)
}
Ejemplo n.º 27
0
// WriteMeta writes a metadata value to the datastore under the given key.
// The value is stored in JSON format: it must be possible to marshal v into JSON.
// The value can be read back using ReadMeta.
//
// If an error occurs, WriteMeta returns it but also logs the error
// using ctxt.Errorf.
func WriteMeta(ctxt appengine.Context, key string, v interface{}) error {
	js, err := json.Marshal(v)
	if err != nil {
		ctxt.Errorf("write meta %s: marshal JSON: %v", key, err)
		return err
	}
	err = WriteData(ctxt, "Meta", key, &meta{JSON: js})
	if err == nil {
		memcache.Delete(ctxt, "app.Meta."+key)
	}
	return err
}
Ejemplo n.º 28
0
/*
 * This function will clear a specified entity from the memcache and the datastore
 */
func DeleteCache(r *http.Request, identifier string) {
	c := appengine.NewContext(r)

	// Delete from memcache
	memcache.Delete(c, identifier)

	// Delete from the datastore
	key := datastore.NewKey(c, "Cache", identifier, 0, nil)
	var cache Cache
	datastore.Get(c, key, &cache)
	datastore.Delete(c, key)
}
Ejemplo n.º 29
0
// break up the text into words and add/remove keywords  for the dish
func updateDishKeywords(c *context, key *datastore.Key, dish *Dish) {
	words := make(map[string]bool)
	addWords(dish.Name, words)
	addWords(dish.Source, words)
	addWords(dish.Text, words)
	addTags(c.c, key, words)
	if updateKeywords(c.c, key, words) {
		// if we made changes, we need to clear the cache
		cacheKey := c.lid.Encode() + "/dish/" + key.Encode() + "/keywords/"
		memcache.Delete(c.c, cacheKey)
	}
}
Ejemplo n.º 30
0
// update the ingredient's keywords
func updateIngredientKeywords(c *context, key *datastore.Key,
	ing *Ingredient) {
	words := make(map[string]bool)
	addWords(ing.Name, words)
	addWords(ing.Category, words)
	addTags(c.c, key, words)
	if updateKeywords(c.c, key, words) {
		// if we made changes, we need to clear the cache
		cacheKey := c.lid.Encode() + "/ingredient/" + key.Encode() + "/keywords/"
		memcache.Delete(c.c, cacheKey)
	}
}